我想自相关不同级别的数据,为每个级别生成图。但是,我似乎找不到将数据帧拆分到不同 ID 级别的方法:
##My data is:
*data.1*
ID y.var.1
1 1 2.284620
2 1 2.820829
3 1 3.889701
4 1 5.180010
5 1 6.080572
6 2 6.972568
7 2 8.082126
8 2 9.075686
9 2 9.864694
10 2 10.942456
11 3 11.853353
12 3 13.112986
13 3 13.893405
14 3 15.037400
15 3 16.015836
## I use dlply (from the plyr package) to split the dataframe by the level ID
data_ID<-dlply(data.1, .(ID), function(X) acf(y.var.1, na.action = na.pass))
head(data_ID)
##and although this produces three groups, they all have the same values which are the same as when I do autocorrelation on the entire dataframe..
> head(data_ID)
$`1`
Autocorrelations of series ‘y.var.1’, by lag
0 1 2 3 4 5 6 7 8 9 10 11
1.000 0.804 0.600 0.409 0.230 0.071 -0.075 -0.194 -0.293 -0.370 -0.409 -0.418
$`2`
Autocorrelations of series ‘y.var.1’, by lag
0 1 2 3 4 5 6 7 8 9 10 11
1.000 0.804 0.600 0.409 0.230 0.071 -0.075 -0.194 -0.293 -0.370 -0.409 -0.418
$`3`
Autocorrelations of series ‘y.var.1’, by lag
0 1 2 3 4 5 6 7 8 9 10 11
1.000 0.804 0.600 0.409 0.230 0.071 -0.075 -0.194 -0.293 -0.370 -0.409 -0.418
> dput(data.1)
structure(list(ID = c(1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3,
3, 3), y.var.1 = c(2.28462022795481, 2.82082936729163, 3.88970139114628,
5.18001014821836, 6.08057215599522, 6.97256785426474, 8.08212595903149,
9.07568620628701, 9.8646935842879, 10.9424555128125, 11.8533529745958,
13.1129856348251, 13.8934049954063, 15.0374003752388, 16.0158355330431
)), .Names = c("ID", "y.var.1"), row.names = c(NA, -15L), class = "data.frame")
任何人都对如何解决这个问题有任何想法,那就太好了!