pt_linear: Linear (ln-ln) demand curve fitting

View source: R/pt_linear.R

pt_linearR Documentation

Linear (ln-ln) demand curve fitting

Description

This function fits a linear (ln-ln) demand curve in order to calculate eta. See details for additional information on the linear demand equation.

Usage

pt_linear(pt, id_var, type = NULL, zero_val = 0.001, group_var = NULL)

Arguments

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","individual"). The default is "overall" which will calculate overall demand for the entire data frame. For 'type' "group", demand for each of the groups as identified by the 'group_var' are visualized. When 'type' equals "individual", the equation-derived demand indicator eta is calculated for each individual as identified by 'id_var'.

zero_val

The value to substitute zero values in the price and consumption data (default is 0.001).

group_var

The name of the grouping variable when 'type' equals "group".

Details

The linear demand equation allows for elasticity (eta) to be represented by a constant across the span of the prices. Eta is estimated from the slope of the linear demand equation, and represents the percent change in consumption associated with a one percent increase in price by taking the natural log of both consumption and price. See Gilroy et al. (2020) for further discussion on eta.

Gilroy, S. P., Kaplan, B. A., & Reed, D. D. (2020). Interpretation (s) of elasticity in operant demand. Journal of the Experimental Analysis of Behavior, 114(1), 106-115.

Value

A ggplot2 graphical object; For 'type' "individual", the original pt data frame plus the derived values for each individual is returned.

Examples

### --- 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
pt4 <- pt_linear(pt3$data, id_var = "ID", type = "individual")


PBCAR/PThelper documentation built on May 13, 2024, 3:45 p.m.