pt_auc: Area-under-the-curve demand calculation

View source: R/pt_auc.R

pt_aucR Documentation

Area-under-the-curve demand calculation

Description

This function calculates the area-under-the-curve (AUC). See details for additional information.

Usage

pt_auc(pt, id_var, type, qmax = NULL, 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", equation-derived demand indicators for each of the groups as identified by the 'group_var' are visualized. When 'type' equals "individual", equation-derived demand indicators are calculated for each individual as identified by 'id_var'.

qmax

The maximum consumption amount possible on the purchase task. This must be provided in order to calculate AUC proportionately.

group_var

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

Details

The use of AUC as a measure of demand was proposed by Amlung et al. (2015), and is derived by calculating the area of several trapezoids under the empirical consumption curve. A putative advantage of AUC is that it is an aggregated empirical indicator that does not rely on model assumptions inherent in non-linear regression approaches. Of note, although conceptually reflecting the overall demand curve, in practice it has been highly correlated with individual demand curve indicator of Omax (Amlung et al., 2015).

The area of each trapezoid is calculated by the formula (P2 − P1)*[(Q2 + Q1)/ 2]. Here, P2 and P1 are price P and price P - 1, whilst Q2 and Q1 are consumption Q at price P and price P - 1. The AUC is expressed as a proportion of the total area (range from 0 to 1), allowing for comparison across different purchase tasks or samples.

Amlung, M., Yurasek, A., McCarty, K. N., MacKillop, J., & Murphy, J. G. (2015). Area Under the Curve as a Novel Metric of Behavioral Economic Demand for Alcohol. Experimental and Clinical Psychopharmacology, 23(3), 168.

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_auc(pt3$data, id_var = "ID", type = "individual", qmax = 99)


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