This utility function prepares tidy choice data for fast MCMC samplers.
vd_prepare(dt, Af = NULL)
tidy choice data (columns: id, task, alt, x, p, attributes)
(optional) contains a full design matrix (for attribute-based screening), or, more generally, a design matrix used for attribute-based screening
list containing information for estimation functions
Note: This function is only exported because it makes it easier to tinker with this package.
This function re-arranges choice data for fast access in highly-optimized MCMC samplers.
It Pre-computes task-wise total expenditures sumpsx
and generates indices xfr
,xto
,lfr
,lto
for fast data access.
#minimal data example
dt <- structure(list(id = c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L, 2L),
task = c(1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L),
alt = c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L),
x = c(1, 0, 2, 1, 0, 1, 2, 3, 1, 1, 0, 1),
p = c(0, 1, 1, 1, 2, 0, 2, 2, 1, 2, 1, 1),
attr2 = c(1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0),
attr1 = c(0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1)),
class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,-12L))
#run prep function
test <- dt %>% vd_prepare