【问题标题】:R - geeglm Error: contrasts can be applied only to factors with 2 or more levelsR - geeglm 错误:对比只能应用于具有 2 个或更多级别的因子
【发布时间】:2016-09-03 15:37:09
【问题描述】:

我已将 GEE 应用于以下数据集(str 如下)。一切都很好。

> 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 ...

然后我转换了结果变量,原因是我们想要监控随时间的变化。所以转换后的数据的str如下图,和上一个几乎一模一样(除了一些名字的变化)。

> 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 ...

然后我再次运行 GEE,它给了我错误。

> 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

我还测试了数据中的所有变量,它们都包含多个值。所以我在这里完全迷失了。我也看到了很多关于这个错误的帖子,但似乎没有一个能够在这里解决我的问题。感谢您的帮助!

【问题讨论】:

    标签: r


    【解决方案1】:

    我将关联结构更改为 AR1,它起作用了。我确实测试了相关性(随着时间的推移而降低)并且 AR1 是正确使用的结构。

    但通常非结构化应该是保存选项?

    【讨论】:

    • 我和你有同样的问题。它适用于其他选项,但“非结构化”。
    • 嘿,我刚刚重新排序了我的数据,它可以工作了。我建议您尝试重新排序您的数据,例如“cd4.5m1
    猜你喜欢
    • 1970-01-01
    • 2015-12-09
    • 2020-03-27
    • 2023-03-23
    • 1970-01-01
    • 2021-01-24
    • 2017-01-29
    • 2020-04-22
    • 2016-04-21
    相关资源
    最近更新 更多