Hello, I'm using a complex survey dataset and my goal is to simply spit out a bunch of probability-weighted outcome variable means for the different levels of covariate. So I first define the structure of the study design (I'm using the CDC's NHANES data):
dhanes <- svydesign(id=~PSU, strat=~STRATA, weight=~lab_weight, data=final, nest=TRUE) No problem there. Now I use the "svyby" function as follows: svyby(~outcome, ~covariate, design=dhanes, svymean, na.rm=T) -> haha print(haha) covariate outcome se.outcome 1 1 0.4961189 0.08828457 2 2 0.4474706 0.22214557 3 3 0.5157026 0.12076008 4 4 0.6773910 0.20605025 NA NA 0.8728167 0.15622274 ...and it works just fine. I get a nice table of the mean and standard error for each level of the covariate. I started writing a custom function to automate this and I had problems. Consider this really basic custom function (that does not seem very different from the above code): this_is_a_test <-function(outcome, covariate) { svyby(~outcome, ~covariate, design=dhanes, svymean, na.rm=T) -> haha print(hah) } I get the following output: Error in `[.survey.design2`(design, nas == 0, ) : (subscript) logical subscript too long I really don't understand this because I haven't done anything too different. Before I can even start writing up the rest of the function, I have to settle this. Any ideas? -Roni [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.