Package 'bayesanova'

Title: Bayesian Inference in the Analysis of Variance via Markov Chain Monte Carlo in Gaussian Mixture Models
Description: Provides a Bayesian version of the analysis of variance based on a three-component Gaussian mixture for which a Gibbs sampler produces posterior draws. For details about the Bayesian ANOVA based on Gaussian mixtures, see Kelter (2019) <arXiv:1906.07524>.
Authors: Riko Kelter
Maintainer: Riko Kelter <[email protected]>
License: GPL-2
Version: 1.6
Built: 2025-02-17 05:00:21 UTC
Source: https://github.com/cran/bayesanova

Help Index


Bayesian ANOVA

Description

Provides a Bayesian version of the analysis of variance (ANOVA) based on a three-component Gaussian mixture, for which a Gibbs sampler produces the posteriors of the means and standard deviation of each component. Also, model assumptions can be checked and results visualised.

Details

The DESCRIPTION file: This package was not yet installed at build time.
Index: This package was not yet installed at build time.
The core function is bayes.anova which provides the Bayesian version of the ANOVA. Also, assumptions can be checked via assumption.check, and anovaplot produces visualizations of the results.

Author(s)

Riko Kelter

Maintainer: Riko Kelter

References

For details, see: https://arxiv.org/abs/1906.07524v1

Examples

set.seed(42)
x1=rnorm(75,0,1)
x2=rnorm(75,1,1)
x3=rnorm(75,2,1)
assumption.check(x1,x2,x3,conf.level = 0.95)
result=bayes.anova(n=1000,first=x1,second=x2,third=x3)
anovaplot(result)

anovaplot

Description

Plots the results of a Bayesian ANOVA

Usage

anovaplot(dataframe, type="rope", sd="sd", ci=0.95)

Arguments

dataframe

A dataframe which is the result of a Bayesian ANOVA

type

Selects the type of plot which should be produced. The default is "rope", which produces a posterior region of practical equivalence (ROPE) analysis and posterior distributions for the three effect sizes of interest. Other options are to produce posteriors for each parameter via type=="pars", or to produce posteriors for the difference of means and variances via type=="diff".

sd

Selects if the results include posterior draws for the standard deviation (default) or the variance. sd="sd" is the default. sd="var" assumes that the dataframe includes posterior draws of the variances of each group.

ci

The credible level used for producing credible intervals. The default is ci=0.95.

Value

Produces plots of the results depending on which type is selected. In the default setting, the produced plots include horizontal colored lines which visualize the standard regions of practical equivalence (ROPEs) for the effect size of Cohen. In particular, the ROPE of no effect, δ(0.2,0.2)\delta \in (-0.2,0.2) is shown as a red horizontal line, the ROPE of a small effect, δ[0.2,0.5)|\delta| \in [0.2,0.5) is shown as an orange horizontal line, the ROPE of a medium effect, δ[0.5,0.8)|\delta| \in [0.5,0.8) is shown as an green horizontal line, and the ROPE of a large effect, δ[0.8,0.)|\delta| \in [0.8,0.\infty) is shown as a purple horizontal line. Corresponding dashed vertical lines show the boundaries between these default ROPEs for effect sizes.

Author(s)

Riko Kelter

References

For details, see: https://arxiv.org/abs/1906.07524v1

Examples

set.seed(42)
x1=rnorm(75,0,1)
x2=rnorm(75,1,1)
x3=rnorm(75,2,1)
result=bayes.anova(n=1000,first=x1,second=x2,third=x3)

anovaplot(result)
anovaplot(result, type="effect")

x4=rnorm(75,3,1)
result2=bayes.anova(n=1000,first=x1,second=x2,third=x3,fourth=x4)
anovaplot(result2)

assumption.check

Description

This function checks the assumption of normality for each of the groups x1, x2, x3 (and optional x4, x5 and 6) used in the Bayesian ANOVA via Shapiro-Wilk tests with confidence level conf.level.

Usage

assumption.check(x1,x2,x3,x4=NULL,x5=NULL,x6=NULL,conf.level=0.95)

Arguments

x1

Numerical vector containing the values for the first group

x2

Numerical vector containing the values for the second group

x3

Numerical vector containing the values for the third group

x4

Numerical vector containing the values for the fourth group. Defaults to NULL.

