Apologies if this is in the manual, but I've been searching all day and I can't find it.
I want to run an LC model on choice data I have. In both the demographic data and the alternative attribute data, some columns are continuous, some are binary, and some are categorical.
I'm at a loss for how to code this.
For example, I have the following in the attributes:
* price (continuous)
* side effect risk (categorical: low, medium, high)
* over-the-counter (binary: yes / no)
In the demographics, similarly, I have:
* age (continuous)
* education (categorical: primary, secondary, university, more)
* prior doctor's visit (categorical: yes, no, unknown)
Here's what I've got so far, for a 3-class model, with 3 alternatives at each choice task:
Code: Select all
apollo_beta = c(
asc_1 = 0,
asc_2 = 0,
asc_3 = 0,
price_a = 0,
price_b = 0,
price_c = 0,
sfx_a = 0,
sfx_b = 0,
sfx_c = 0,
otc_a = 0,
otc_b = 0,
otc_c = 0,
delta_a = 0,
educ_a = 0,
prior_a = 0,
age_a = 0,
delta_b = 0,
educ_b = 0,
prior_b = 0,
age_b = 0,
delta_c = 0,
educ_c = 0,
prior_c = 0,
age_c = 0,
)
apollo_fixed = c("asc_3", "delta_c","educ_c","prior_c", "age_c")
#Define latent class components
apollo_lcPars=function(apollo_beta, apollo_inputs){
lcpars = list()
lcpars[["price"]] = list(price_a, price_b, price_c)
lcpars[["sfx"]] = list(sfx_a, sfx_b, sfx_c)
lcpars[["otc"]] = list(otc_a, otc_b, otc_c)
### Utilities of class allocation model
V=list()
V[["class_a"]] = delta_a + educ_a*educ + prior_a*prior
V[["class_b"]] = delta_b + educ_b*educ + prior_b*prior
V[["class_c"]] = delta_c + educ_c*educ + prior_c*prior
### Settings for class allocation models
classAlloc_settings = list(
classes = c(class_a=1, class_b=2, class_c=3),
utilities = V
)
lcpars[["pi_values"]] = apollo_classAlloc(classAlloc_settings)
return(lcpars)
}
Code: Select all
Error in educ_a * educ : non-numeric argument to binary operator
In addition: Warning message:
In Ops.factor(prior_a, prior) : ‘*’ not meaningful for factors