rsurvey

The use of I() in svyciprop() in the Survey package


I want to estimate various proportions and their confidence intervals using the Survey package in R, using the svyciprop() function, like this

data(api)
dclus1<-svydesign(id=~dnum, fpc=~fpc, data=apiclus1)
svyciprop(~I(ell==0), dclus1, method="li")

I think I understand the principles of the I() function in R, but I do not understand the need for this function in this particular case. In fact, if I leave out I(), equal results are being produced.

data(api)
dclus1<-svydesign(id=~dnum, fpc=~fpc, data=apiclus1)
svyciprop(~ell==0, dclus1, method="li")

Thank you for your help and let me know if more information is needed.


Solution

  • The I() in a formula says to evaluate the expression ell==0 and use the result as a predictor. It is necessary when the expression contains operators like +, -, etc. that are interpreted specially in a model formula.

    In this case it isn't necessary, because == doesn't mean something special in a model formula. I'd assume it is used for consistency: whenever you want to construct a variable in a model formula, wrap the construction in I() to avoid the possibility of using an operator that will be misinterpreted.