About

In the DfD and DfE tasks it's convenient to create a txt file containing the gambles and load this file into the app with the functions provided by ShinyPsych. For this to work, the file must be in a specific form. This short tutorial shows you the form the files must have. If you'd like a template just check out the ShinyPsych app in your R library. It contains a folder called extdata which contains different lists we included as defaults or examples. The TwoOptExample.txt up to SixOptExample.txt are the files you can use as template. The first is also the file we're showing you here in this tutorial. Other gamble files in extdata are the ones named after the authors of papers in which the gambles were reported. Check the general tutorial page for a list of papers which we used for our default files.

Creating a File

Ok let's first read in the file. Note that you can also execute this code to read in the file in your R session, given that you have installed ShinyPsych.

# load library
library(ShinyPsych)

# get path to file
fil <- system.file("extdata", "TwoOptExample.txt",
                   package = "ShinyPsych")

# read in the file
gamble.df <- read.table(fil, header = TRUE, sep = "\t",
                    stringsAsFactors = FALSE)

# display the file
knitr::kable(gamble.df, align = rep("c", ncol(gamble.df)))

As you can see the structure is relatively straight forward. The first column gamble indicates the trial number. This will be the identifier when the trial order is randomized in the task. The next four columns are the two outcomes g1o1 and g1o2 and the two probabilities with which these outcomes occur g1p1 and g1p2. These four columns define the two outcomes of the first gamble g1. The next four columns do the same for the second gamble g2. Now if we would have choice problems with three gambles to choose from we would just add another four columns for gamble three g3o1, g3p1, g3o2 and g3p2. Same if we'd like to have more than two outcome-probability pairs per option. If we had three outcome-probability pairs we'd simply use g1o1, g1p1, g1o2, g1p2, g1o3 and g1p3. Note two things here: (1) all gambles must have the same number of outcome-probability pairs in the file. If, however, one of your gambles has fewer options than the other, just set the outcome and probability of that pair to 0. (2) because in the function the variables are indexed by name rather than order it is important to use the exact same names as indicated here.

You can use separators other than tabs, but you need to indicate this in createDfdList()/ createDfeList() as the default is set to sepFile = "\t". Also the file doesn't necessarily have to be a .txt file, it can be anything readable by read.table().

That's it. If you file has this form you can use it in your app...



mdsteiner/ShinyPsych documentation built on Feb. 12, 2022, 2:09 p.m.