# csCompare: Statistically compare CRs towards two CSs In AngelosPsy/condir: Computation of P Values and Bayes Factors for Conditioning Data

## Description

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

## Usage

 ```1 2 3``` ```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 speficication 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 threeshold 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. (submitted).Bayesian Hypothesis Testing for Human Threat Conditioning Research: An introduction and the condir R package.

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

`t.test`, `ttest.tstat`
 `1` ```csCompare(cs1 = rnorm(n = 100, mean = 10), cs2 = rnorm(n = 100, mean = 9)) ```