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 |
Compare CRs towards two CSs within a frequentist and a Bayesian framework.
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 )
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 )
cs1 |
a numeric vector of values. If the |
cs2 |
a numeric vector of values. If the |
group |
column index or name that contain the group data. See
|
data |
numeric matrix or data frame that contains the relevant data. |
alternative |
a character string for the specification of
the alternative hypothesis. Possible values: |
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 |
out.thres |
The threshold for detecting outliers (default is 3). If set
to 0, no outliers analysis will be performed. See |
boxplot |
Should a boxplot of the variables be produced (default is TRUE)? |
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.
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.
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
set.seed(1000) csCompare(cs1 = rnorm(n = 100, mean = 10), cs2 = rnorm(n = 100, mean = 9))
set.seed(1000) csCompare(cs1 = rnorm(n = 100, mean = 10), cs2 = rnorm(n = 100, mean = 9))
Plot the mean of median of each CRs, for each CS
csPlot( cs1, cs2, group = NULL, data = NULL, ylab = "CRs", col = c("black", "grey"), legend = c("cs1", "cs2") )
csPlot( cs1, cs2, group = NULL, data = NULL, ylab = "CRs", col = c("black", "grey"), legend = c("cs1", "cs2") )
cs1 |
a numeric vector of values. If the |
cs2 |
a numeric vector of values. If the |
group |
column index or name that contain the group data. See
|
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. |
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.
set.seed(1000) csPlot(cs1 = rnorm(n = 100, mean = 10), cs2 = rnorm(n = 100, mean = 9))
set.seed(1000) csPlot(cs1 = rnorm(n = 100, mean = 10), cs2 = rnorm(n = 100, mean = 9))
Report results of data analyses run with the csCompare
.
csReport( csCompareObj = NULL, csSensitivityObj = NULL, save = FALSE, fileName = "report", alphaLevel = 0.05, interpretation = FALSE )
csReport( csCompareObj = NULL, csSensitivityObj = NULL, save = FALSE, fileName = "report", alphaLevel = 0.05, interpretation = FALSE )
csCompareObj |
a list or data frame returned from
the |
csSensitivityObj |
Sensitivity analysis results returned from the
|
save |
If |
fileName |
The file name of the produced report. The argument is
ignored if |
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). |
set.seed(1000) tmp <- csCompare(cs1 = rnorm(n = 100, mean = 10), cs2 = rnorm(n = 100, mean = 9)) csReport(tmp)
set.seed(1000) tmp <- csCompare(cs1 = rnorm(n = 100, mean = 10), cs2 = rnorm(n = 100, mean = 9)) csReport(tmp)
Plots the results of robustness test
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 )
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 )
cs1 |
a numeric vector of values. If the |
cs2 |
a numeric vector of values. If the |
group |
column index or name that contain the group data. See
|
data |
numeric matrix or data frame that contains the relevant data. |
alternative |
a character string for the specification of
the alternative hypothesis. Possible values: |
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). |
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).
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.
set.seed(1000) csRobustnessPlot(cs1 = rnorm(n = 100, mean = 10), cs2 = rnorm(n = 100, mean = 9))
set.seed(1000) csRobustnessPlot(cs1 = rnorm(n = 100, mean = 10), cs2 = rnorm(n = 100, mean = 9))
csCompare
resultsPerform a sensitivity analysis for the Bayes factors computed
with the csCompare
results
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 )
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 )
cs1 |
a numeric vector of values. If the |
cs2 |
a numeric vector of values. If the |
group |
column index or name that contain the group data. See
|
data |
numeric matrix or data frame that contains the relevant data. |
alternative |
a character string for the specification of
the alternative hypothesis. Possible values: |
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 |
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.
The function returns a data frame with the results of the student t-test and the Bayesian t-test.
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.
csCompare
, t.test
,
ttest.tstat
set.seed(1000) csSensitivity(cs1 = rnorm(n = 100, mean = 10), cs2 = rnorm(n = 100, mean = 9))
set.seed(1000) csSensitivity(cs1 = rnorm(n = 100, mean = 10), cs2 = rnorm(n = 100, mean = 9))
condir
packageLaunches a Shiny app for performing the core analyses included
in condir
csShine()
csShine()
The function can be called without any arguments (i.e., csShine()
).
For the interface, we used a css
template available
at http://getbootstrap.com.
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.
csCompare
resultsIt provides wrapper functions for generating tables of different types of computer languages.
csTable(csCompareObj, typeOfTable = "latex")
csTable(csCompareObj, typeOfTable = "latex")
csCompareObj |
a list or data frame returned from
the |
typeOfTable |
The type of table to be generated. See details |
csCompare
generates tables of different languages.
The options are latex
, and markdown
.
tmp <- csCompare(cs1 = c(1, 2, 3, 1, 4), cs2 = c(10, 12, 12, 31, 13)) csTable(tmp)
tmp <- csCompare(cs1 = c(1, 2, 3, 1, 4), cs2 = c(10, 12, 12, 31, 13)) csTable(tmp)
Function used for determining the symbol, and the form, of the BF reported.
roundBF(bf, rscale, BF01 = TRUE)
roundBF(bf, rscale, BF01 = TRUE)
bf |
Logical. The BF. |
rscale |
The rscale that was used. |
BF01 |
Whether the BF01 (default) should be reported or not |