gpt4 book ai didi

reshape 数据以与 geeglm() 一起使用

转载 作者:行者123 更新时间:2023-12-04 11:49:41 24 4
gpt4 key购买 nike

你能帮我弄清楚为什么我会出错吗?

最初我的数据如下所示:

> attributes(compl)$names
[1] "UserID" "compl_bin" "Sex.x" "PHQ_base" "PHQ_Surv1" "PHQ_Surv2" "PHQ_Surv3"
[8] "PHQ_Surv4" "EFE" "Neuro" "Intervention.x" "depr0" "error1_1.x" "error1_2.x"
[15] "error1_3.x" "error1_4.x" "stress0" "stress1" "stress2" "stress3" "stress4"
[22] "hours1" "hours2" "hours3" "hours4" "subject"

首先,我 reshape 我的数据为 geeglm 做准备:
compl$subject <- factor(rownames(compl))
nobs <- nrow(compl)
compl_long <- reshape(compl, idvar = "subject",
varying = list(c("PHQ_Surv1", "PHQ_Surv2" ,
"PHQ_Surv3", "PHQ_Surv4"),
c("error1_1.x", "error1_2.x",
"error1_3.x", "error1_4.x"),
c("stress1", "stress2", "stress3",
"stress4"),
c("hours1", "hours2", "hours3",
"hours4")),
v.names = c("PHQ", "error", "stress", "hours"),
times = c("1", "2", "3", "4"), direction = "long")

-(编者注:不确定下一个输出来自什么......)
 [1] "UserID"         "compl_bin"      "Sex.x"          "PHQ_base"       "EFE"            "Neuro"          "Intervention.x"
[8] "depr0" "stress0" "subject" "time" "PHQ" "error" "stress"
[15] "hours"

然后我使用 geeglm 函数:
library(geepack)

geeSand=(geeglm(PHQ~as.factor(compl_bin) + Neuro+PHQ_base+as.factor(depr0) +
EFE+as.factor(Sex.x) + as.factor(error)+stress+hours,
family = poisson, data=compl_long,
id=subject, corst="exchangeable"))

我收到一个错误:
"Error in geese.fit(xx, yy, id, offset, soffset, w, waves = waves, zsca,  : 
nrow(zsca) and length(y) not match"

如果我删除变量 as.factor(error) 和 hours,geeglm 不会提示,我会得到输出。该函数不适用于错误和小时变量。我检查所有变量的长度,它们是相等的。你能帮我找出问题所在吗?

非常感谢!

最佳答案

发现于:https://stat.ethz.ch/pipermail/r-help/2008-October/178337.html

"
我很确定这是 geese() 中的错误,应该报告给

geepack 的维护者。问题在于失踪的处理
值(value)观。

如果看 dim(na.omit(dat[,c("id","score","chem","time")])) 一个
得到 44。
在 geese.fit() 中,zsca 设置为等于 matrix(1,N,1) ,其中设置了 N
等于
长度(id)。但是 id 的长度为 46 而响应 y 是
修剪
通过消除任何数据行来减少长度 44
变量
涉案失踪。因此出现了问题。

问题的解决需要代码重写
geepack 的维护者。”

关于 reshape 数据以与 geeglm() 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12327322/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com