From fbfec0d6a05f6f82ed97679e1969a5fbd31d29d8 Mon Sep 17 00:00:00 2001 From: Brent Kaplan Date: Tue, 14 Nov 2023 22:40:04 +0000 Subject: [PATCH] version 0.3.0 --- DESCRIPTION | 8 +- MD5 | 33 +++-- NAMESPACE | 4 + NEWS.md | 17 +++ R/beezdiscounting-package.R | 3 +- R/{five.fivetrial.R => five.fivetrial_dd.R} | 6 +- R/five.fivetrial_pd.R | 6 + R/fivetrial.R | 137 +++++++++++++++++- README.md | 84 ++++++++++- data/five.fivetrial.rda | Bin 1377 -> 0 bytes data/five.fivetrial_dd.rda | Bin 0 -> 1286 bytes data/five.fivetrial_pd.rda | Bin 0 -> 1456 bytes man/ans_dd.Rd | 2 +- man/ans_pd.Rd | 20 +++ man/calc_dd.Rd | 2 +- man/calc_pd.Rd | 20 +++ ...five.fivetrial.Rd => five.fivetrial_dd.Rd} | 10 +- man/five.fivetrial_pd.Rd | 16 ++ man/score_dd.Rd | 2 +- man/score_pd.Rd | 20 +++ man/timing_dd.Rd | 2 +- man/timing_pd.Rd | 20 +++ 22 files changed, 374 insertions(+), 38 deletions(-) rename R/{five.fivetrial.R => five.fivetrial_dd.R} (61%) create mode 100644 R/five.fivetrial_pd.R delete mode 100644 data/five.fivetrial.rda create mode 100644 data/five.fivetrial_dd.rda create mode 100644 data/five.fivetrial_pd.rda create mode 100644 man/ans_pd.Rd create mode 100644 man/calc_pd.Rd rename man/{five.fivetrial.Rd => five.fivetrial_dd.Rd} (59%) create mode 100644 man/five.fivetrial_pd.Rd create mode 100644 man/score_pd.Rd create mode 100644 man/timing_pd.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 03edb85..7465491 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: beezdiscounting Title: Behavioral Economic Easy Discounting -Version: 0.2.0 -Date: 2023-11-02 +Version: 0.3.0 +Date: 2023-11-14 Authors@R: person("Brent", "Kaplan", email = "bkaplan.ku@gmail.com", role = c("aut", "cre", "cph"), comment = c(ORCID = "0000-0002-3758-6776")) @@ -20,7 +20,7 @@ Depends: R (>= 2.10) Imports: dplyr, gtools, magrittr, psych, stringr, tidyr LazyData: true NeedsCompilation: no -Packaged: 2023-11-02 17:46:55 UTC; brent +Packaged: 2023-11-14 21:49:54 UTC; brent Author: Brent Kaplan [aut, cre, cph] () Repository: CRAN -Date/Publication: 2023-11-02 19:00:02 UTC +Date/Publication: 2023-11-14 22:40:02 UTC diff --git a/MD5 b/MD5 index e68b8e1..5fe0e11 100644 --- a/MD5 +++ b/MD5 @@ -1,33 +1,40 @@ -d33cb3984eb9a08d4bd5d9ee0637142e *DESCRIPTION -5522e33eb88c512bfc1d08830eccf3d7 *NAMESPACE -fda5ee2f3e8df853ee075bcf8940e215 *NEWS.md -ab9f1299ec0c841ad4f924117d252f9e *R/beezdiscounting-package.R -cd069940a1562dcc7adb05799ad427a8 *R/five.fivetrial.R -d56ba418257b7705fadf017b4995c626 *R/fivetrial.R +d5f450c1f607626c18ea9cfba9c82448 *DESCRIPTION +342530d95ad4b766e49b7677528929d8 *NAMESPACE +0ef00a31a908b6a98dd7929264b4eb84 *NEWS.md +3e6057f8f13c934dbeacc735cac3b3b1 *R/beezdiscounting-package.R +83389fa41fca7c90365b22949a5b85f9 *R/five.fivetrial_dd.R +2e8675631127528847c1269e68036233 *R/five.fivetrial_pd.R +1bee5e182cdfc1e578475450a31b6f3e *R/fivetrial.R 9894fe75ea7a66300b487b4837c8d30f *R/mcq.R 61db9a8cc0978926481fc46c55acca12 *R/mcq27.R 2c4b07c6df0f02b1043041b0daf9bf22 *R/sysdata.rda b56ff2b193ecba52f9ec7f3b10cca008 *R/utils-pipe.R d916bcf04673165715fe983294b3deb0 *R/utils.R -d3370e31b3e7dd81a8a9b37347df2042 *README.md +64856f39312cf53585c4f0843112f0c0 *README.md ea124a494ad7922985532ad3b308e4d5 *build/partial.rdb -64187c42c1e51d09730a0c46f1e17295 *data/five.fivetrial.rda +5761877b984f869ad59040f83ebbc25b *data/five.fivetrial_dd.rda +8615198f52cac43ab1a638d6dd0b611a *data/five.fivetrial_pd.rda 71ddc0b43cc6405100ef6606e996d6e7 *data/mcq27.rda db865a9dedc30063e4865e0493bfa7c5 *inst/5.5_Trial_Discounting_Template_1k.qsf d9ad748b67535601df5f2c23bd0ef2ad *inst/CITATION -7f8f1853ab58cfe884a3c8a040e21e2d *man/ans_dd.Rd +d6fe4e3f3879ab6b636db1cb8ad992d7 *man/ans_dd.Rd +fbe6ec487156dbff0caea203c2bb9918 *man/ans_pd.Rd c6297fe0132f141edb3f784594217b08 *man/beezdiscounting-package.Rd -adadeb20c1caae90a0a6b3b6e725c750 *man/calc_dd.Rd -ba13fc31ec0115299c550462d7b205c2 *man/five.fivetrial.Rd +80f4cf80ce0895b7083a039b4d4d26c4 *man/calc_dd.Rd +81cdc236d15ee9041f3d89d72a07cb27 *man/calc_pd.Rd +8d0f911d17cbb3f94fe88b5714e07175 *man/five.fivetrial_dd.Rd +c8fb1499940617c08e9185ab68aad600 *man/five.fivetrial_pd.Rd 28926d9e3a31876cc148a7e422ea0cf7 *man/generate_data_mcq.Rd 7a46e4c5a7346fecea7adcbf37b03186 *man/inn.Rd e9ae858d6314fd3f23551d3debc89634 *man/long_to_wide_mcq.Rd 8c0548d2c0392d16bc57a3ba08d90f85 *man/long_to_wide_mcq_excel.Rd 795ba03a0c6138f9c081a62a46331ffe *man/mcq27.Rd 8f4aad003a999fae004ba9361f9a99d6 *man/pipe.Rd -815143364b15c4a8479ded940898f2cd *man/score_dd.Rd +3116fde558785a0dc0a007e27b660cba *man/score_dd.Rd 1be2a8451941d0321de8f8f9f12890bf *man/score_mcq27.Rd c08b4be1371c67dd13a071fca064ca6b *man/score_one_mcq27.Rd -07ba486fcdc7eaa0294f756f20f280df *man/timing_dd.Rd +08957df8391b0439c806b52d750f4818 *man/score_pd.Rd +65559d83c565dcf643f7a8fd17912ba3 *man/timing_dd.Rd +e25a935467bc508f57c6ce700ad63ee0 *man/timing_pd.Rd 8f1c66ed27d00bf88894f84bb9df0c1b *man/wide_to_long_mcq.Rd b91ee494fc68133e1bc2c0f79646ad0d *man/wide_to_long_mcq_excel.Rd diff --git a/NAMESPACE b/NAMESPACE index d1f2a9a..97e9667 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,13 +2,17 @@ export("%>%") export(ans_dd) +export(ans_pd) export(calc_dd) +export(calc_pd) export(generate_data_mcq) export(long_to_wide_mcq) export(long_to_wide_mcq_excel) export(score_dd) export(score_mcq27) +export(score_pd) export(timing_dd) +export(timing_pd) export(wide_to_long_mcq) export(wide_to_long_mcq_excel) importFrom(magrittr,"%>%") diff --git a/NEWS.md b/NEWS.md index a559584..2e83805 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,20 @@ +# beezdiscounting 0.3.0 + +## New features + +* Add functions for scoring 5.5 trial probability discounting task (from the Qualtrics template) including: `calc_pd()` +(and `score_pd()`, `timing_pd()`, and `ans_pd`). + +## Minor fix + +* Subsetting issue is fixed in `score_dd()` that would unintentionally drop all rows if both conditions were `FALSE`. + +## Other changes + +* Rename example data from `five.fivetrial` to `five.fivetrial_dd` for delay discounting. + +* Add example data `five.fivetrial_pd` for probability discounting. + # beezdiscounting 0.2.0 ## New features diff --git a/R/beezdiscounting-package.R b/R/beezdiscounting-package.R index 789d5be..821f9ec 100644 --- a/R/beezdiscounting-package.R +++ b/R/beezdiscounting-package.R @@ -10,4 +10,5 @@ utils::globalVariables(c( "attentionflag", "kval", "ed50", "Attend-SS", "Attend-LL", "magnitude", "question", "measure", "value", - "subjectid", "questionid")) + "subjectid", "questionid", + "hval", "ep50")) diff --git a/R/five.fivetrial.R b/R/five.fivetrial_dd.R similarity index 61% rename from R/five.fivetrial.R rename to R/five.fivetrial_dd.R index 8c0f389..620cc3d 100644 --- a/R/five.fivetrial.R +++ b/R/five.fivetrial_dd.R @@ -1,7 +1,7 @@ -#' Example Qualtrics output from the 5.5 trial discounting template. +#' Example Qualtrics output from the 5.5 trial delay discounting template. #' -#' An example dataset containing four participants' data (two typical discounting +#' An example dataset containing four participants' data (two typical discounting #' patterns and two patterns suggesting potential misattention to the task). #' #' @format Example Qualtrics output -"five.fivetrial" +"five.fivetrial_dd" diff --git a/R/five.fivetrial_pd.R b/R/five.fivetrial_pd.R new file mode 100644 index 0000000..61dcdae --- /dev/null +++ b/R/five.fivetrial_pd.R @@ -0,0 +1,6 @@ +#' Example Qualtrics output from the 5.5 trial probability discounting template. +#' +#' An example dataset containing four participants' data. +#' +#' @format Example Qualtrics output +"five.fivetrial_pd" diff --git a/R/fivetrial.R b/R/fivetrial.R index f78f0c8..274debb 100644 --- a/R/fivetrial.R +++ b/R/fivetrial.R @@ -7,7 +7,7 @@ #' @export #' #' @examples -#' score_dd(five.fivetrial) +#' score_dd(five.fivetrial_dd) score_dd <- function(df) { dd1 <- df |> dplyr::select(ResponseId, paste0("I", seq(1, 31, by = 2)), "AttendSS" = `Attend-SS`, @@ -31,8 +31,10 @@ score_dd <- function(df) { ddframe$kval[ddframe$index == indexes[i]] <- ifelse (ddframe$response[ddframe$index == indexes[i]] %in% "ss", recodess[i], recodell[i]) } - ddframe <- ddframe[-which(ddframe$ResponseId %in% ddframe$ResponseId[ddframe$index %in% "AttendSS"] & ddframe$index %in% "I1"), ] - ddframe <- ddframe[-which(ddframe$ResponseId %in% ddframe$ResponseId[ddframe$index %in% "AttendLL"] & ddframe$index %in% "I31"), ] + subset_indices <- which(ddframe$ResponseId %in% ddframe$ResponseId[ddframe$index %in% "AttendSS"] & ddframe$index %in% "I1") + ddframe <- if (length(subset_indices) != 0) ddframe[-subset_indices, ] else ddframe + subset_indices <- which(ddframe$ResponseId %in% ddframe$ResponseId[ddframe$index %in% "AttendLL"] & ddframe$index %in% "I31") + ddframe <- if (length(subset_indices) != 0) ddframe[-subset_indices, ] else ddframe ddframe$attentionflag[ddframe$index %in% "AttendSS" & ddframe$response %in% "ss"] <- "Yes" ddframe$attentionflag[ddframe$index %in% "AttendLL" & ddframe$response %in% "ll"] <- "Yes" ddframe$attentionflag[ddframe$ResponseId %in% ddframe$ResponseId[which(ddframe$attentionflag == "Yes")]] <- "Yes" @@ -54,7 +56,7 @@ score_dd <- function(df) { #' @export #' #' @examples -#' timing_dd(five.fivetrial) +#' timing_dd(five.fivetrial_dd) timing_dd <- function(df) { timing <- dplyr::select(df, ResponseId, dplyr::contains("Timing")) colnames(timing) <- gsub("Timing_First Click", "firstclick", colnames(timing)) @@ -91,7 +93,7 @@ timing_dd <- function(df) { #' @export #' #' @examples -#' ans_dd(five.fivetrial) +#' ans_dd(five.fivetrial_dd) ans_dd <- function(df) { ans <- df |> dplyr::select(ResponseId, paste0("I", 1:31), dplyr::starts_with("Attend")) |> @@ -111,10 +113,133 @@ ans_dd <- function(df) { #' @export #' #' @examples -#' calc_dd(five.fivetrial) +#' calc_dd(five.fivetrial_dd) calc_dd <- function(df) { return(dplyr::left_join(timing_dd(df), ans_dd(df), by = c("ResponseId", "index")) |> dplyr::left_join(dplyr::select(score_dd(df), ResponseId, attentionflag, kval, ed50), by = c("ResponseId")) |> dplyr::arrange(ResponseId, q)) } + +#' Score 5.5 trial probability discounting from Qualtrics template +#' +#' @param df A dataframe containing all the columns +#' +#' @return A dataframe with id, indexes, response, h value, and effective probability 50. +#' @importFrom stats complete.cases +#' @export +#' +#' @examples +#' score_pd(five.fivetrial_pd) +score_pd <- function(df) { + pd1 <- df |> + dplyr::select(ResponseId, paste0("I", seq(1, 31, by = 2)), "AttendSS" = `Attend-SS`, + "AttendLL" = `Attend-LL`) |> + dplyr::select(-dplyr::contains("Timing"), -dplyr::contains("DO")) + pdframe <- pd1 |> + tidyr::pivot_longer(cols = 2:ncol(pd1), names_to = "index", values_to = "response") %>% + dplyr::filter(complete.cases(.)) |> + dplyr::mutate(response = ifelse(stringr::str_detect(response, "for sure"), "sc", "lu")) + pdframe$hval <- NA + pdframe$attentionflag <- "No" + indexes <- paste0("I", seq(1, 31, by = 2)) + recodesc <- c("99", "56.72448", "35.510562", "19.390719", "10.173495", "5.290003", + "2.934058", "1.601445", "0.850963", "0.457604", "0.256064", + "0.134491", "0.074501", "0.035898", "0.022875", "0.012403") + recodelu <- c("80.628779", "43.714986", "27.856777", "13.422618", "7.435436", "3.905279", + "2.185294", "1.175139", "0.624436", "0.340825", "0.189036", + "0.098295", "0.051571", "0.028161", "0.017629", "0.010101") + for (i in seq_along(indexes)) { + if (length(pdframe$response[pdframe$index == indexes[i]]) == 0) next + pdframe$hval[pdframe$index == indexes[i]] <- ifelse (pdframe$response[pdframe$index == indexes[i]] %in% "sc", + recodesc[i], recodelu[i]) + } + subset_indices <- which(pdframe$ResponseId %in% pdframe$ResponseId[pdframe$index %in% "AttendSS"] & pdframe$index %in% "I1") + pdframe <- if (length(subset_indices) != 0) pdframe[-subset_indices, ] else pdframe + subset_indices <- which(pdframe$ResponseId %in% pdframe$ResponseId[pdframe$index %in% "AttendLL"] & pdframe$index %in% "I31") + pdframe <- if (length(subset_indices) != 0) pdframe[-subset_indices, ] else pdframe + pdframe$attentionflag[pdframe$index %in% "AttendSS" & pdframe$response %in% "sc"] <- "Yes" + pdframe$attentionflag[pdframe$index %in% "AttendLL" & pdframe$response %in% "lu"] <- "Yes" + pdframe$attentionflag[pdframe$ResponseId %in% pdframe$ResponseId[which(pdframe$attentionflag == "Yes")]] <- "Yes" + pdframe$hval[pdframe$index %in% "AttendSS" & pdframe$response %in% "lu"] <- "99" + pdframe$hval[pdframe$index %in% "AttendLL" & pdframe$response %in% "sc"] <- "0.010101" + + pdframe$hval <- as.numeric(pdframe$hval) + pdframe$ep50 <- 1/pdframe$hval + return(pdframe) + +} + +#' Extract timing metrics from 5.5 trial probability discounting from Qualtrics template +#' +#' @param df A dataframe containing all the columns +#' +#' @return A dataframe with ResponseId, indexes, values and timing +#' @importFrom stats complete.cases +#' @export +#' +#' @examples +#' timing_pd(five.fivetrial_pd) +timing_pd <- function(df) { + timing <- dplyr::select(df, ResponseId, dplyr::contains("Timing")) + colnames(timing) <- gsub("Timing_First Click", "firstclick", colnames(timing)) + colnames(timing) <- gsub("Timing_Last Click", "lastclick", colnames(timing)) + colnames(timing) <- gsub("Timing_Page Submit", "pagesubmit", colnames(timing)) + colnames(timing) <- gsub("Timing_Click Count", "totalclicks", colnames(timing)) + timing <- timing |> + tidyr::pivot_longer(cols = 2:ncol(timing), names_to = "question", values_to = "value") %>% + dplyr::filter(complete.cases(.)) + timing$q <- NA + timing$question <- gsub("Attend-LL", "AttendLL", timing$question) + timing$question <- gsub("Attend-SS", "AttendSS", timing$question) + timing <- timing |> + tidyr::separate(question, c("index", "measure"), sep = "-") |> + tidyr::spread(measure, value) + timing$q[timing$index %in% c("I16")] <- 1 + timing$q[timing$index %in% c("I8", "I24")] <- 2 + timing$q[timing$index %in% c("I4", "I12", "I20", "I28")] <- 3 + timing$q[timing$index %in% c("I2", "I6", "I10", "I14", "I18", "I22", "I26", "I30")] <- 4 + timing$q[timing$index %in% c("I1", "I3", "I5", "I7", "I9", "I11", "I13", "I15", "I17", "I19", + "I21", "I23", "I25", "I27", "I29", "I31")] <- 5 + timing$q[timing$index %in% c("AttendSS", "AttendLL")] <- 6 + timing[4:7] <- sapply(timing[4:7], as.numeric) + return(dplyr::arrange(timing, ResponseId, q)) + +} + +#' Converts answers from 5.5 trial probability discounting from Qualtrics template +#' +#' @param df A dataframe containing all the columns +#' +#' @return A dataframe with the ResponseId, index, and response (sc or lu). +#' @importFrom stats complete.cases +#' @export +#' +#' @examples +#' ans_pd(five.fivetrial_pd) +ans_pd <- function(df) { + ans <- df |> + dplyr::select(ResponseId, paste0("I", 1:31), dplyr::starts_with("Attend")) |> + dplyr::select(-dplyr::contains("Timing"), -dplyr::contains("_DO")) %>% + tidyr::pivot_longer(cols = 2:ncol(.), names_to = "index", values_to = "response") %>% + dplyr::filter(complete.cases(.)) |> + dplyr::mutate(response = ifelse(stringr::str_detect(response, "for sure"), "sc", "lu")) + ans$index <- gsub("-", "", ans$index) + return(ans) +} + +#' Calculate scores, answers, and timing for 5.5 trial probability discounting from Qualtrics template +#' +#' @param df A dataframe containing all the columns from the template. +#' +#' @return A dataframe with h/ep50 values, answers, timing +#' @export +#' +#' @examples +#' calc_pd(five.fivetrial_pd) +calc_pd <- function(df) { + return(dplyr::left_join(timing_pd(df), ans_pd(df), by = c("ResponseId", "index")) |> + dplyr::left_join(dplyr::select(score_pd(df), ResponseId, attentionflag, hval, ep50), + by = c("ResponseId")) |> + dplyr::arrange(ResponseId, q)) +} diff --git a/README.md b/README.md index 8a64c7d..66b2ce6 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ available as a .qsf file in this package. ## Note About Use -Currently, this version (0.1.1) appears stable. I encourage you to use +Currently, this version (0.3.0) appears stable. I encourage you to use it but be aware that, as with any software release, there might be (unknown) bugs present. I’ve tried hard to make this version usable while including the core functionality (described more below). However, @@ -33,7 +33,7 @@ my [GitHub page](https://github.com/brentkaplan/beezdiscounting) or ### CRAN Release (recommended method) -The latest stable version of `beezdiscounting` (currently v.0.1.1) can +The latest stable version of `beezdiscounting` (currently v.0.3.0) can be found on [CRAN](https://CRAN.R-project.org/package=beezdiscounting) and installed using the following command. The first time you install the package, you may be asked to select a CRAN mirror. Simply select the @@ -624,6 +624,77 @@ The original data and the new responses imputed (access via `...$data`): Original Data and Imputed Data +## Scoring the Minute Discounting Tasks + +### 5.5 Trial Delay Discounting Task + +``` r +dd_out <- calc_dd(five.fivetrial_dd) + +knitr::kable(dd_out, caption = "Scoring Summary of the 5.5 Trial Delay Discounting Task") +``` + +| ResponseId | index | q | firstclick | lastclick | pagesubmit | totalclicks | response | attentionflag | kval | ed50 | +|-----------:|:---------|----:|-----------:|----------:|-----------:|------------:|:---------|:--------------|----------:|------------:| +| 1 | I16 | 1 | 1.761 | 1.761 | 3.337 | 1 | ll | No | 0.0067058 | 149.1249275 | +| 1 | I24 | 2 | 7.729 | 7.729 | 8.457 | 1 | ss | No | 0.0067058 | 149.1249275 | +| 1 | I20 | 3 | 1.558 | 1.558 | 3.377 | 1 | ll | No | 0.0067058 | 149.1249275 | +| 1 | I22 | 4 | 2.333 | 3.949 | 4.501 | 2 | ss | No | 0.0067058 | 149.1249275 | +| 1 | I21 | 5 | 3.161 | 3.161 | 3.728 | 1 | ss | No | 0.0067058 | 149.1249275 | +| 2 | I16 | 1 | 3.779 | 3.779 | 4.351 | 1 | ss | No | 4.8989795 | 0.2041241 | +| 2 | I8 | 2 | 1.454 | 1.454 | 3.190 | 1 | ss | No | 4.8989795 | 0.2041241 | +| 2 | I4 | 3 | 1.179 | 1.179 | 3.144 | 1 | ll | No | 4.8989795 | 0.2041241 | +| 2 | I6 | 4 | 0.873 | 0.873 | 3.256 | 1 | ss | No | 4.8989795 | 0.2041241 | +| 2 | I5 | 5 | 2.621 | 2.621 | 3.258 | 1 | ss | No | 4.8989795 | 0.2041241 | +| 3 | I16 | 1 | 1.115 | 1.115 | 3.272 | 1 | ss | Yes | NA | NA | +| 3 | I8 | 2 | 0.679 | 0.679 | 3.074 | 1 | ss | Yes | NA | NA | +| 3 | I4 | 3 | 0.606 | 0.606 | 3.044 | 1 | ss | Yes | NA | NA | +| 3 | I2 | 4 | 0.745 | 0.745 | 3.302 | 1 | ss | Yes | NA | NA | +| 3 | I1 | 5 | 0.924 | 0.924 | 4.181 | 1 | ss | Yes | NA | NA | +| 3 | AttendSS | 6 | 1.450 | 1.450 | 4.181 | 1 | ss | Yes | NA | NA | +| 4 | I16 | 1 | 1.011 | 1.011 | 3.190 | 1 | ll | Yes | NA | NA | +| 4 | I24 | 2 | 1.041 | 1.041 | 3.109 | 1 | ll | Yes | NA | NA | +| 4 | I28 | 3 | 0.806 | 0.806 | 3.113 | 1 | ll | Yes | NA | NA | +| 4 | I30 | 4 | 0.822 | 0.822 | 3.487 | 1 | ll | Yes | NA | NA | +| 4 | I31 | 5 | 0.914 | 0.914 | 3.170 | 1 | ll | Yes | NA | NA | +| 4 | AttendLL | 6 | 2.158 | 2.158 | 3.573 | 1 | ll | Yes | NA | NA | + +Scoring Summary of the 5.5 Trial Delay Discounting Task + +### 5.5 Trial Probability Discounting Task + +``` r +pd_out <- calc_pd(five.fivetrial_pd) + +knitr::kable(pd_out, caption = "Scoring Summary of the 5.5 Trial Probability Discounting Task") +``` + +| ResponseId | index | q | firstclick | lastclick | pagesubmit | totalclicks | response | attentionflag | hval | ep50 | +|-----------:|:---------|----:|-----------:|----------:|-----------:|------------:|:---------|:--------------|----------:|----------:| +| 1 | I16 | 1 | 3.980 | 3.980 | 5.184 | 1 | sc | No | 7.435436 | 0.1344911 | +| 1 | I8 | 2 | 4.010 | 4.010 | 4.763 | 1 | lu | No | 7.435436 | 0.1344911 | +| 1 | I12 | 3 | 2.061 | 2.061 | 3.252 | 1 | sc | No | 7.435436 | 0.1344911 | +| 1 | I10 | 4 | 1.525 | 1.525 | 3.019 | 1 | sc | No | 7.435436 | 0.1344911 | +| 1 | I9 | 5 | 2.253 | 2.954 | 3.738 | 2 | lu | No | 7.435436 | 0.1344911 | +| 2 | I16 | 1 | 2.873 | 2.873 | 3.883 | 1 | sc | No | 99.000000 | 0.0101010 | +| 2 | I8 | 2 | 3.745 | 3.745 | 4.864 | 1 | sc | No | 99.000000 | 0.0101010 | +| 2 | I4 | 3 | 1.159 | 1.159 | 6.356 | 1 | sc | No | 99.000000 | 0.0101010 | +| 2 | I2 | 4 | 3.064 | 3.064 | 5.408 | 1 | sc | No | 99.000000 | 0.0101010 | +| 2 | I1 | 5 | 2.049 | 2.049 | 5.097 | 1 | sc | No | 99.000000 | 0.0101010 | +| 2 | AttendSS | 6 | 2.295 | 2.295 | 4.641 | 1 | lu | No | 99.000000 | 0.0101010 | +| 3 | I16 | 1 | 8.933 | 8.933 | 9.769 | 1 | sc | No | 1.601445 | 0.6244361 | +| 3 | I8 | 2 | 2.163 | 2.163 | 2.981 | 1 | lu | No | 1.601445 | 0.6244361 | +| 3 | I12 | 3 | 3.129 | 3.129 | 3.895 | 1 | lu | No | 1.601445 | 0.6244361 | +| 3 | I14 | 4 | 2.655 | 2.655 | 4.855 | 1 | lu | No | 1.601445 | 0.6244361 | +| 3 | I15 | 5 | 4.021 | 4.021 | 4.705 | 1 | sc | No | 1.601445 | 0.6244361 | +| 4 | I16 | 1 | 4.415 | 4.415 | 5.382 | 1 | sc | No | 7.435436 | 0.1344911 | +| 4 | I8 | 2 | 6.123 | 6.123 | 6.974 | 1 | lu | No | 7.435436 | 0.1344911 | +| 4 | I12 | 3 | 1.673 | 1.673 | 3.191 | 1 | sc | No | 7.435436 | 0.1344911 | +| 4 | I10 | 4 | 1.757 | 1.757 | 3.259 | 1 | sc | No | 7.435436 | 0.1344911 | +| 4 | I9 | 5 | 1.207 | 1.207 | 4.592 | 1 | lu | No | 7.435436 | 0.1344911 | + +Scoring Summary of the 5.5 Trial Probability Discounting Task + ## Learn More About Functions To learn more about a function and what arguments it takes, type “?” in @@ -661,3 +732,12 @@ front of the function name. discounting task: accurate discount rates in less than one minute. *Experimental and Clinical Psychopharmacology, 22*(3), 222-228. + +- Koffarnus, M. N., Rzeszutek, M. J., & Kaplan, B. A. (2021). Additional + discounting rates in less than one minute: Task variants for + probability and a wider range of delays. + + +- Koffarnus, M. N., Kaplan, B. A., & Stein, J. S. (2017). User guide for + Qualtrics minute discounting template. + diff --git a/data/five.fivetrial.rda b/data/five.fivetrial.rda deleted file mode 100644 index 4e8119efa8501811c4f8d27fa2da6df7537fde03..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1377 zcmV-n1)lmsT4*^jL0KkKS>Gno9{>?%f6)JTZwy3p|L{LQ{&2tl-|9dB004jm;0AvC zO6#K8UdgU000004FG5X>IF$536n~A(qe5R6w}CM9;Sc>Pg6r6 zXda`|VU(Q|Rxp@Ggb*oPM56^!B$hE0m|`+S;G~>2AuUnK$#?g6QtMYAhaA)*qWS`f zmqvNZvmgzXDTyHphGJ_i2}Z;Ute^ol!rc;1gqcwd68mh}w5^b;gwUZ%l}SoUDN0nN zr7Eh7@@J~P;YC6fRp@TtCN^s~**LFv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_` z-~$i-PUvK#MSZ=HcPr-2QXz{n*PG3H5D3f&%7lt$&dKV2w?41%D3fEMSiF32Thp^y z$_4&u?wz>z@vOmu9_L5)h*8>E&2rZ@GIEp64dt}J4Iz+NT?sNf?OTSUYB)QM<+-6< zJ+)3JvjTFcR`gtxW7eUrt7~G;(niot+_g+{%mcD4RiHS4sHJ-tq9A4gKy97cm#-=# z1;|yt_?q)q8LND8q=VzDrQ4SL?V`i2!9%Akh7$I&TSp>1`2f5}U)z>fO(lIHfZ}XP zJ@8{yK|)6w0I-Tq{OaZS`vYJrxC+36E@`!nEV!0a&H!o+3Bqg-0Q5*f0POeEtsm*0 zxE}xUL{*69J|r^0L`)aCAuq`Ny@Ikb0>VHc70pMLXL&Q?cfaoWeZj>#-&fR_2t zq!VhZzsAKQ=)M{KXF^85*R8P1T8g|>Iyu+DuSq(2`mAqFeVmjDvAGwE_*i|T;i)fu z>}le{$8^IMxy zI2E>hAI|RXwmPV<`AAeC+4bjgUU1hHgqUFpt`o@*->#f)=a6@_FO3*1_7wk25W(mpC-j zt?Pz!Xj_Ql{Os7AvS%kpF1Lr(4ZX-8xMJM&c#FD5b?1w2`Sb@D4rg6hTZtdD#w@c8npd8xNWH)OgWCK?oIJqWxC@=&IOY#!%5PI^YUZ~szhEw qJa=~bNNZJ&GnG7PJK3`762E6=kWadDMn`d>30aKtK)o=6gTDb?PKs6l literal 0 HcmV?d00001 diff --git a/man/ans_dd.Rd b/man/ans_dd.Rd index c8cb994..9ebfb2a 100644 --- a/man/ans_dd.Rd +++ b/man/ans_dd.Rd @@ -16,5 +16,5 @@ A dataframe with the ResponseId, index, and response (ss or ll). Converts answers from 5.5 trial delay discounting from Qualtrics template } \examples{ -ans_dd(five.fivetrial) +ans_dd(five.fivetrial_dd) } diff --git a/man/ans_pd.Rd b/man/ans_pd.Rd new file mode 100644 index 0000000..7e02688 --- /dev/null +++ b/man/ans_pd.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fivetrial.R +\name{ans_pd} +\alias{ans_pd} +\title{Converts answers from 5.5 trial probability discounting from Qualtrics template} +\usage{ +ans_pd(df) +} +\arguments{ +\item{df}{A dataframe containing all the columns} +} +\value{ +A dataframe with the ResponseId, index, and response (sc or lu). +} +\description{ +Converts answers from 5.5 trial probability discounting from Qualtrics template +} +\examples{ +ans_pd(five.fivetrial_pd) +} diff --git a/man/calc_dd.Rd b/man/calc_dd.Rd index 2db3735..287da67 100644 --- a/man/calc_dd.Rd +++ b/man/calc_dd.Rd @@ -16,5 +16,5 @@ A dataframe with k/ed50 values, answers, timing Calculate scores, answers, and timing for 5.5 trial delay discounting from Qualtrics template } \examples{ -calc_dd(five.fivetrial) +calc_dd(five.fivetrial_dd) } diff --git a/man/calc_pd.Rd b/man/calc_pd.Rd new file mode 100644 index 0000000..bdd269b --- /dev/null +++ b/man/calc_pd.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fivetrial.R +\name{calc_pd} +\alias{calc_pd} +\title{Calculate scores, answers, and timing for 5.5 trial probability discounting from Qualtrics template} +\usage{ +calc_pd(df) +} +\arguments{ +\item{df}{A dataframe containing all the columns from the template.} +} +\value{ +A dataframe with h/ep50 values, answers, timing +} +\description{ +Calculate scores, answers, and timing for 5.5 trial probability discounting from Qualtrics template +} +\examples{ +calc_pd(five.fivetrial_pd) +} diff --git a/man/five.fivetrial.Rd b/man/five.fivetrial_dd.Rd similarity index 59% rename from man/five.fivetrial.Rd rename to man/five.fivetrial_dd.Rd index f495cdc..f1eb34f 100644 --- a/man/five.fivetrial.Rd +++ b/man/five.fivetrial_dd.Rd @@ -1,14 +1,14 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/five.fivetrial.R +% Please edit documentation in R/five.fivetrial_dd.R \docType{data} -\name{five.fivetrial} -\alias{five.fivetrial} -\title{Example Qualtrics output from the 5.5 trial discounting template.} +\name{five.fivetrial_dd} +\alias{five.fivetrial_dd} +\title{Example Qualtrics output from the 5.5 trial delay discounting template.} \format{ Example Qualtrics output } \usage{ -five.fivetrial +five.fivetrial_dd } \description{ An example dataset containing four participants' data (two typical discounting diff --git a/man/five.fivetrial_pd.Rd b/man/five.fivetrial_pd.Rd new file mode 100644 index 0000000..c7ff431 --- /dev/null +++ b/man/five.fivetrial_pd.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/five.fivetrial_pd.R +\docType{data} +\name{five.fivetrial_pd} +\alias{five.fivetrial_pd} +\title{Example Qualtrics output from the 5.5 trial probability discounting template.} +\format{ +Example Qualtrics output +} +\usage{ +five.fivetrial_pd +} +\description{ +An example dataset containing four participants' data. +} +\keyword{datasets} diff --git a/man/score_dd.Rd b/man/score_dd.Rd index 74a0f5c..a9f4ab2 100644 --- a/man/score_dd.Rd +++ b/man/score_dd.Rd @@ -16,5 +16,5 @@ A dataframe with id, indexes, response, k value, and effective delay 50. Score 5.5 trial delay discounting from Qualtrics template } \examples{ -score_dd(five.fivetrial) +score_dd(five.fivetrial_dd) } diff --git a/man/score_pd.Rd b/man/score_pd.Rd new file mode 100644 index 0000000..bc1e9e4 --- /dev/null +++ b/man/score_pd.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fivetrial.R +\name{score_pd} +\alias{score_pd} +\title{Score 5.5 trial probability discounting from Qualtrics template} +\usage{ +score_pd(df) +} +\arguments{ +\item{df}{A dataframe containing all the columns} +} +\value{ +A dataframe with id, indexes, response, h value, and effective probability 50. +} +\description{ +Score 5.5 trial probability discounting from Qualtrics template +} +\examples{ +score_pd(five.fivetrial_pd) +} diff --git a/man/timing_dd.Rd b/man/timing_dd.Rd index f099d66..978013c 100644 --- a/man/timing_dd.Rd +++ b/man/timing_dd.Rd @@ -16,5 +16,5 @@ A dataframe with ResponseId, indexes, values and timing Extract timing metrics from 5.5 trial delay discounting from Qualtrics template } \examples{ -timing_dd(five.fivetrial) +timing_dd(five.fivetrial_dd) } diff --git a/man/timing_pd.Rd b/man/timing_pd.Rd new file mode 100644 index 0000000..16e393c --- /dev/null +++ b/man/timing_pd.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fivetrial.R +\name{timing_pd} +\alias{timing_pd} +\title{Extract timing metrics from 5.5 trial probability discounting from Qualtrics template} +\usage{ +timing_pd(df) +} +\arguments{ +\item{df}{A dataframe containing all the columns} +} +\value{ +A dataframe with ResponseId, indexes, values and timing +} +\description{ +Extract timing metrics from 5.5 trial probability discounting from Qualtrics template +} +\examples{ +timing_pd(five.fivetrial_pd) +}