View source: R/pt_curve_mixed.R
pt_curve_mixed | R Documentation |
This function derives overall demand indicators using a mixed effects exponentiated equation (Kaplan et al., 2021) for the entire sample or by a grouping variable. The overall demand curve will be visualized alongside each individual demand curve. See details for further information on reaching convergence using mixed effects exponentiated equations.
pt_curve_mixed(pt, id_var, type = NULL, k = NULL, group_var = NULL)
pt |
A data frame consisting of the 'id_var' and purchase task variables. |
id_var |
The name of the unique identifier as identified in the data frame. |
type |
The level for fitting the demand curves, one of c("overall","group"). The default is "overall" which will calculate the overall demand for the entire data frame. For 'type' "group", equation-derived demand indicators for each of the groups as identified by the 'group_var'. |
k |
The k-value to use in the exponentiated demand equation. The default is NULL, in which the k-value is calculated from the entire sample, with k representing the span of consumption in log units. Otherwise, a single numerical value can be given as the k-value, allowing for comparisons across studies, since k influences the calculation of alpha. When k is calculated from the entire sample, it is calculated using the mean average consumption at the lowest and highest price points and in instances when the mean average consumption at the highest price point is 0, the lowest non-zero mean consumption is used. |
group_var |
The name of the grouping variable when 'type' equals "group". |
To reach convergence using a mixed effects approach, starting values for each individual (the random effects) are obtained by fitting an exponentiated demand equation to each individual's data. The starting values for the fixed effects are obtained by fitting an exponentiated demand equation to each group's mean data. To also assist with convergence, two mixed effects models are run. The first relaxes the tolerance of the convergence criteria to 1e-3 (from the default 1e-6). The coefficients from this initial model provide the starting values for a second fitted mixed model with a more stringent tolerance level (1e-6), as recommended by Kaplan et al. (2021). If the second model with a more strict tolerance does not converge, then the initial model is returned alongside a message in the console. If the model does not reach convergence despite the relaxed tolerance values, then the non-converged results using the regular default tolerance level are returned alongside a message in the console. These results should not be relied upon and instead it is recommended that fixed effect demand curves are fit instead by using the 'pt_curves()' function.
Kaplan, B. A., Franck, C. T., McKee, K., Gilroy, S. P., & Koffarnus, M. N. (2021). Applying Mixed-Effects Modeling to Behavioral Economic Demand: An Introduction. Perspectives on behavior science, 44(2-3), 333–358. https://doi.org/10.1007/s40614-021-00299-7
A ggplot2 graphical object
### --- Load Data
data("cpt_data")
### --- Prep Data
pt <- price_prep(cpt_data, id_var = "ID", vars = c(paste0("cpt",1:15)),
prices = c("0","0.05","0.10","0.20","0.30","0.40","0.50", "0.75","1","2","3","4","5","7.5","10"))
pt2 <- pt_prep(pt, id_var = "ID", type = "partial", remove0 = TRUE, max_val = 99)
pt3 <- pt_qc(pt2, id_var = "ID", type = "partial")
### --- Function Example
pt_curve_mixed(pt3$data, id_var = "ID", type = "overall")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.