4

以下を使用して作成されたplmオブジェクトがあります。

require(plm)
plm1 <- plm(Sepal.Length ~ Petal.Length + Petal.Width, data = iris, index = "Species")

pseries オブジェクトをマトリックスや data.frame のような使用可能なものに操作することはできないようです。

> data.frame(resid(plm1))
Error in as.data.frame.default(x[[i]], optional = TRUE) : 
  cannot coerce class '"pseries"' into a data.frame

次のようなものがあればいいのですが:

> 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

ddply または aggregate を使用して、各種の rsquared を見つけることができます。

助言がありますか?

4

2 に答える 2

3

これらの線に沿った何かがうまくいくかもしれません

library(plm)
plm1 <- plm(Sepal.Length ~ Petal.Length + Petal.Width, data = iris, index = "Species")
res <- residuals(plm1)
df <- cbind(as.vector(res), attr(res, "index"))
names(df) <- c("resid", "species", "time")
str(df)
## 'data.frame':    150 obs. of  3 variables:
##  $ resid  : num  0.1499 -0.0501 -0.1595 -0.4407 0.0499 ...
##  $ species: Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ time   : Factor w/ 50 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
于 2014-08-04T21:56:32.207 に答える