survey weights in R [message #25942] |
Thu, 12 January 2023 21:44 |
dhivvyajp@am.amrita.edu
Messages: 4 Registered: January 2023
|
Member |
|
|
I am currently working on this dataset IAMR7DFL.DTA
I am looking forward to use survey weights for the chi-square test and logistic regression. After searching in the internet, I came across this piece of code.
my_design <-svydesign(id=~Mendata$psu, weights=~Mendata$wt, strata=Mendata$strata, data=Mendata, survey.lonely.psu = "adjust")
It worked and my_design shows this
> my_design
Stratified 1 - level Cluster Sampling design (with replacement)
With (9102) clusters.
svydesign(id = ~Mendata$psu, weights = ~Mendata$wt, strata = Mendata$strata,
data = Mendata, survey.lonely.psu = "adjust")
After that when I am doing the chi-square test like this,
I am getting the following error.
> svychisq(~InternetUsage+RuralOrUrban, my_design, statistic="adjWald")
Error in onestrat(x[index, , drop = FALSE], clusters[index], nPSU[index][1], :
Stratum (51) has only one PSU at stage 1
Kindly help me to resolve this issue and also please specify the analysis of chi-square test and logistic regression with and without survey weights.
|
|
|
Re: survey weights in R [message #25946 is a reply to message #25942] |
Fri, 13 January 2023 12:14 |
Shireen-DHS
Messages: 140 Registered: August 2020 Location: USA
|
Senior Member |
|
|
Hello,
I have done this recently in R and the code below works. I see you have the option to adjust for error your received but can you try the following code for your data?
# setting the survey design using the weight (wt), psu, and strata
mysurvey<-svydesign(id=Mendata$v021, data=IRdata, strata=Mendata$v022, weight=Mendata$wt, nest=T)
options(survey.lonely.psu="adjust")
# chi-square results
svychisq(~InternetUsage+RuralOrUrban, mysurvey)
Best,
Shireen Assaf
The DHS Program
|
|
|
|
|