x5

Numerical vector containing the values for the fifth group. Defaults to NULL.

x6

Numerical vector containing the values for the sixth group. Defaults to NULL.

conf.level

Confidence level of the Shapiro-Wilk test used. Significance level equals 1-conf.level

Details

If a single Shapiro-Wilk test fails, the method returns a warning and recommends to use further diagnostics.

Value

Histograms and Quantile-Quantile plots for all groups are produced, either a warning or a confirmation of normality in all three groups is printed to the console.

Author(s)

Riko Kelter

References

For details, see: https://arxiv.org/abs/1906.07524v1

Examples

set.seed(42)
x1=rnorm(75,0,1)
x2=rnorm(75,1,1)
x3=rnorm(75,2,1)

assumption.check(x1,x2,x3,conf.level = 0.95)

bayes.anova

Description

This function runs a Bayesian analysis of variance (ANOVA) on the data. The Bayesian ANOVA model assumes normally distributed data in all three groups, and conducts inference based on a Gibbs sampler in a three-component Gaussian-mixture with unknown parameters.

Usage

bayes.anova(n=10000,first,second,third,fourth=NULL,fifth=NULL,sixth=NULL,
hyperpars="custom",burnin=n/2,sd="sd",q=0.1,ci=0.95)

Arguments

n

Number of posterior draws the Gibbs sampler produces. The default is n=10000.

first

Numerical vector containing the values of the first group

second

Numerical vector containing the values of the second group

third

Numerical vector containing the values of the third group

fourth

Numerical vector containing the values of the fourth group. Default value is NULL.

fifth

Numerical vector containing the values of the fifth group. Default value is NULL.

sixth

Numerical vector containing the values of the sixth group. Default value is NULL.

hyperpars

Sets the hyperparameters on the prior distributions. Two options are provided. The default is "custom", and the other is "rafterys". For details, see the references.

burnin

Burn-in samples for the Gibbs sampler

sd

Selects if posterior draws should be produced for the standard deviation (default) or the variance. The two options are "sd" and "var" respectively.

q

Tuning parameter for the hyperparameters. The default is q=0.1 and it is recommended not to change this.

ci

The credible level for the credible intervals produced. Default is ci=0.95.

Details

The Gibbs sampler is run with four Markov chains to run convergence diagnostics.

Value

Returns a dataframe which includes four columns for each parameter of interest. Each column corresponds to the posterior draws of a single Markov chain obtained by the Gibbs sampling algorithm.

Author(s)

Riko Kelter

References

For details, see: https://arxiv.org/abs/1906.07524v1

Examples

set.seed(42)
x1=rnorm(75,0,1)
x2=rnorm(75,1,1)
x3=rnorm(75,2,1)
x4=rnorm(75,-1,1)
result=bayes.anova(first=x1,second=x2,third=x3)
result=bayes.anova(n=1000,first=x1,second=x2,third=x3,
hyperpars="custom",burnin=750,ci=0.99,sd="sd")
result2=bayes.anova(n=1000,first=x1,second=x2,third=x3,
fourth=x4)

post.pred.check

Description

Provides a posterior predictive check for a fitted Bayesian ANOVA model.

Usage

post.pred.check(anovafit, ngroups, out, reps = 50, eta)

Arguments

anovafit

A dataframe returned by bayes.anova

ngroups

An integer which is the number of groups used in the ANOVA

out

A numerical vector containing the originally observed data in all groups

reps

An integer which is the number of posterior predictive distributions sampled from the ANOVA models posterior distribution. Defaults to 50 sampled parameters.

eta

A numerical vector containing the weight values of the mixture.

Details

Provides a posterior predictive check for a fitted Bayesian ANOVA model.

Value

Produces a plot consisting of a density estimate of the original data and posterior predictive distributions sampled from the posterior of the Bayesian ANOVA model as density overlays.

Author(s)

Riko Kelter

Examples

set.seed(700)
x1=rnorm(1000,0,1)
x2=rnorm(1000,1,1)
x3=rnorm(1000,2,2)

result=bayes.anova(n=1000,first = x1, second=x2, third=x3)
post.pred.check(result, ngroups = 3, out = c(x1,x2,x3), reps = 25, eta = c(1/3,1/3,1/3))