8

I have a question regarding calling variables in svycontrast() function with survey package. I'm trying to automate some contrast against a fixed parameter. I can do that no problem like this:

library(survey)    
data(api)

dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)

diff <- svyby(~enroll, by = ~cnum, dclus1, na.rm.all = FALSE, svymean, covmat = T, vartype = "se")

parameter <- 550

svycontrast(diff, quote(`1` - parameter))

#           nlcon SE
# contrast 2.8182  0

However, I have been for hours trying to figure out how to call that rowname `1`, but with different approaches I keep getting mostly the following error message:

row <- quote(1)

svycontrast(diff, quote(row - parameter))
Error in row - parameter : non-numeric argument to binary operator

Any help would be very much appreciated.

Waldi
  • 39,242
  • 6
  • 30
  • 78
David Jorquera
  • 2,046
  • 12
  • 35

2 Answers2

7

You could use substitute combined with as.symbol:

row <- 1

substitute(row - parameter, list(row = as.symbol(row)))
# `1` - parameter

svycontrast(diff, substitute(row - parameter, list(row = as.symbol(row))))

#          nlcon SE
#contrast 2.8182  0
Waldi
  • 39,242
  • 6
  • 30
  • 78
7

I think you can use bquote instead of quote here

> row <- 1

> svycontrast(diff, bquote(.(as.name(row)) - parameter))
          nlcon SE
contrast 2.8182  0
ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81