[R] problem with 'svyby' function from SURVEY package

From: Roni Kobrosly <slyron84_at_gmail.com>
Date: Thu, 03 Jun 2010 00:14:35 -0400


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                         



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?


        [[alternative HTML version deleted]]

R-help_at_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. Received on Thu 03 Jun 2010 - 04:16:25 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 03 Jun 2010 - 16:20:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive