test_directional_effect: Tests for a Directional Effect

View source: R/directional_tests.R

test_directional_effectR Documentation

Tests for a Directional Effect

Description

The function tests for a group-level directional of a difference score (comparing two conditions, under the independent variable, iv) according to the summary function (summary_function)for a random split of the data, using bootstrapping and permuting each participants' independent variable labels. The function accepts a dataset in long format with specific columns: identifier ('idv'), independent and dependent variables (iv and dv, respectively). For each participant, the function calculates the difference score between two conditions. The difference score is calculated by subtracting the result of applying the summary function (summary_function) to the 2nd level if the independent variable, iv, from the 1st level. Then, the average effect across participants is tested against a bootstrapped null distribution in which effects are calculated for each participant with a random sign (see Stelzer, J., Chen, Y., & Turner, R., 2013). All levels of the independent variable must be included under each identifier.

Usage

test_directional_effect(
  data,
  idv = "id",
  dv = "rt",
  iv = "condition",
  summary_function = base::mean,
  null_dist_samples = 10000,
  ci_level = 95,
  ci_reps = 0
)

Arguments

data

The dataset to analyze.

idv

The name of the participant identifier column.

dv

The dependent variable to apply the summary function (summary_function) to. For multiple dependent variables use a string list with the names of each dependent variable (e.g., c('dv1','dv2')),

iv

Labels of an independent variable, indicating the different levels under which the dependent variable ('dv') is expected to differ.

summary_function

The summary function to apply to the dependent variables ('dv') under each level of the independent variable ('iv') for each participant ('idv'). This function should map a matrix maintaining the original dataframe columns to a number: matrix -> numeric (e.g. function(mat) mean(mat), which is the default summary function).

null_dist_samples

The number of samples taken from the null distribution.

ci_level

- The confidence level (in percents, e.g. setting the argument to 50 generates a 50 to use when computing the bootstrapped confidence interval on the group-level statistic (see the return value 'ci', and the argument 'ci_reps'). The default value of this argument is 95, that would lead to computing the 95 the group-level statistic.

ci_reps

- The number repetitions to use when computing the bootstrapped confidence interval around the group-level statistic. The default value of this argument is zero, which would lead to not computing the confidence interval at all.

Value

A list including the results of the function

  • p - The two-sided p_value of the estimated effect compared with the distribution of effects under the bootstrapped null distribution. the p-value is adjusted according to (B + 1) / (M + 1), see Phipson & Smyth, 2010.

  • statistic - The group-level statistic describing the average effect across participants.

  • null_dist - A numerical vector of samples of effects under the null hypothesis (where the effect of each participant is assigned a random sign).

  • effect_per_id - An effect score for each participant.

  • ci_low (optional) - The lower bound of a confidence interval around the statistic (returned only if the 'ci_reps' argument was set to a value different than 0).

  • ci_high (optional) - The higher bound of a confidence interval around the statistic (returned only if the 'ci_reps' argument was set to a value different than 0).

See Also

[signcon::get_directional effect()] returns the directional effect of each participant.


mufcItay/weaknull documentation built on Jan. 29, 2025, 7:28 p.m.