Computes a single Bayes factor, or samples from the posterior, for an ANOVA model defined by a design matrix
1 2 3 4 5 
y 
vector of observations 
X 
design matrix whose number of rows match

struc 
vector grouping the columns of 
gMap 
alternative way of grouping the columns of

rscale 
a vector of prior scale(s) of appropriate length (see Details). 
iterations 
Number of Monte Carlo samples used to estimate Bayes factor or posterior 
progress 
if 
gibi 
interface for a future graphical user interface (not intended for use by end users) 
gibbs 
if 
ignoreCols 
if 
thin 
MCMC chain to every 
method 
the integration method (only valid if

continuous 
either FALSE is no continuous covariates are included, or a logical vector of length equal to number of columns of X indicating which columns of the design matrix represent continuous covariates 
noSample 
if 
This function is not meant to be called by endusers,
although technicallyminded users can call this function
for flexibility beyond what the other functions in this
package provide. See lmBF
for a
userfriendly frontend to this function. Details about
the priors can be found in the help for
anovaBF
and the references therein.
Arguments struc
and gMap
provide a way of
grouping columns of the design matrix as a factor; the
effects in each group will share a common g
parameter. Only one of these arguments is needed; if both
are given, gMap
takes precedence.
gMap
should be a vector of the same length as the
number of nonconstant rows in X
. It will contain
all integers from 0 to Ng1, where
Ng is the total number of g parameters.
Each element of gMap
specifies the group to which
that column belongs.
If all columns belonging to a group are adjacent,
struc
can instead be used to compactly represent
the groupings. struc
is a vector of length
Ng. Each element specifies the number columns
in the group. gMap
is thus the
inverse.rle
of struc
, minus 1.
The vector rscale
should be of length
Ng, and contain the prior scales of the
standardized effects. See Rouder et al. (2012) for more
details and the help for anovaBF
for some
typical values.
The method used to estimate the Bayes factor depends on
the method
argument. "simple" is most accurate for
small to moderate sample sizes, and uses the Monte Carlo
sampling method described in Rouder et al. (2012).
"importance" uses an importance sampling algorithm with
an importance distribution that is multivariate normal on
log(g). "laplace" does not sample, but uses a Laplace
approximation to the integral. It is expected to be more
accurate for large sample sizes, where MC sampling is
slow. If method="auto"
, then an initial run with
both samplers is done, and the sampling method that
yields the leastvariable samples is chosen. The number
of initial test iterations is determined by
options(BFpretestIterations)
.
If posterior samples are requested, the posterior is sampled with a Gibbs sampler.
If posterior
is FALSE
, a vector of length 2
containing the computed log(e) Bayes factor (against the
interceptonly null), along with a proportional error
estimate on the Bayes factor. Otherwise, an object of
class mcmc
, containing MCMC samples from the
posterior is returned.
Richard D. Morey (richarddmorey@gmail.com), Jeffery N. Rouder (rouderj@missouri.edu)
Rouder, J. N., Morey, R. D., Speckman, P. L., Province, J. M., (2012) Default Bayes Factors for ANOVA Designs. Journal of Mathematical Psychology. 56. p. 356374.
See lmBF
for the userfriendly front end to
this function; see regressionBF
and
anovaBF
for testing many regression or ANOVA
models simultaneously.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21  ## Classical example, taken from t.test() example
## Student's sleep data
data(sleep)
plot(extra ~ group, data = sleep)
## traditional ANOVA gives a p value of 0.00283
summary(aov(extra ~ group + Error(ID/group), data = sleep))
## Build design matrix
group.column < rep(1/c(sqrt(2),sqrt(2)),each=10)
subject.matrix < model.matrix(~sleep$ID  1,data=sleep$ID)
## Note that we include no constant column
X < cbind(group.column, subject.matrix)
## (log) Bayes factor of full model against grandmean only model
bf.full < nWayAOV(y = sleep$extra, X = X, struc = c(1,10), rscale=c(.5,1))
exp(bf.full['bf'])
## Compare with lmBF result (should be about the same, give or take 1%)
bf.full2 < lmBF(extra ~ group + ID, data = sleep, whichRandom = "ID")
bf.full2

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
All documentation is copyright its authors; we didn't write any of that.