bayes.t.test: Bayesian First Aid alternative to the t-test

Description Usage Arguments Details Value References Examples

Description

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).

Usage

 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, ...)

Arguments

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 t.test.

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 t.test.

cred.mass

the amount of probability mass that will be contained in reported credible intervals. This argument fills a similar role as conf.level in t.test.

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 cred.mass and is only retained in order to mantain compatibility with binom.test.

formula

a formula of the form lhs ~ rhs where lhs is a numeric variable giving the data values and rhs a factor with two levels giving the corresponding groups.

data

an optional matrix or data frame (or similar: see model.frame) containing the variables in the formula formula. By default the variables are taken from environment(formula).

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 NAs. Defaults to getOption("na.action").

Details

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)

A graphical diagram of the one sample the
BEST model

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:

A graphical diagram of the two sample the
BEST model

If two vectors are supplied and paired=TRUE then the paired difference between x - y is modeled using the one sample BEST.

Value

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.

References

Kruschke, J. K. (2013). Bayesian estimation supersedes the t test. Journal of Experimental Psychology: General, 142(2), 573.

Examples

 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)
 

rasmusab/bayesian_first_aid documentation built on May 27, 2019, 2:03 a.m.