bayes.t.test {Bolstad}  R Documentation 
Bayesian ttest
Description
Performs one and two sample ttests (in the Bayesian hypothesis testing framework) on vectors of data
Usage
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 = TRUE,
conf.level = 0.95,
prior = c("jeffreys", "joint.conj"),
m = NULL,
n0 = NULL,
sig.med = NULL,
kappa = 1,
sigmaPrior = "chisq",
nIter = 10000,
nBurn = 1000,
...
)
## S3 method for class 'formula'
bayes.t.test(formula, data, subset, na.action, ...)
Arguments
x 
a (nonempty) numeric vector of data values. 
... 
any additional arguments 
y 
an optional (nonempty) numeric vector of data values. 
alternative 
a character string specifying the alternative hypothesis, must be one of

mu 
a number indicating the true value of the mean (or difference in means if you are performing a two sample test). 
paired 
a logical indicating whether you want a paired ttest. 
var.equal 
a logical variable indicating whether to treat the two variances as being equal.
If 
conf.level 
confidence level of interval. 
prior 
a character string indicating which prior should be used for the means, must be one of

m 
if the joint conjugate prior is used then the user must specify a prior mean in the onesample or paired case, or two prior means in the twosample case. Note that if the hypothesis is that there is no difference between the means in the twosample case, then the values of the prior means should usually be equal, and if so, then their actual values are irrelvant.This parameter is not used if the user chooses a Jeffreys' prior. 
n0 
if the joint conjugate prior is used then the user must specify the prior precision or precisions in the two sample case that represent our level of uncertainty about the true mean(s). This parameter is not used if the user chooses a Jeffreys' prior. 
sig.med 
if the joint conjugate prior is used then the user must specify the prior median for the unknown standard deviation. This parameter is not used if the user chooses a Jeffreys' prior. 
kappa 
if the joint conjugate prior is used then the user must specify the degrees of freedom for the inverse chisquared distribution used for the unknown standard deviation. Usually the default of 1 will be sufficient. This parameter is not used if the user chooses a Jeffreys' prior. 
sigmaPrior 
If a twosample ttest with unequal variances is desired then the user must choose between
using an chisquared prior ("chisq") or a gamma prior ("gamma") for the unknown population standard deviations.
This parameter is only used if 
nIter 
Gibbs sampling is used when a twosample ttest with unequal variances is desired. This parameter controls the sample size from the posterior distribution. 
nBurn 
Gibbs sampling is used when a twosample ttest with unequal variances is desired. This parameter controls the number of iterations used to burn in the chains before the procedure starts sampling in order to reduce correlation with the starting values. 
formula 
a formula of the form 
data 
an optional matrix or data frame (or similar: see 
subset 
currently ingored. 
na.action 
currently ignored. 
Value
A list with class "htest" containing the following components:
statistic 
the value of the tstatistic. 
parameter 
the degrees of freedom for the tstatistic. 
p.value 
the pvalue for the test. 
"
conf.int 
a confidence interval for the mean appropriate to the specified alternative hypothesis. 
estimate 
the estimated mean or difference in means depending on whether it was a onesample test or a twosample test. 
null.value 
the specified hypothesized value of the mean or mean difference depending on whether it was a onesample test or a twosample test. 
alternative 
a character string describing the alternative hypothesis. 
method 
a character string indicating what type of ttest was performed. 
data.name 
a character string giving the name(s) of the data. 
result 
an object of class 
Methods (by class)

default
: Bayesian ttest 
formula
: Bayesian ttest
Author(s)
R Core with Bayesian internals added by James Curran
Examples
bayes.t.test(1:10, y = c(7:20)) # P = .3.691e01
## Same example but with using the joint conjugate prior
## We set the prior means equal (and it doesn't matter what the value is)
## the prior precision is 0.01, which is a prior standard deviation of 10
## we're saying the true difference of the means is between [25.7, 25.7]
## with probability equal to 0.99. The median value for the prior on sigma is 2
## and we're using a scaled inverse chisquared prior with 1 degree of freedom
bayes.t.test(1:10, y = c(7:20), var.equal = TRUE, prior = "joint.conj",
m = c(0,0), n0 = rep(0.01, 2), sig.med = 2)
##' Same example but with a large outlier. Note the assumption of equal variances isn't sensible
bayes.t.test(1:10, y = c(7:20, 200)) # P = .1979  NOT significant anymore
## Classical example: Student's sleep data
plot(extra ~ group, data = sleep)
## Traditional interface
with(sleep, bayes.t.test(extra[group == 1], extra[group == 2]))
## Formula interface
bayes.t.test(extra ~ group, data = sleep)