I've plot this graphic to identify graphically high-leverage points in my linear model.
Given the variable "NOMBRES" of the data set which my model uses, I've tried to plot all the points of my graphic but it gets illegible. Here's the code I ran:
> plot(hatvalues(tmodel),residuals(tmodel))
> text(hatvalues(tmodel),residuals(tmodel),labels=DSET$NOMBRES)
So I would like to plot just the points with leverage(hat value) above 0.05 using the label "DSET$NOMBRES".
The “identify” tool in R allows you to quickly find outliers. You click on a point in the scatter plot to label it. You can place the label right by clicking slightly right of center, etc. The label is the row number in your dataset unless you specify it differenty as below.
To add the labels, we have text() , the first argument gives the X value of each point, the second argument the Y value (so R knows where to place the text) and the third argument is the corresponding label. The argument pos=1 is there to tell R to draw the label underneath the point; with pos=2 (etc.)
Identify high-leverage points according to your definition:
hlev <- which(hatvalues(tmodel)>0.05)
Add numeric labels to the graph:
text(hatvalues(tmodel)[hlev], residuals(tmodel)[hlev],
labels=DSET$NOMBRES[hlev])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With