首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >模型矩阵具有多重共线性

模型矩阵具有多重共线性
EN

Stack Overflow用户
提问于 2016-01-06 17:03:44
回答 1查看 208关注 0票数 1

我正在使用R中的lme函数来运行模型:

代码语言:javascript
复制
f0 <- lme(value ~ -1 + cs_d0 + va_d0 + cs_d0:visitmse + va_d0:visitmse + cs_d0:ageb + va_d0:ageb +
+           cs_d0:lesionse + va_d0:lesionse, random =  
+            ~ -1 + (cs_d0 + va_d0) + visitmse:( cs_d0 + va_d0)|pat , weights = 
+             varIdent(form=~1| cs_d0), control=lmeControl(opt="optim"), data =D0Train)

但是我遇到了一个错误

代码语言:javascript
复制
Error in MEEM(object, conLin, control$niterEM) : 
  Singularity in backsolve at level 0, block 1

当我搜索并尝试查看模型矩阵时,我发现了这个问题:

代码语言:javascript
复制
> m <- model.matrix(value ~ -1 + cs_d0 + va_d0 + cs_d0:visitmse + va_d0:visitmse + cs_d0:ageb + va_d0:ageb +
+           cs_d0:lesionse + va_d0:lesionse + va_d0:gender   ,data =D0Train)
> m[1:10,]
   cs_d0 va_d0 cs_d0:visitmse va_d0:visitmse cs_d0:ageb va_d0:ageb cs_d0:lesionse0 cs_d0:lesionse1 va_d0:lesionse1 va_d0:gender2
1      1     0            0.0              0         70          0               0               1               0             0
2      1     0            0.5              0         70          0               0               1               0             0
3      1     0            1.0              0         70          0               0               1               0             0
4      1     0            9.0              0         70          0               0               1               0             0
5      1     0            0.0              0         80          0               1               0               0             0
6      1     0            3.0              0         80          0               1               0               0             0
7      1     0            6.0              0         80          0               1               0               0             0
8      1     0            0.0              0         77          0               1               0               0             0
9      1     0            3.0              0         77          0               1               0               0             0
10     1     0            6.0              0         77          0               1               0               0             0

损伤是具有两个水平(0,1)的因子,

代码语言:javascript
复制
str(D0Train$lesionse)
 Factor w/ 2 levels "0","1": 2 2 2 2 1 1 1 1 1 1 ...

但在模型(cs_d0:lesionse0 , cs_d0:lesionse1 )中,它似乎有两个以上的层次。

下面是一个示例:

代码语言:javascript
复制
# lesion type
lesion = factor(c(rep(0,150),rep(1,50))) 
# gender
sex = factor(c(rep(0,150),rep(1,50)), label=c("Female","Male"))
# visiting time by months
time = rep(c(0,3,6,9),time = 4, 200)
# subjects 
subject = rep(1:50, each = 4)
# first  response variable "identity"
x_1 = c(rep(0, 100), rep(1,100)) 
# second  response variable "identity"
x_2 = c(rep(1, 100), rep(0,100))
# values of both reponses variables (x_1, x_2)
value = c(rnorm(100,20,1),rnorm(100,48,1))
# variables refer to reponses variables (x_1, x_2)
variable = factor(c(rep(0,150),rep(1,50)), label=c("X2","X1"))

df = data.frame(subject , time, sex, lesion, x_1,x_2,value, variable)

library(nlme)
# fit the model that each response variable has intercept and slope (time) for each random and fixed effects
# as well as fixed effects slopes for sex and lesion, and each response has different variance 
f=  lme(value ~ -1 + x_1 + x_2 + x_1:time + x_2:time +  x_1:lesion + x_2:lesion + 
               x_1:sex + x_2:sex, random = ~ -1 + (x_1 + x_2) + time:( x_1 + x_2)|subject , 
       weights = varIdent(form=~1| x_1), control=lmeControl(opt="optim"), data =df)

fm = model.matrix(value ~ -1 + x_1 + x_2 + x_1:time + x_2:time +  x_1:lesion + x_2:lesion + 
               x_1:sex + x_2:sex,data=df)

你可以帮助我或给我一些建议吗?

EN

回答 1

Stack Overflow用户

发布于 2016-01-26 01:31:16

根据您的示例数据,错误是正确的。你有一个奇点。

x_1:timex_2:time是重复的列--当x_1:time == 0,x_2:time == time时。当x_1:time == time时,x_2:time == 0。x_1x_2的主要效果也是如此。

您的模型被过度指定了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34629176

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档