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 |
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.
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.
Riko Kelter
Maintainer: Riko Kelter
For details, see: https://arxiv.org/abs/1906.07524v1
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)
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)
Plots the results of a Bayesian ANOVA
anovaplot(dataframe, type="rope", sd="sd", ci=0.95)
anovaplot(dataframe, type="rope", sd="sd", ci=0.95)
dataframe |
A dataframe which is the result of a Bayesian ANOVA |
type |
Selects the type of plot which should be produced. The default is |
sd |
Selects if the results include posterior draws for the standard deviation (default) or the variance. |
ci |
The credible level used for producing credible intervals. The default is |
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, is shown as a red horizontal line, the ROPE of a small effect,
is shown as an orange horizontal line, the ROPE of a medium effect,
is shown as an green horizontal line, and the ROPE of a large effect,
is shown as a purple horizontal line. Corresponding dashed vertical lines show the boundaries between these default ROPEs for effect sizes.
Riko Kelter
For details, see: https://arxiv.org/abs/1906.07524v1
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)
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)
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
.
assumption.check(x1,x2,x3,x4=NULL,x5=NULL,x6=NULL,conf.level=0.95)
assumption.check(x1,x2,x3,x4=NULL,x5=NULL,x6=NULL,conf.level=0.95)
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 |
If a single Shapiro-Wilk test fails, the method returns a warning and recommends to use further diagnostics.
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.
Riko Kelter
For details, see: https://arxiv.org/abs/1906.07524v1
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)
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)
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.
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)
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)
n |
Number of posterior draws the Gibbs sampler produces. The default is |
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 |
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 |
q |
Tuning parameter for the hyperparameters. The default is |
ci |
The credible level for the credible intervals produced. Default is |
The Gibbs sampler is run with four Markov chains to run convergence diagnostics.
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.
Riko Kelter
For details, see: https://arxiv.org/abs/1906.07524v1
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)
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)
Provides a posterior predictive check for a fitted Bayesian ANOVA model.
post.pred.check(anovafit, ngroups, out, reps = 50, eta)
post.pred.check(anovafit, ngroups, out, reps = 50, eta)
anovafit |
A dataframe returned by |
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. |
Provides a posterior predictive check for a fitted Bayesian ANOVA model.
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.
Riko Kelter
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))
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))