Skip to content

Commit

Permalink
Merge branch 'release/2.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
psychelzh committed Dec 7, 2021
2 parents 521ca0c + 7cac718 commit 6f5fa43
Show file tree
Hide file tree
Showing 57 changed files with 354 additions and 238 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: preproc.iquizoo
Title: Utility Functions for Data Processing of Iquizoo Games
Version: 2.0.1
Version: 2.1.0
Authors@R:
person("Liang", "Zhang", , "psychelzh@outlook.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-9041-1150"))
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# preproc.iquizoo 2.1.0

## Breaking Changes

* Now `options()` support is removed, but accept two additional arguments `.input` and `.extra`.

# preproc.iquizoo 2.0.1

## Internal
Expand Down
19 changes: 8 additions & 11 deletions R/bart.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,23 @@
#' This task is deemed as a measure of impulsivity. Read more details on
#' [this website](http://www.impulsivity.org/measurement/BART).
#'
#' @templateVar .by TRUE
#' @template params-template
#' @template common
#' @template options
#' @return A [tibble][tibble::tibble-package] contains following values:
#' \item{mean_pumps}{Mean of hits for balloons not exploded.}
#' \item{mean_pumps_raw}{Mean of hits for all balloons.}
#' \item{num_explosion}{Number of exploded balloons.}
#' @export
bart <- function(data, .by = NULL) {
bart <- function(data, .by = NULL, .input = NULL, .extra = NULL) {
.input <- list(name_feedback = "feedback", name_nhit = "nhit") |>
update_settings("preproc.input")
update_settings(.input)
data |>
mutate(
nhit_cor = ifelse(
.data[[.input[["name_feedback"]]]] == 1,
.data[[.input[["name_nhit"]]]], NA
)
) |>
group_by(across(all_of(.by))) |>
summarise(
mean_pumps = mean(.data[["nhit_cor"]], na.rm = TRUE),
mean_pumps = .data[[.input[["name_nhit"]]]] |>
# keep not exploded trials only
.subset(.data[[.input[["name_feedback"]]]] == 1) |>
mean(),
mean_pumps_raw = mean(.data[[.input[["name_nhit"]]]]),
num_explosion = sum(.data[[.input[["name_feedback"]]]] == 0),
.groups = "drop"
Expand Down
10 changes: 5 additions & 5 deletions R/bps.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
#' This function mainly calculates the "*BPS score*" developed .by Stark et. al.
#' (2013).
#'
#' @templateVar .by TRUE
#' @template params-template
#' @template common
#' @template options
#' @return A [tibble][tibble::tibble-package] contains following values:
#' \item{pc}{Percent of correct responses.}
#' \item{p_sim_foil}{Percent of similar responses for "foil" stimuli.}
#' \item{p_sim_lure}{Percent of similar responses for "lure" stimuli.}
#' \item{p_sim_target}{Percent of similar responses for "target" stimuli.}
#' \item{bps_score}{BPS score.}
#' @export
bps <- function(data, .by = NULL) {
bps <- function(data, .by = NULL, .input = NULL, .extra = NULL) {
.input <- list(
name_phase = "phase",
name_acc = "acc",
name_type = "type",
name_resp = "resp"
) |>
update_settings("preproc.input")
update_settings(.input)
.extra <- list(
phase_test = "test",
resp_sim = "similar"
) |>
update_settings("preproc.extra")
update_settings(.extra)
data_cor <- data |>
filter(.data[[.input[["name_phase"]]]] == .extra$phase_test)
pc_all <- data_cor |>
Expand Down
20 changes: 10 additions & 10 deletions R/counts.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#' responses, [sumscore()] adds up the score for each response.
#'
#' @name counts
#' @templateVar .by TRUE
#' @template params-template
#' @template common
#' @template options
#' @return A [tibble][tibble::tibble-package] contains following values:
#' \item{nc}{Count of correct responses. For [countcorrect()].}
#' \item{nc_cor}{Corrected count of correct responses (subtracting number of
Expand All @@ -20,9 +20,9 @@ NULL

#' @rdname counts
#' @export
countcorrect <- function(data, .by = NULL) {
countcorrect <- function(data, .by = NULL, .input = NULL, .extra = NULL) {
.input <- list(name_acc = "acc") |>
update_settings("preproc.input")
update_settings(.input)
if (is.character(data[[.input[["name_acc"]]]])) {
# character input uses "-" to separate individual responses
data <- data |>
Expand All @@ -44,9 +44,9 @@ countcorrect <- function(data, .by = NULL) {

#' @rdname counts
#' @export
countcorrect2 <- function(data, .by = NULL) {
countcorrect2 <- function(data, .by = NULL, .input = NULL, .extra = NULL) {
.input <- list(name_nc = "ncorrect", name_ne = "nerror") |>
update_settings("preproc.input")
update_settings(.input)
data |>
group_by(across(all_of(.by))) |>
summarise(
Expand All @@ -59,9 +59,9 @@ countcorrect2 <- function(data, .by = NULL) {

#' @rdname counts
#' @export
sumweighted <- function(data, .by = NULL) {
sumweighted <- function(data, .by = NULL, .input = NULL, .extra = NULL) {
.input <- list(name_weight = "nstim", name_acc = "acc") |>
update_settings("preproc.input")
update_settings(.input)
data |>
group_by(across(all_of(.by))) |>
summarise(
Expand All @@ -75,9 +75,9 @@ sumweighted <- function(data, .by = NULL) {

#' @rdname counts
#' @export
sumscore <- function(data, .by = NULL) {
sumscore <- function(data, .by = NULL, .input = NULL, .extra = NULL) {
.input <- list(name_score = "score") |>
update_settings("preproc.input")
update_settings(.input)
data |>
group_by(across(all_of(.by))) |>
summarise(
Expand Down
10 changes: 5 additions & 5 deletions R/cpt.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#' are many methods used to calculate the performance index of this task, and
#' here only includes those common ones.
#'
#' @templateVar .by TRUE
#' @template params-template
#' @template common
#' @template options
#' @return A [tibble][tibble::tibble-package] contains following values:
#' \item{nc}{Count of correct responses.}
#' \item{mrt}{Mean reaction time of hits.}
Expand All @@ -15,11 +15,11 @@
#' \item{commissions}{Number of errors caused by action.}
#' \item{omissions}{Number of errors caused by inaction.}
#' @export
cpt <- function(data, .by = NULL) {
cpt <- function(data, .by = NULL, .input = NULL, .extra = NULL) {
.input <- list(name_acc = "acc", name_type = "type", name_rt = "rt") |>
update_settings("preproc.input")
update_settings(.input)
.extra <- list(type_signal = "target") |>
update_settings("preproc.extra")
update_settings(.extra)
data_cor <- data |>
# some tests records stimuli not presented
filter(.data[[.input[["name_acc"]]]] != -1) |>
Expand Down
10 changes: 5 additions & 5 deletions R/driving.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
#'
#' A test measuring impulsivity originally developed .by Gardner et. al. (2005).
#'
#' @templateVar .by TRUE
#' @template params-template
#' @template common
#' @template options
#' @return A [tibble][tibble::tibble-package] contains following values:
#' \item{still_ratio}{The ratio of still duration in yellow light state.}
#' @export
driving <- function(data, .by = NULL) {
driving <- function(data, .by = NULL, .input = NULL, .extra = NULL) {
.input <- list(
name_still_dur = "stilldur",
name_still_light = "stilllight",
name_yellow_dur = "yellowdur"
) |>
update_settings("preproc.input")
update_settings(.input)
.extra <- list(light_yellow = "yellow") |>
update_settings("preproc.extra")
update_settings(.extra)
data |>
group_by(across(all_of(.by))) |>
mutate(
Expand Down
10 changes: 5 additions & 5 deletions R/drm.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@
#' This is a classical false memory test. Here calculates the effect size of
#' false memory.
#'
#' @templateVar .by TRUE
#' @template params-template
#' @template common
#' @template options
#' @return A [tibble][tibble::tibble-package] contains following values:
#' \item{tm_dprime}{Sensitivity (d') of true memory (against "foil" stimuli).}
#' \item{tm_bias}{Bias of true memory (against "foil" stimuli).}
#' \item{fm_dprime}{Sensitivity (d') of false memory.}
#' \item{fm_bias}{ias of false memory.}
#' @export
drm <- function(data, .by = NULL) {
drm <- function(data, .by = NULL, .input = NULL, .extra = NULL) {
.input <- list(
name_type = "type",
name_resp = "resp",
name_acc = "acc",
name_rt = "rt"
) |>
update_settings("preproc.input")
update_settings(.input)
.extra <- list(
type_filler = "filler",
type_old = "old",
type_foil = "foil",
type_lure = "lure",
resp_old = "old"
) |>
update_settings("preproc.extra")
update_settings(.extra)
data |>
filter(.data[[.input[["name_type"]]]] != .extra$type_filler) |>
group_by(across(all_of(c(.by, .input[["name_type"]])))) |>
Expand Down
10 changes: 5 additions & 5 deletions R/igt.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
#' [wikipedia](https://en.wikipedia.org/wiki/Iowa_gambling_task). This modified
#' version uses pools to simulate cards, but the essential ideas are the same.
#'
#' @templateVar .by TRUE
#' @template params-template
#' @template common
#' @template options
#' @return A [tibble][tibble::tibble-package] contains following values:
#' \item{sum_outcome}{The total outcome over all trials.}
#' \item{perc_good}{The number of choices on "good" pools.}
#' @export
igt <- function(data, .by = NULL) {
igt <- function(data, .by = NULL, .input = NULL, .extra = NULL) {
.input <- list(name_outcome = "outcome", name_pool = "poolid") |>
update_settings("preproc.input")
update_settings(.input)
.extra <- list(pools_advantage = c("a", "b")) |>
update_settings("preproc.extra")
update_settings(.extra)
data |>
group_by(across(all_of(.by))) |>
summarise(
Expand Down
10 changes: 5 additions & 5 deletions R/jlo.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
#' This test is about visuo-spatial skills. For more details, read [this
#' introduction](https://en.wikipedia.org/wiki/Judgment_of_Line_Orientation).
#'
#' @templateVar .by TRUE
#' @template params-template
#' @template common
#' @template options
#' @return A [tibble][tibble::tibble-package] contains following values:
#' \item{nc}{Count of correct responses.}
#' \item{mean_ang_err}{Mean of the response angle errors.}
#' \item{mean_log_err}{Mean of the log-transformed (of base 2) response angle
#' errors.}
#' @export
jlo <- function(data, .by = NULL) {
jlo <- function(data, .by = NULL, .input = NULL, .extra = NULL) {
.input <- list(name_resp = "resp", name_angle = "angle", name_acc = "acc") |>
update_settings("preproc.input")
update_settings(.input)
.extra <- list(resp_anticlock = "left", resp_clockwise = "right") |>
update_settings("preproc.extra")
update_settings(.extra)
data |>
mutate(
resp_angle = stringr::str_split(
Expand Down
12 changes: 6 additions & 6 deletions R/locmem.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#' deal with the distance condition only. [locmem2()] deals with a special case
#' when the response order and distance both matter.
#'
#' @templateVar .by TRUE
#' @template params-template
#' @template common
#' @template options
#' @return A [tibble][tibble::tibble-package] contains following values:
#' \item{nc_loc}{Count of correct responses for location.}
#' \item{mean_dist_err}{Mean of the response distance errors.}
Expand All @@ -15,9 +15,9 @@
#' \item{nc_order}{Count of correct responses for order. For [locmem2()]
#' only.}
#' @export
locmem <- function(data, .by = NULL) {
locmem <- function(data, .by = NULL, .input = NULL, .extra = NULL) {
.input <- list(name_dist = "resplocdist") |>
update_settings("preproc.input")
update_settings(.input)
data |>
mutate(
dist = parse_char_resp(.data[[.input[["name_dist"]]]]),
Expand All @@ -35,9 +35,9 @@ locmem <- function(data, .by = NULL) {

#' @rdname locmem
#' @export
locmem2 <- function(data, .by = NULL) {
locmem2 <- function(data, .by = NULL, .input = NULL, .extra = NULL) {
.input <- list(name_acc_order = "respaccorder") |>
update_settings("preproc.input")
update_settings(.input)
loc_results <- locmem(data, .by)
nc_order <- data |>
mutate(
Expand Down
8 changes: 4 additions & 4 deletions R/london.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
#'
#' A classical test on problem solving.
#'
#' @templateVar .by TRUE
#' @template params-template
#' @template common
#' @template options
#' @return A [tibble][tibble::tibble-package] contains following values:
#' \item{total_score}{Total score defined .by the game itself.}
#' \item{mean_level}{Mean level reached.}
#' \item{level_score}{Sum of mean score (a ratio) for each level.}
#' @export
london <- function(data, .by = NULL) {
london <- function(data, .by = NULL, .input = NULL, .extra = NULL) {
.input <- list(
name_level = "level",
name_score = "score",
name_outcome = "outcome",
name_steps = "stepsused"
) |>
update_settings("preproc.input")
update_settings(.input)
total_score <- data |>
group_by(across(all_of(.by))) |>
summarise(
Expand Down
28 changes: 10 additions & 18 deletions R/multisense.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,35 @@
#' There will typically be some speed advantage if there are more than one
#' sensory inputs to be employed. This function calculates this advantage.
#'
#' @templateVar .by TRUE
#' @template params-template
#' @template common
#' @template options
#' @return A [tibble][tibble::tibble-package] contains following values:
#' \item{mrt_image}{Mean reaction time of Image stimuli.}
#' \item{mrt_sound}{Mean reaction time of Sound stimuli.}
#' \item{mrt_mixed}{Mean reaction time of Mixed stimuli.}
#' \item{mrt_mixadv}{Mean reaction decrease of Mixed stimuli compared to other
#' two types of stimuli.}
#' @export
multisense <- function(data, .by = NULL) {
multisense <- function(data, .by = NULL, .input = NULL, .extra = NULL) {
.input <- list(name_type = "type", name_rt = "rt") |>
update_settings("preproc.input")
update_settings(.input)
.extra <- list(
type_image = "image",
type_sound = "sound",
type_mixed = "mixed"
) |>
update_settings("preproc.extra")
update_settings(.extra)
data |>
group_by(across(
all_of(c(.by, .input[["name_type"]]))
)) |>
mutate(
rt_cor = ifelse(
.data[[.input[["name_rt"]]]] > 100,
.data[[.input[["name_rt"]]]], NA
)
) |>
mutate(
rt_cor = ifelse(
.data[["rt_cor"]] %in%
graphics::boxplot(.data[["rt_cor"]], plot = FALSE)$out,
NA, .data[["rt_cor"]]
)
filter(.data[[.input[["name_rt"]]]] > 100) |>
filter(
!.data[[.input[["name_rt"]]]] %in%
graphics::boxplot(.data[[.input[["name_rt"]]]], plot = FALSE)$out
) |>
summarise(
mrt = mean(.data[["rt_cor"]], na.rm = TRUE),
mrt = mean(.data[[.input[["name_rt"]]]]),
.groups = "drop"
) |>
pivot_wider(
Expand Down
Loading

0 comments on commit 6f5fa43

Please sign in to comment.