0

i have a dataframe with information of participants' country, demographic characteristics (e.g. age, gender) and biochemical measurements (e.g. weight, bp readings etc). I also have the psu and weights calculated for each participant. i have:

steps_3jan <- STEPS_All_countries_4_ %>% select(country, year,
                                                age,
                                                sex,
                                                m11,
                                                m12,
                                                stratum,
                                                psu,
                                                wstep1,
                                                wstep2,
                                                wstep3)

steps_3jan <- subset(steps_3jan, !is.na(psu))
steps_3jan <- subset(steps_3jan, !is.na(wstep1))
steps_3jan <- subset(steps_3jan, !is.na(stratum))

steps_3jan_matrix <- as.data.frame(steps_3jan)

I was was trying to use svydesign to do this:

steps_3jan_design <- svydesign(id =~psu, 
                               strata =~stratum,
                               nest = TRUE,
                               weights = ~wstep1,
                               data = steps_3jan_matrix)

svymean(~age, steps_3jan_design, na.rm = TRUE)

but got the below error:

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

if anyone is able to help it would be greatly appreciated!

jpsmith
  • 11,023
  • 5
  • 15
  • 36
  • Can you make your post [reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and provide your data using `dput(STEPS_All_countries_4_)`? – jrcalabrese Jan 06 '23 at 15:14
  • In particular, is it true that stratum 0 has only one PSU? – Thomas Lumley Jan 15 '23 at 21:01

0 Answers0