I have the following data in a data.table:
h x1 y1 swNx11
1: 1 39.075565717 0 1.03317231703408
2: 1 40.445951251 0 7.14418755725832
3: 1 37.800722944 0 0.435946586361557
4: 1 41.085221504 0 0.381347141150498
5: 1 36.318077491 0 0.497077163135359
---
24996: 25 39.110138193 0 0.942922612158002
24997: 25 39.331940413 0 1.42227399208458
24998: 25 37.479473784 0 0.390657876415799
24999: 25 35.892044242 0 0.599937357458247
25000: 25 40.699588303 0 0.486486760245521
I've created a function to analyse them in svyglm:
msmMC <- function(y, x, sw, name){
msm <- svyglm(y ~ x,family=quasibinomial(link="logit"),design = svydesign(~ 1, weights = ~ sw))
out <- cbind("name",coef(summary(msm))[2,1],coef(summary(msm))[2,2])
return(out)
}
msmswNx1<-dt2[,list(dtmsm=list(msmMC(y1, x1, swNx1, Nx1))),by="h"]
outNx1 <- unlist(dt.lm[,msmswNx1])
When I run this function, I get the following error:
Error in [.data.table(dt2, , list(dtmsm = list(msmMC(y1, x1, swNx1, : column or expression 1 of 'by' or 'keyby' is type list. Do not quote column names. Useage: DT[,sum(colC),by=list(colA,month(colB))]
Yet it works fine with a different model, such as glm or polr. So what is going on here? Why is svyglm so picky about by-group processing with a data.table?