R - geeglm Error: contrasts can be applied only to factors with 2 or more levels

时光怂恿深爱的人放手 提交于 2019-12-08 08:07:55

问题


I have applied GEE to the following dataset (str as below). Everything is fine.

> str(cd4.5m2)
'data.frame':   1300 obs. of  7 variables:
 $ id       : Factor w/ 260 levels "1","5","29","32",..: 1 1 1 1 1 2 2 2 2 2 ...
 $ Treatment: Factor w/ 4 levels "Alternating",..: 2 2 2 2 2 1 1 1 1 1 ...
 $ Age      : num  36.4 36.4 36.4 36.4 36.4 ...
 $ Gender   : Factor w/ 2 levels "Female","Male": 2 2 2 2 2 2 2 2 2 2 ...
 $ logcd4   : num  3.14 3.04 2.77 2.83 3.22 ...
 $ Week     : num  0 7.57 15.57 23.57 32.57 ...
 $ Time     : int  0 1 2 3 4 0 1 2 3 4 ...

I then transformed the outcome variable, reason being we want to monitor the change over time. So the str of the transformed data looks like below, which is almost exactly the same as the previous one (other than some name changes).

> str(cd4.5m1)
'data.frame':   1300 obs. of  6 variables:
 $ id             : Factor w/ 260 levels "1","5","29","32",..: 1 2 3 4 5 6 7 8 9 10 ...
 $ Treatment      : Factor w/ 4 levels "Alternating",..: 2 1 4 1 3 3 1 4 1 3 ...
 $ Age            : num  36.4 35.9 47.5 37.3 42.7 ...
 $ Gender         : Factor w/ 2 levels "Female","Male": 2 2 2 1 2 2 2 2 2 2 ...
 $ Week           : num  1 1 1 1 1 1 1 1 1 1 ...
 $ cd4.change.norm: num  0.572 0.572 0.572 0.572 0.572 ...

I then run the GEE again and it gives me the error.

> gee1.default <- geeglm(cd4.change.norm ~ Treatment, data=cd4.5m1, id=id, family=gaussian, corstr="unstructured")
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : 
  contrasts can be applied only to factors with 2 or more levels

I also tested all variables in the data, they all contain multiple values. So I'm completely lost here. I also saw a lot of posts on this Error, but none seem to be able to address my issue here. Help appreciated!


回答1:


I changed the correlation structure to AR1, and it worked. I did test the correlation (decreased over time) and AR1 is the correct structure to use.

But normally unstructured should be the save option?



来源:https://stackoverflow.com/questions/37108357/r-geeglm-error-contrasts-can-be-applied-only-to-factors-with-2-or-more-levels

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!