I have a plm object created using:
require(plm)
plm1 <- plm(Sepal.Length ~ Petal.Length + Petal.Width, data = iris, index = "Species")
I'm trying to extract the residuals to manually calculate r-squared by Species by can't seem to manipulate the pseries object into something useable like a matrix or data.frame.
> data.frame(resid(plm1))
Error in as.data.frame.default(x[[i]], optional = TRUE) :
cannot coerce class '"pseries"' into a data.frame
It would be nice if I had something like:
> df1 <- data.frame(time = rep(1:10,15), Species = iris$Species, resid1 = runif(150))
> head(df1)
time Species resid1
1 1 setosa 0.7038776
2 2 setosa 0.2164597
3 3 setosa 0.1988884
4 4 setosa 0.9311872
5 5 setosa 0.7087211
6 6 setosa 0.9914357
That I could use ddply or aggregate on to find the rsquared for each Species.
Any suggestions?
May be something along these lines will do the trick