"svydesign" and referencing a data frame with weighted cases.

I’ve read in weighted data from a .sav (SPSS) file and created a survey design for weighting cases with the following:

install.packages("survey")
library("survey")
library(haven)
YRBS2017 <- read_sav("Desktop/YRBS2017/YRBS2017.sav")
attach(YRBS2017)
View(YRBS2017)
YRBS17 <- svydesign(id=~psu, weight=~weightvar, strata=~stratum, data=YRBS2017, nest=TRUE)

Then I ran geepack for the Zou Regression Model

install.packages("geepack")
library(geepack)
geeglm.log.poisson <- geeglm(formula = Q25 ~ QN84 + Age + Sex + QN42, data = YRBS17, family = poisson(link = "log"), id = IDNo, corstr = "exchangeable")

However, the code returns the following error message:

Error in as.data.frame.default(data) :

cannot coerce class ‘c("survey.design2", "survey.design")’ to a data.frame

I think the issue is that the svydesign function gives an output that is of object type "survey design" rather than "data frame." So, I’m asking geepack to make the model, but I’m not giving it a data frame to obtain data from. How might I transform a survey design object into a data frame object while retaining the weighted properties I need for analysis? I have never had to do the steps requiring library "survey" so I don't know exactly how to do it. Can I manually tell R to treat the object as a data frame and it'll obey; how?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.