These plots are diagnostic plots for multiple linear regression. The documentation for the leveragePlot function seems straightforward, but I can't get the function to produce anything. Let's do a simple model with mtcars.
From what I can tell, one of the following should produce a plot
leveragePlot(model1, cyl)
or
leveragePlot(model1, ~cyl)
but neither does. I consistently get ~cyl is not a term in the model and similar errors when I try other terms or combinations of terms. I've also tried explicitly using terms= to no avail.
I imagine this is just my inability to read the help documentation syntax correctly, but I'm at a wall and need some help.
I am quite familiar with reproducible examples and thought I was providing one when I provided a specific data set and the things that I had tried. Thanks for catching the typo, though. I, of course, meant leveragePlots, although there is a leveragePlot function in car as well that seems to map to the same code.
I too was able to run the example in the help file, but was not able to reduce it to a simpler example, although as you see I tried several things. The example in the help runs the lm() inside the leveragePlots() function itself, which is certainly not the way that users would use the plot. Since it's a diagnostic plot, most people would have run a linear model and would then want to produce the plot afterward, as I am trying to do.
Your reduced example may not work as you've requested the Y variable (prestige) rather than one of the X variables (income, education, etc), and leverage plots are used on the X variables. That may be one reason you are getting an error.
I very much appreciate the help but am not sure what your post is trying to tell me -- that the help page works but other things don't?
It seems that changing from LeveragePlot to LeveragePlots allows me to enter a model as the argument and I will get one plot for each effect, that is, all the possible leverage plots for the model. the LeveragePlot function is (I think) where you ask for a specific term in the model, rather than all terms, and it is that function that I cannot get to work.
You were missing information about the used libraries, i.e. library calls, this is fundamental to ensure the reproducibility of the code, otherwise people would have to guess which packages are you using, as technocrat did.
Uh, @leecreighton, I have the same type of lapses (probably more often) as typing LeveragePlot (again) for LeveragePlots. That is why a reprex is useful: it catches us our when we do that.
leveragePlots takes an lm model as argument with one-sided terms to specify which numeric regressors, factors and interactions to include. The default is all. To specify a single regressor