Giter Club home page Giter Club logo

purchasetasks's Introduction

DOI

!! ARCHIVED !!

This script is based on an older version of PThelper, and as such has been archived in favour of the release of PThelepr 0.3.0. More information can be found [here].(https://github.com/PBCAR/PThelper)

Package Release

This script has been used to build an R package that provides a systematic approach to purchase task data processing. Download instructions and details for the {PThelper} package are available here.

PurchaseTasks Repository

This repository contains the script for processing purchase task data. This READ ME document introduces users to purchase tasks, and walks users through the process of running this script who have little working knowledge of R.

Introduction to Purchase Tasks

These demand instruments are used to measure the reinforcer pathology - the extent to which a value for a commodity is effected by increased cost. Greater demand (i.e. little sensitivity to price changes) is often associated with substance-related problems and use disorders (see Bickel et al. (2011). The Behavioral Economics and Neuroeconomics of Reinforcer Pathologies: Implications for Etiology and Treatment of Addiction). There are 5 different indices generated by the purchase task:

Breakpoint - The first increment of cost with zero consumption

Intensity - Consumption at the first price point

Omax - The maximum expenditure

Pmax - The price associated with the maximum total expenditure

Elasticity - Measures sensitivity of consumption to increases in cost

Overview of Processing

Purchase tasks often use branching logic in administering the questions, such that no further prices are presented after a zero response within an array. Individuals who contradict themselves at the last item of the array are considered missing and are removed, since it cannot be assumed that all subsequent responses would be zeroes.

Quality control removes individuals who:

i) Do not exhibit a decelerating trend (referred to as a trend violation). Does not include those with a starting value of 0

ii) Exhibit a bounce ratio of of 10% or higher (inconsistencies in values given)

iii) Exhibit 2 or more reversals. A reversal is 2 or more consecutive 0's prior to a positive value

Winsorization at the price level occurs for values with a z score +/- 3.99, whereby the outlying value is changed to one unit above the nearest non-outlying value. For the price level, a unit is 1 standard amount consumed such as 1 drink, 1 cigarette, or 1 gram of cannabis.

Winsorizing at the index level occurs for values with a z score +/- 3.99. Outliers are recoded as 0.001 greater than the next highest non-outlying value, thus retaining order.

The winsorizing type used for both price and index level values is preserve order winsorization, as opposed to other techniques such as replacing all outliers with the corresponding +/- 3.99 regular value rounded up or with a value that is a unit higher than the highest non-outlying value (see {beezdemand} package documentation).

Purchase Task Template

Processed data provides two sets of these indices:

i) Winsorized variables (at both the price and index level), as denoted by the suffix _W

ii) Non-winsorized variables (no outlier management)

Packages:

This script utilizes the {beezdemand} package to process the behavioural economic data. It also utilizes {dplyr} and {psych} packages

Changes Required:

There are 7 changes required by the user of this script. These are outlined at the top of the script, with examples:

a) Set your working directory - This is the file location of your data to be analyzed. To set your working directory, go to:

  Session > Set Working Directory > Choose Directory

b) Input the name of your data file (this script is set up to only import .csv files)

c) Input the name of your ID variable

d) Copy and Paste all the names of the purchase task items

e) Assign the price associated with each purchase task item

f) Input the maximum allowed value identified in the purchase task

g) Input the total N individuals in the data set

The Script:

The rest of the script provides prompts for the user, specifically pointing out when they should look at the output in the console for any possible changes/ information needed. At the end, a summary of the data is provided (also in the console). The final part of the script exports the processed data and summary tables to the working directory that was set at the beginning of the document (4 .csv files total):

i) "purchase.task.csv" - This merges the processed data with the original inputted data (all N)

ii) "PT.variables.csv" - This provides the descriptive statistics of the purchase task variables (both winsorized and non-winsorized, as well as log10 and square root transformations of the winsorized index-level variables)

iii) "price.level.variables.csv" - This provides the descriptive statistics of the price-level variables (the initial items of the purchase task both winsorized and non-winsorized)

iv) "Appendix.csv" - This provides a table of all the outlying values that were changed by ID (through winsorizing)

Purchase Task Report

This script uses R-markdown to produce a PDF report of the processed data. It is an alternative to the output produced by the Purchase Task Template.R. The benefits of using this script to produce a report is that all the information about the data processing is provided and therefore documented.

It requires the user to:

a) Save the data set and the script in the same file location

b) Name of the .csv file

c) The name of the ID variable

d) The names of the purchase task item variables

e) The price of each purchase task item

f) Input the maximum allowed value identified in the purchase task

g) Input the total N individuals in the data set

purchasetasks's People

Contributors

kbelisar avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

purchasetasks's Issues

Improper BP if lowest price is non-zero

The current script does not create a proper breakpoint value when the lowest price included in the purchase task != 0. Thus, need to capture the lowest price point and assign this value, rather than assume 0. Specifically in this section of code:

CREATE proper breakpoint variable

PT.final.results$Breakpoint <- PT.final.results$BP0
for (id_num in PT.wide2$id){
pt.sum <- sum(PT.wide2[PT.wide2$id==id_num,prices], na.rm = FALSE)
last.amount <- PT.wide2[PT.wide2$id==id_num,length(prices)+1]
if(is.na(PT.final.results$BP0[PT.final.results$id==id_num]) & (pt.sum==0)){
PT.final.results$Breakpoint[PT.final.results$id==id_num] <- 0
} else if (is.na(PT.final.results$BP0[PT.final.results$id==id_num]) & (last.amount>0)){
PT.final.results$Breakpoint[PT.final.results$id==id_num] <- as.numeric(prices)[length(prices)]+1
}
}

.RMD file

There is an issue with the .rmd file properly running due to the following code error if there are no individuals with their first two responses equalling 0:

PT.W.index[temp_ind,][,c('Q0d','Alpha','R2','EV','Omax','Pmax')] <- NA

Alpha-numeric IDs will cause errors

Will not run if IDs are alpha-numeric. Help users with transformation of IDs to numeric (using row names) and merge the numeric ID with the original alpha-numeric IDs.

PTs with no responses for higher prices

Sometimes, all participants exit the purchase task without reaching the final array. This causes prices to be 'NA' in the winsorization of price-level data (Step 4 of processing). Need to be able to process with a modified (shortened) price list.

Add script to visualize the different transformations

Log or square root transformations aid in achieving a more normalized distribution. There is some (albeit limited) evidence that the purchase task indices have an effect of magnitude and thus perform best when transformed even when a normal distribution is not an assumption of an analytical technique.

Adding a script to easily understand the effect a transformation has on skewness would be beneficial for non-R users.

Re-create script as set of functions

Arguably, the amount of script can be daunting for non-R users. Stream-lining the various steps outlined in the current Purchase Task script in the form of functions would be beneficial for users, allowing the focus to be on what each step of the process achieves. It can also allow for customization at each step.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.