2012-09-08 128 views
3

您能否幫我弄清楚爲什麼出現錯誤?重塑用於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"  

首先我重塑我的數據爲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(錯誤)和小時,geeglm不抱怨,而我得到的輸出。該函數不適用於錯誤和小時變量。我檢查所有變量的長度,它們是相等的。你能幫我弄清楚什麼是錯的?

非常感謝!

+0

重複的例子的任何機會嗎?你有你的數據的任何'NA'值? –

回答

1

發現這個在:https://stat.ethz.ch/pipermail/r-help/2008-October/178337.html

「 我敢肯定這是鵝()中的錯誤,應報告給
的 維護者geepack的問題是缺少的治療。
值。

如果長相在暗淡(na.omit(DAT [,C( 「ID」, 「得分」, 「化學」, 「時間」)]))一個
得到44. 在鵝.fit()zsca被設置爲等於矩陣(1,N,1),其中N被設置爲
等於 長度(id)。但是ID具有長度46,而響應y已經被
修整爲 ,直至長度44,其通過消除任何
所涉及的變量 所缺失的任何行數據。因此一個問題。

問題的解決方案需要由
維護者geepack的一些代碼重寫。」