View source: R/plot_diagnostics.R
plot_diagnostics | R Documentation |
This function diagnoses individual demand, by visualizing empirical consumption or fitted demand curves (linear or exponentiated). This function can be used to assess fitted demand curves of those with poor R^2 values (default is < 0.5) or those that are greater than a set number of standard deviations away from the mean (default is |3|). Alternatively, this function can be used to visualize all empirical demand or individual demand curves. See details for further information.
plot_diagnostics(
pt,
id_var,
type = NULL,
diagnostics = "all",
threshold = NULL,
zero_val = 0.001,
n_rc = c(4, 5)
)
pt |
A data frame consisting of the 'id_var', purchase task variables, alpha or eta (depending on the type of demand curve to diagnose), Q0 and k-value if 'type' is "curve", as well as and R^2 values is 'diagnostics' argument is "r2". |
id_var |
The name of the unique identifier as identified in the data frame. |
type |
The type of demand to be visualized. One of c("empirical","linear","curve"). |
diagnostics |
The diagnostic used to identify potentially poor-quality demand curves when 'type' is "linear" or "curve". One of c("r2","zscore","all"). The default is "all". |
threshold |
The threshold of R^2 or z-score, depending on the 'diagnostics' selected. For 'diagnostics' "r2", the default is 0.5, thus plotting those with R^2 scores lower than 0.5. For 'diagnostics' "zscore", the default is 3, plotting those with a demand value (alpha or eta) value that is greater than 3 standard deviations away from the mean (z-score > |3|). |
zero_val |
For 'type' "linear", the value to substitute zero values in the price and consumption data (default is 0.001). |
n_rc |
The number of rows and columns used to display individual curves. The default is c(4,5). |
To diagnose empirical consumption before or after quality control has been implemented, this function provides users the ability to plot individual responses on the purchase task, similar to the consumption visualization produced using the 'plot_summary()' function. To diagnose fitted linear or exponentiated demand curves, this function will produce individual demand curves similar to those produced for overall demand in the 'pt_linear' or 'pt_curve()' function, respectively.
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")
pt4 <- pt_curve(pt3$data, id_var = "ID", type = "individual")
### --- Function Example
plot_diagnostics(pt4, id_var = "ID", type = "curve", diagnostics = "r2", threshold = 0.7)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.