Package 'condir'

Title: Computation of P Values and Bayes Factors for Conditioning Data
Description: Set of functions for the easy analyses of conditioning data.
Authors: Angelos-Miltiadis Krypotos [aut, cre]
Maintainer: Angelos-Miltiadis Krypotos <[email protected]>
License: GPL-3
Version: 0.1.4
Built: 2025-02-13 04:14:06 UTC
Source: https://github.com/angelospsy/condir

Help Index


Statistically compare CRs towards two CSs

Description

Compare CRs towards two CSs within a frequentist and a Bayesian framework.

Usage

csCompare(
  cs1,
  cs2,
  group = NULL,
  data = NULL,
  alternative = "two.sided",
  conf.level = 0.95,
  mu = 0,
  rscale = 0.707,
  descriptives = TRUE,
  out.thres = 3,
  boxplot = TRUE
)

Arguments

cs1

a numeric vector of values. If the data argument is defined, it can refer to either the column index or the column name of the data object. See Details for more information.

cs2

a numeric vector of values. If the data argument is defined, it can refer to either the column index or the column name of the data object. See Details for more information.

group

column index or name that contain the group data. See Details for more information.

data

numeric matrix or data frame that contains the relevant data.

alternative

a character string for the specification of the alternative hypothesis. Possible values: "two.sided" (default), "greater" or "less".

conf.level

Interval's confidence level.

mu

a numeric value for the mean value or mean difference.

rscale

the scale factor for the prior used in the Bayesian t.test.

descriptives

Returns basic descriptive statistics for cs1 and cs2.

out.thres

The threshold for detecting outliers (default is 3). If set to 0, no outliers analysis will be performed. See Details below for more information.

boxplot

Should a boxplot of the variables be produced (default is TRUE)?

Details

csCompare performs both a student t-test (using the stats::t.test function) and a Bayesian t-test (using the BayesFactor::ttest.tstat). If cs1 and/or cs2 are or refer to multiple columns of a matrix or a data.frame, then the row means are computed before the t-tests are performed. In case group is NULL, paired-samples t-tests will be run. In case the group is different than NULL, then the csCompare first computes difference scores between the cs1 and the cs2 (i.e., cs1 - cs2). In case the group argument is defined but, after removal of NA's (stats::na.omit), only one group is present, a paired samples t-test is run. In case of independent samples t-test, the function runs a Welch's t-test.

Regarding outliers, those are detected based on the deviations from the standardized residuals of each test. For example, in case of a paired-samples t-test, the csCompare function will run an additional regression for detecting deviations (defined in the out.thres argument) from the standardized residuals. The detected outliers are removed from both the frequentists and Bayesian analyses.

Value

The function returns (at least) 3 list objects. These are: descriptives, freq.results, and bayes.results. In case outliers are detected, then the outlier analyses are returned as well with the name res.out as prefix to all list objects. For example, the descriptive statistics of the outlier analyses, can be indexed by using obj$res.out$descriptives, with obj being the object of the csCompare results.

The values of the descriptives are described in psych::describe.

The values of the freq.results are: method: which test was run.

alternative: the alternative hypothesis.

WG1, WG2: the Shapiro test values, separately for group 1 and group 2. In case of a paired-samples t-test, the WG2 is 0.

WpG1, WpG2: the p-values of Shapiro test, separately for group 1 and group 2. In case of a paired-samples t-test, the WpG2 is 0.

null.value: The value defined by mu (see above).

LCI, HCI: The low (LCI) and high (HCI) bounds of the confidence intervals.

t.statistic: Logical.

df: The degrees of freedom of the t-test performed.

p.value: The p-value of the performed t-test.

cohenD: The Cohen's d for the performed t-test.

cohenDM: The magnitude of the resulting Cohen's d.

hedgesG: The Hedge's g for the performed t-test.

hedgesGM: The magnitude of the resulting Hedge's g.

The values of the bayes.results are:

LNI, HNI: The low (LNI) and high (HNI) intervals of the hypothesis to test.

rscale: The used scale (see rscale argument above).

bf10: The BF10.

bf01: The BF01.

propError: The proportional error of the computed Bayes factor.

References

Krypotos, A. M., Klugkist, I., & Engelhard, I. M. (2017). Bayesian hypothesis testing for human threat conditioning research: An introduction and the condir R package. European Journal of Psychotraumatology, 8.

