An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090402/a2db4190/attachment-0001.pl>
problem with svyglm()
2 messages · Federico Calboli, Thomas Lumley
3 days later
On Thu, 2 Apr 2009, Federico Calboli wrote:
Hello,
I'm trying to use the function svyglm in the library survey.
I create a data survey object:
data_svy<- svydesign(id=~PSU, strata=~sample_domain,
weights=~sample_weight, data=data, nest=TRUE)
and I try to use svyglm() with little success:
R<-svyglm(data_svy[,4]~(data_svy[,iCol]==listModality[[iVar]]
[iMod]),design=data_svy, family=binomial(link="logit")
Error in svyglm.survey.design(data_svy[, 4] ~ (data_svy[, iCol] ==
listModality[[iVar]][iMod]), :
all variables must be in design= argument
I don't know what you are trying to do here, but svyglm() wants a formula where the variables are all in the design object. Also, data_svy[,iCol] won't do what you probably expect, since data_svy isn't a data frame.
Puzzlingly the following code works: R<-glm(data[,4]~(data[,iCol]==listModality[[iVar]][iMod]), family=binomial(link="logit")
There are two differences here. The first is that glm() doesn't require
variables to be in the data= argument, because it doesn't have to carry
around the design meta-data. The second is that data[,4] is a
well-defined variable, whereas data_svy[,4] is meaningless.
It's hard to guess exactly what you are trying to do here. If you are
trying to do a loop over regression models then you have to do something
like
for(v in vnames) {
models[[v]] <- eval(bquote( svyglm(y~x+.(as.name(v)), design=data_svy)))
}
-thomas