Description Usage Arguments Details Value References Examples
bayes.t.test
estimates the mean of one group, or the difference in
means between two groups, using Bayesian estimation and is intended as a
replacement for t.test
. Is based on Bayesian Estimation
Supersedes the t-test (BEST) (Kruschke, 2012).
1 2 3 4 5 6 7 8 9 10 | bayes.t.test(x, ...)
## Default S3 method:
bayes.t.test(x, y = NULL, alternative = c("two.sided",
"less", "greater"), mu = 0, paired = FALSE, var.equal = FALSE,
cred.mass = 0.95, n.iter = 30000, progress.bar = "text", conf.level,
...)
## S3 method for class 'formula'
bayes.t.test(formula, data, subset, na.action, ...)
|
x |
a (non-empty) numeric vector of data values. |
... |
further arguments to be passed to or from methods. |
y |
an optional (non-empty) numeric vector of data values. |
alternative |
ignored and is only retained in order to mantain
compatibility with |
mu |
a fixed relative mean value to compare with the estimated mean (or the difference in means when performing a two sample BEST). |
paired |
a logical indicating whether you want to estimate a paired samples BEST. |
var.equal |
ignored and is only retained in order to mantain
compatibility with |
cred.mass |
the amount of probability mass that will be contained in
reported credible intervals. This argument fills a similar role as
|
n.iter |
The number of iterations to run the MCMC sampling. |
progress.bar |
The type of progress bar. Possible values are "text", "gui", and "none". |
conf.level |
same as |
formula |
a formula of the form |
data |
an optional matrix or data frame (or similar: see
|
subset |
an optional vector specifying a subset of observations to be used. |
na.action |
a function which indicates what should happen when the data
contain |
As with the t.test
function bayes.t.test
estimates one of
three models depending on the arguments given. All three models are based on
the Bayesian Estimation Supersedes the t test (BEST) model developed by
Kruschke (2013).
If one vecor is supplied a one sample BEST is run. BEST assumes the data (x) is distributed as a t distribution, a more robust alternative to the normal distribution due to its wider tails. Except for the mean (μ) and the scale (σ) the t has one additional parameter, the degree-of-freedoms (ν), where the lower ν is the wider the tails become. When ν gets larger the t distribution approaches the normal distribution. While it would be possible to fix ν to a single value BEST instead estimates ν allowing the t-distribution to become more or less normal depending on the data. Here is the full model for the one sample BEST:
x[i] ~ t(μ, σ, ν)
μ ~ Normal(M[μ], S[μ])
σ ~ Uniform(L[σ], H[σ])
ν ~ Shifted-Exp(1/29, shift=1)
The constants M[μ], S[μ], L[σ] and H[σ] are set so that the priors on μ and σ are essentially flat.
If two vectors are supplied a two sample BEST is run. This is essentially the same as estimaiting two separate one sample BEST except for that both groups are assumed to have the same ν. Here is a Kruschke style diagram showing the two sample BEST model:
If two vectors are supplied and paired=TRUE
then the paired difference
between x - y
is modeled using the one sample BEST.
A list of class bayes_paired_t_test
,
bayes_one_sample_t_test
or bayes_two_sample_t_test
that
contains information about the analysis. It can be further inspected using
the functions summary
, plot
, diagnostics
and
model.code
.
Kruschke, J. K. (2013). Bayesian estimation supersedes the t test. Journal of Experimental Psychology: General, 142(2), 573.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # Using Student's sleep data as in the t.test example
# bayes.t.test can be called in the same way as t.test
# so you can both supply two vectors...
bayes.t.test(sleep$extra[sleep$group == 1], sleep$extra[sleep$group == 2])
# ... or use the formula interface.
bayes.t.test(extra ~ group, data = sleep)
# Save the return value in order to inspect the model result further.
fit <- bayes.t.test(extra ~ group, data = sleep)
summary(fit)
plot(fit)
# MCMC diagnostics
diagnostics(fit)
# Print out the R code to run the model. This can be copy n' pasted into
# an R-script and further modified.
model.code(fit)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.