简体   繁体   中英

How to use Survey Package in R to run linear regression

I am attempting to analyze data from the National Health Interview Survey to look at the association between nativity and salary. To do so, I need to use the survey package in R to account properly for weighting, strata, etc... I have written the code with the survey function but can't seem to get a regression to run since I am given the error message:

"Error in onestrat(x[index, , drop = FALSE], clusters[index], nPSU[index][1], : Stratum (6001) has only one PSU at stage 1"

I'm not sure what to fix and hoping someone can help! Here is the code I have run so far

nhissvy <- svydesign(id=~PSU, strata=~STRATA,
                 nest = TRUE,
                 weights=~PERWEIGHT,
                 data=NHIS1)

 summary(svyglm(adj_SALARY ~ AGE+IMMIGRANT+FEMALE+MARRIED+NEWEDUC+YEAR_2015+YEAR_2016+YEAR_2017+YEAR_2018, design = nhissvy))

Here is more documentation from the CDC on how to use this function if it helps: https://www.cdc.gov/nchs/data/nhis/2016var.pdf

Thank you!

for that error, you might want to use the most conservative option listed here

options( survey.lonely.psu = "adjust" )

for more detail, check out the Regression Models and Tests of Association section of http://asdfree.com/national-health-interview-survey-nhis.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM