title: Reshaping data for use with geeglm()
body: <p>Could you please help me figure out why I am getting an error?</p>
  
  <p>Initially my data looks like this:</p>
  
  <pre><code>&gt; 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"       
  </code></pre>
  
  <p>First I reshape my data to prepare for geeglm:</p>
  
  <pre><code>compl$subject &lt;- factor(rownames(compl))
  nobs &lt;- nrow(compl) 
  compl_long &lt;- 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")
  </code></pre>
  
  <p>-(Editor's note: not sure what this next output is from...)</p>
  
  <pre><code> [1] "UserID"         "compl_bin"      "Sex.x"          "PHQ_base"       "EFE"            "Neuro"          "Intervention.x"
   [8] "depr0"          "stress0"        "subject"        "time"           "PHQ"            "error"          "stress"       
  [15] "hours" 
  </code></pre>
  
  <p>Then I use geeglm function:</p>
  
  <pre><code>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"))
  </code></pre>
  
  <p>I am getting an error:</p>
  
  <pre><code>"Error in geese.fit(xx, yy, id, offset, soffset, w, waves = waves, zsca,  : 
    nrow(zsca) and length(y) not match"
  </code></pre>
  
  <p>If I remove variables as.factor(error) and hours, geeglm does not complain, and I am getting the output. The function does not work with error and hours variables. I check the length of all the variables, they are equal. Could you please help me figure out what is wrong?</p>
  
  <p>Many thanks!</p>