On May 21, 2010, at 11:48 AM, Thomas Lumley wrote:

On Thu, 20 May 2010, David Winsemius wrote:

Almost. Testing with the examples on svytable help page:

test <- function(Z){                         
fmla <- as.formula( paste(" ~ ", paste(c(Z, "stype"), collapse= "+")))
 chisq <- svychisq( fmla, design=rclus1,
                               statistic="adjWald", round=4)
}

reslt <- test("sch.wide")
reslt

        Design-based Wald test of association

data: svychisq(fmla, design = rclus1, statistic = "adjWald", round = 4)
F = 2.2296, ndf = 2, ddf = 13, p-value = 0.1471

The "con" object probably does not exist, so one needs to pass a character name to the formula.


That works, but you can see why I prefer

test<-function(formula){
   svychisq(update(formula, ~.+stype), dclus1)
}

test(~sch.wide)


I certainly can see the reason for your preference. Much cleaner. I also looked at the help page for update.formula as suggested by the update help page. So, when the R interpreter encounters the "~" in the test call, it acts in a manner something akin to encountering back- quote or "$" and defers evaluation of "sch.wide"?


Model formulas were invented for precisely this purpose. You can work around them using character strings or using bare symbol names and substitute, but it's really easier just to work with the formula.

   -thomas

Thomas Lumley                   Assoc. Professor, Biostatistics
tlum...@u.washington.edu        University of Washington, Seattle


David Winsemius, MD
West Hartford, CT

______________________________________________
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.

Reply via email to