DeclareDesign / randomizr

randomizr: Easy-to-Use Tools for Common Forms of Random Assignment and Sampling
https://declaredesign.org/r/randomizr
Other
36 stars 9 forks source link

unquoted variable names in prob argument #76

Closed graemeblair closed 6 years ago

graemeblair commented 6 years ago

For probability-proportional-to-size sampling (and other designs), you may want to use an unquoted variable name in the probability to set the inclusion probability as a function of that variable. This doesn't seem to work in the same way that block names etc. work.

my_pop <- declare_population(N = 1000, smp_prob = runif(N, 0, 1))
my_smp <- declare_sampling(prob = smp_prob)

dat <- my_pop()
> my_smp(dat)
Error in sample.int(length(x), size, replace, prob) : 
  incorrect number of probabilities

Seems like the NSE should work in the same way taking the blocks variable out of data as taking the variable here smp_prob out of data:

decl <- eval_tidy(quo(declare_rs(N=!!nrow(data), !!!options)), data)

  data <- fabricate(data,
    !!S := draw_rs(!!decl),
    !!samp := obtain_inclusion_probabilities(!!decl),
    ID_label = NA
  )

Any ideas why this isn't working?

graemeblair commented 6 years ago

sorry wrong repo