[R] calling svydesign function that uses model.frame

Richard Valliant rvalliant at survey.umd.edu
Tue Apr 12 03:21:18 CEST 2005


I need help on calling the svydesign function in the survey package
(although this error appears not to be specific to svydesign). I am
passing parameters incorrectly but am not sure how to correct the
problem.

## Call the main function PS.sim (one of mine).  The dots are
parameters I omitted to simplify the question.
## y.col, str.col, clus.id, and PS.col are names of columns in the
object pop.

PS.sim(pop=small, y.col="NOTCOV", 
		...,str.col="new.str", clus.id="new.psu", 
		PS.col="PS.var", ...)

## A data.frame called sam.dat is generated by PS.sim.  Its first 3
lines are:

 ID new.str PS.var new.psu NOTCOV       wts
213       1      3            2                 2          37.7
236       1      3            2                 2          37.7
286       1      2            2                 2          37.7

## Next, try to generate a survey design object.
## This fails (note the use of the calling parms clus.id and str.col):
svydesign(id = ~clus.id, strata = ~str.col, weights = wts, 
     data = sam.dat, nest = TRUE)

## with this error:     
Error in model.frame(formula, rownames, variables, varnames, extras,
extranames,  : 
        invalid variable type

## It looks like clus.id is substituted as "new.psu", likewise for
str.col

## The call below works when I use the actual column names not the
calling parms:
svydesign(id = ~new.psu, strata = ~new.str, weights = wts,data =
sam.dat, nest = TRUE)


I need to call svydesign with the parms I use to invoke the main
function PS.sim, i.e., ~clus.id and ~str.col. 
How do I do that?

Thanks,
Richard




More information about the R-help mailing list