Reputation: 33
I am doing some studywork using PIRLS 2016 and PIRLS 2021 data. I need to perform linear regression with weighted data (I apologize for the non-english language in the code). To correctly calculate the weighted data I used:
imputetas.kopas.X <- lapply(1:5,
function(x, dati = X) {
dati$PV <- unlist(X[, paste0("ASRREA0", x)])
return(dati)
})
Then I created a design using:
dizains.X.1 <- svrepdesign(repweights = "TOTWGT",
type = "JK1",
scale = 1,
combined.weights = TRUE,
weights = P2016.1$X.TOTWGT,
data = imputationList(imputetas.kopas.X))
and
survey_design_Regr_ASBGSCR1 <- svydesign(
ids = 1:nrow(Regr.ASBGSCR1),
weights = P2016.1$X.TOTWGT,
data = Regr.ASBGSCR1
)
When trying to combine everything in and perform the linear regression:
modelis1 <- MIcombine(with(dizains.X.1, svyglm(formulla, design = survey_design_Regr_ASBGSCR1)))
This is the "formulla" variable:
formulla <- as.formula(paste("X.ASBGSCR ~ X.ASBGERL + X.ASBGSLR + X.ASBH03A + X.ASBG03 + X.ASBGHRL + X.ASBGSSB + X.ASBG06"))
And all of those variables are under the same data frame used in the design variable. I get an error stating:
Error in UseMethod("svyglm", design) :
no applicable method for 'svyglm' applied to an object of class "svyimputationList"
What have I done wrong?
Upvotes: 0
Views: 350
Reputation: 2765
You should not specify design=
inside the with()
call. The point of the with()
call is that it subsitutes each imputed data set in turn into the expression you supply. For example, on the help page for with.svyimputationList
designs<-svydesign(id=~id, strata=~sex, data=all)
results<-with(designs, svymean(~drkfre))
MIcombine(results)
there is no design=
argument specified to svymean
Upvotes: 1