小编use*_*028的帖子

重塑数据以与 geeglm() 一起使用

您能帮我弄清楚为什么我会收到错误吗?

最初我的数据如下所示:

> 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"       
Run Code Online (Sandbox Code Playgroud)

首先,我重塑数据以准备 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 …
Run Code Online (Sandbox Code Playgroud)

r

5
推荐指数
1
解决办法
4733
查看次数

标签 统计

r ×1