我正在尝试使用lme
中的包R
来模拟基于多元线性混合效果模型的数据。数据是
> data_simO[1:10,]
pat time outcome csse vase
1 1 0 0 35.94075 -0.08586536
2 1 3 0 29.98295 -3.84084267
3 1 6 0 24.80345 -7.95054467
4 1 9 0 18.05502 -11.85375518
5 2 0 0 35.78939 -0.39146190
6 2 3 0 -24.13811 22.92276577
7 2 6 0 -84.15957 46.32400538
8 2 9 0 -144.33715 69.66958083
9 3 0 0 36.47212 0.10686316
10 3 3 0 72.50521 -5.72415186
> summary(data_simO)
pat time outcome csse vase
Min. : 1.0 Min. :0.00 0:7080 Min. :-367.196 Min. :-209.065
1st Qu.: 750.8 1st Qu.:2.25 1:4920 1st Qu.: 9.851 1st Qu.: -5.114
Median :1500.5 Median :4.50 Median : 35.694 Median : 4.866
Mean :1500.5 Mean :4.50 Mean : 30.655 Mean : 14.661
3rd Qu.:2250.2 3rd Qu.:6.75 3rd Qu.: 55.881 3rd Qu.: 43.773
Max. :3000.0 Max. :9.00 Max. : 404.946 Max. : 250.006
然后使用melt
函数分割数据取决于结果变量:
> D0Train[1:10,]
pat time outcome variable value cs_d0 va_d0
1 11 0 0 csse 37.101886 1 0
2 11 3 0 csse 12.117602 1 0
3 11 6 0 csse -12.678002 1 0
4 11 9 0 csse -36.600898 1 0
5 13 0 0 csse 36.254159 1 0
6 13 3 0 csse 27.938812 1 0
7 13 6 0 csse 18.471065 1 0
8 13 9 0 csse 9.552347 1 0
9 14 0 0 csse 35.605628 1 0
10 14 3 0 csse 43.438193 1 0
模型是
f1 <- lme(value ~-1+ cs_d1 + va_d1 + time:cs_d1 + time:va_d1,
+ random = ~ -1 + (cs_d1 + va_d1) + time:( cs_d1 + va_d1)|pat, weights=varIdent(form=~1| cs_d1)
+ ,control=lmeControl(maxIter=100,returnObject=TRUE,singular.ok=TRUE, opt="optim"), data =D1Train)
每个响应都有截距和斜率(固定和随机效应)。但是我收到了一个错误:
Error in logLik.reStruct(object, conLin) :
NA/NaN/Inf in foreign function call (arg 3)
我不确定它是什么意思以及如何解决它?