Reputation: 1
ftp://cran.r-project.org/pub/R/web/packages/survey/vignettes/domain.pdf
The complete dataset is tch2012. However, I am only interested in the subpopulation of tch2012 in which two criteria are met: age <= 5
and gender == "female".
And within that subpopulation, I want to compare those with the disease (disease == "1")
and without the disease (disease == "0").
This is the code I wrote:
library(survey)
tch2012.tsl.dsgn <- svydesign(id= ~HOSP_KID, strata= ~KID_STRATUM, weights = ~DISCWT, data = tch2012, nest = TRUE)
create a pointer to subpopulation of female pediatric age 5 years and under
tch2012_f_age5.tsl.dsgn <- subset(tch2012.tsl.dsgn, AGE <= 5 & gender == "female")
weighted data of total number with and without the disease in female pediatric patients age 5 years and under
svyby(~count, ~disease, design=tch2012_f_age5.tsl.dsgn, svytotal)
However, I got the below error message when I ran the svyby()
Error in sum(sapply(covmats, ncol))
: invalid 'type' (list)
of argument
Since I am not very familiar with dealing with weighted data, I am no clue how to trouble shoot.
Thanks in advance for the help!
Upvotes: 0
Views: 441
Reputation: 6094
this code works
library(survey)
data(api)
dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)
x <- subset( dclus1 , sch.wide == 'Yes' )
svyby(~api00, ~stype, design=x, svytotal)
please edit your question by adding a minimal reproducible example How to make a great R reproducible example?
Upvotes: 1