Hi there, I would like to use a formula inside a call to withReplicates in a survey analysis. If the initial call with formula expressed inside the function works as expected, defining the formula outside gives an error message. See example below, adapted from survey:withReplicates help page.
library(survey) library(quantreg) data(api) ## one-stage cluster sample dclus1<-svydesign( id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc) ## convert to bootstrap bclus1<-as.svrepdesign( dclus1, type="bootstrap", replicates=100) ## median regression withReplicates( bclus1, quote( coef( rq( api00~api99, tau=0.5, weights=.weights)))) theta SE (Intercept) 87.78505 18.850 api99 0.91589 0.028 # Defining formula outside Myformula <- as.formula( " api00~api99") # Rerun the same analysis withReplicates( bclus1, quote( coef( rq( formula= Myformula, tau=0.5, weights=.weights)))) Erreur dans eval(expr, envir, enclos) : objet 'api00' introuvable # I suspect the evaluation not done in the right environment. #If you specify with data option in rq, the initial dataframe, formula is then correctly evaluated but .weights are not found. withReplicates( bclus1, quote( coef( rq( formula= Myformula, tau=0.5, weights=.weights, data=apiclus1 )))) Erreur dans eval(expr, envir, enclos) : objet '.weights' introuvable Any help greatly appreciated O__ ---- Alain Le Tertre c/ /'_ --- Institut de Veille Sanitaire (InVS)/ Département Santé Environnement (*) \(*) -- Responsable de l'unité Statistiques & Outils ~~~~~~~~~~ - 12 rue du val d'Osne 94415 Saint Maurice cedex FRANCE Voice: 33 1 41 79 67 62 Fax: 33 1 41 79 67 68 email: a.leter...@invs.sante.fr ______________________________________________ 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.