Rouder, J. N., Speckman, P. L., Sun, D., Morey, R. D., & Iverson, G. (2009). Bayesian t-tests for accepting and rejecting the null hypothesis. Psychonomic Bulletin & Review, 16, 225-237

See Also

t.test, ttest.tstat

Examples

set.seed(1000)
csCompare(cs1 = rnorm(n = 100, mean = 10), cs2 = rnorm(n = 100, mean = 9))

Plot CRs for each CS

Description

Plot the mean of median of each CRs, for each CS

Usage

csPlot(
  cs1,
  cs2,
  group = NULL,
  data = NULL,
  ylab = "CRs",
  col = c("black", "grey"),
  legend = c("cs1", "cs2")
)

Arguments

cs1

a numeric vector of values. If the data argument is defined, it can refer to either the column index or the column name of the data object. See Details for more information.

cs2

a numeric vector of values. If the data argument is defined, it can refer to either the column index or the column name of the data object. See Details for more information.

group

column index or name that contain the group data. See Details for more information.

data

numeric matrix or data frame that contains the relevant data.

ylab

Label for the x-axis

col

The color of the error bars to be used (either given as a numeric vector or a character string). The length of the chosen colors should be equal to the length of the legend names otherwise a warning is returned.

legend

The legend names to be used. The length of the legend labels should be the same as the length of the color string, otherwise a warning is returned.

Details

csCompare performs both a student t-test (using the stats::t.test function) and a Bayesian t-test (using the BayesFactor::ttest.tstat). In case group is not defined, paired-samples t-tests are run. In case the group is defined, then the csCompare first computes difference scores between the cs1 and the cs2 (i.e., cs1 - cs2). In case the group argument is defined but, after removal of NA's (stats::na.omit), only one group is defined, a paired samples t-test is run.

See Also

t.test, ttest.tstat

Examples

set.seed(1000)
csPlot(cs1 = rnorm(n = 100, mean = 10), cs2 = rnorm(n = 100, mean = 9))

Report results of conditioning data

Description

Report results of data analyses run with the csCompare.

Usage

csReport(
  csCompareObj = NULL,
  csSensitivityObj = NULL,
  save = FALSE,
  fileName = "report",
  alphaLevel = 0.05,
  interpretation = FALSE
)

Arguments

csCompareObj

a list or data frame returned from the csCompare function. The object should be of class csCompare.

csSensitivityObj

Sensitivity analysis results returned from the csSensitivity function. The object should be of class csSensitivity.

save

If code argument is set to FALSE (default), the results are printed on the screen. Otherwise, a '.txt' file with the report is generated.

fileName

The file name of the produced report. The argument is ignored if save is set to FALSE.

alphaLevel

The alpha level to be used for determining significant or non-significant results.

interpretation

Should an interpretation of the results be included? (FALSE). In case of the Bayesian results, the results are interpreted according to Lee and Wagenmakers (2013).

Examples

set.seed(1000)
tmp <- csCompare(cs1 = rnorm(n = 100, mean = 10),
cs2 = rnorm(n = 100, mean = 9))
csReport(tmp)

Plot robustness results

Description

Plots the results of robustness test

Usage

csRobustnessPlot(
  cs1,
  cs2,
  group = NULL,
  data = NULL,
  alternative = "two.sided",
  conf.level = 0.95,
  mu = 0,
  rscaleSens = c("medium", "wide", "ultrawide"),
  BF01 = TRUE,
  ylimz = NULL,
  sensitivity = FALSE
)

Arguments

cs1

a numeric vector of values. If the data argument is defined, it can refer to either the column index or the column name of the data object. See Details for more information.

cs2

a numeric vector of values. If the data argument is defined, it can refer to either the column index or the column name of the data object. See Details for more information.

group

column index or name that contain the group data. See Details for more information.

data

numeric matrix or data frame that contains the relevant data.

alternative

a character string for the specification of the alternative hypothesis. Possible values: "two.sided" (default), "greater" or "less".

conf.level

Interval's confidence level.

mu

a numeric value for the mean value or mean difference.

rscaleSens

the scale factor for the prior used in the Bayesian t.test

BF01

Should the BF01 be plotted (default is set to TRUE). If FALSE, the BF10 is plotted.

