[R] Residual-Plotting and na.exclude
Katharina Mersmann
kmersman at smail.uni-koeln.de
Thu Jul 3 16:18:49 CEST 2014
-----Ursprüngliche Nachricht-----
Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im
Auftrag von Katharina Mersmann
Gesendet: Dienstag, 1. Juli 2014 16:22
An: r-help at r-project.org
Betreff: [R] (PLM- package) Residual-Plotting and missing Values
Dear R-Community,
I tried plotting the residuals of an FE-model estimated via plm .
And detected that there are no residuals in the plot for the last two
countries.
I guess this happens because for some countries values are missing and R
gives me the following for
> fixed.reg1.new$resid[1]
5
-0.4051985
Because the first 4 elements are missing. So there are residuals different
from zero for the last two countries, but because of NA there4s a shift
because the residuals are not padded to the correct length.
I read in https://stat.ethz.ch/pipermail/r-help/2008-June/166312.html
and the manual that na.action=na.exclude is useful in lm-case to avoid this:
(when na.exclude is used the residuals and predictions are padded to the
correct length by inserting NAs for cases omitted by na.exclude)
and tried it for my plm regression, but it does not work.
To make it easier explaining the way of proceeding, a reproducible example
could be:
> # add NA4s for firm 6
> data("Grunfeld", package = "plm")
> Grunfeld$inv2= ifelse(Grunfeld$firm==6,NA, Grunfeld$inv)
> data<- pdata.frame(Grunfeld,index=c("firm","year"))
> fixed.reg1.1 <- plm(value~inv2+capital,
+ data = data,na.action=na.exclude
+ ,index=c("firm","year"),
model="within")
> #resid(fixed.reg1.1)
> # no values for firm 6, no residuals displayed from 101-120
> fixed.reg1.1$resid[105]
125
9.371963
> require(lattice)
> xyplot(resid(fixed.reg1.1) ~ firm, data=data)
# As you can see because of the NA4s of firm 6 ,there is a shift because
the residuals are not padded to the correct length,
and looking at the plot suggests there are no residuals for firm 10 but for
firm 6, which is not true.
Perhaps you have an Idea how to get residuals into the correct length? Or
another way to deal with it?
Thanks in advance for your help!
Have a nice day Katie
More information about the R-help
mailing list