ylimz

the limits of the y-axis (default to NULL).

sensitivity

Should the sensitivity results be returned (default is set to FALSE).

Details

This plot template is influenced by the JASP way (https://jasp-stats.org/) for plotting sensitivity analysis results. On the x-axis or the width of the Cauchy's Scale is plotted. On the y-axis either BF01 is plotted (if BF01 is set to TRUE) or BF10 (if BF01 is set to FALSE).

References

JASP Team (2019). JASP (Version 0.11.1)[Computer software].

Krypotos, A. M., Klugkist, I., & Engelhard, I. M. (2017). Bayesian hypothesis testing for human threat conditioning research: An introduction and the condir R package. European Journal of Psychotraumatology, 8.

See Also

csCompare, csSensitivity

Examples

set.seed(1000)
csRobustnessPlot(cs1 = rnorm(n = 100, mean = 10),
cs2 = rnorm(n = 100, mean = 9))

Sensitivity analysis for the Bayes Factors of csCompare results

Description

Perform a sensitivity analysis for the Bayes factors computed with the csCompare results

Usage

csSensitivity(
  cs1,
  cs2,
  group = NULL,
  data = NULL,
  alternative = "two.sided",
  conf.level = 0.95,
  mu = 0,
  rscaleSens = c(0.707, 1, 1.41),
  out.thres = 3
)

Arguments

cs1

a numeric vector of values. If the data argument is defined, it can refer to either the column index or the column name of the data object. See Details for more information.

cs2

a numeric vector of values. If the data argument is defined, it can refer to either the column index or the column name of the data object. See Details for more information.

group

column index or name that contain the group data. See Details for more information.

data

numeric matrix or data frame that contains the relevant data.

alternative

a character string for the specification of the alternative hypothesis. Possible values: "two.sided" (default), "greater" or "less".

conf.level

Interval's confidence level.

mu

a numeric value for the mean value or mean difference.

rscaleSens

the scale factor for the prior used in the Bayesian t.test

out.thres

The threshold for detecting outliers (default is 3). If set to 0, no outliers analysis will be performed. See Details below for more information.

Details

csCompare performs both a student t-test (using the stats::t.test function) and a Bayesian t-test (using the BayesFactor::ttest.tstat). In case group is not defined, paired-samples t-tests are run. In case the group is defined, then the csCompare first computes difference scores between the cs1 and the cs2 (i.e., cs1 - cs2). In case the group argument is defined but, after removal of NA's (stats::na.omit), only one group is defined, a paired samples t-test is run.

Value

The function returns a data frame with the results of the student t-test and the Bayesian t-test.

References

Krypotos, A. M., Klugkist, I., & Engelhard, I. M. (2017). Bayesian hypothesis testing for human threat conditioning research: An introduction and the condir R package. European Journal of Psychotraumatology, 8.

See Also

csCompare, t.test, ttest.tstat

Examples

set.seed(1000)
csSensitivity(cs1 = rnorm(n = 100, mean = 10),
cs2 = rnorm(n = 100, mean = 9))

Shiny app for the condir package

Description

Launches a Shiny app for performing the core analyses included in condir

Usage

csShine()

Details

The function can be called without any arguments (i.e., csShine()). For the interface, we used a css template available at http://getbootstrap.com.

References

Krypotos, A. M., Klugkist, I., & Engelhard, I. M. (2017). Bayesian hypothesis testing for human threat conditioning research: An introduction and the condir R package. European Journal of Psychotraumatology, 8.


Produce tables of csCompare results

Description

It provides wrapper functions for generating tables of different types of computer languages.

Usage

csTable(csCompareObj, typeOfTable = "latex")

Arguments

csCompareObj

a list or data frame returned from the csCompare function

typeOfTable

The type of table to be generated. See details

Details

csCompare generates tables of different languages. The options are latex, and markdown.

Examples

tmp <- csCompare(cs1 = c(1, 2, 3, 1, 4), cs2 = c(10, 12, 12, 31, 13))
csTable(tmp)

Local function for determining how BF is reported

Description

Function used for determining the symbol, and the form, of the BF reported.

Usage

roundBF(bf, rscale, BF01 = TRUE)

Arguments

bf

Logical. The BF.

rscale

The rscale that was used.

BF01

Whether the BF01 (default) should be reported or not