I am interested in fitting a Bayesian Two Factor ANOVA in BUGS or by utilizing some R package. Unfortunately I am having a hard time finding resources on this topic. Any suggestions? Even an article describing the approach would be helpful.

# Solved – Bayesian two-factor ANOVA

anovabayesianbugsr

#### Related Solutions

Here are some links which may interest you comparing frequentist and Bayesian methods:

- http://www.stat.ufl.edu/archived/casella/Talks/BayesRefresher.pdf
- http://www.bayesian-inference.com/advantagesbayesian
- http://www.researchgate.net/post/Bayesian_vs_frequentist_statistics2

In a nutshell, the way I have understood it, given a specific set of data, the frequentist believes that there is a true, underlying distribution from which said data was generated. The inability to get the exact parameters is a function of finite sample size. The Bayesian, on the other hand, think that we start with some assumption about the parameters (even if unknowingly) and use the data to refine our opinion about those parameters. Both are trying to develop a model which can explain the observations and make predictions; the difference is in the assumptions (both actual and philosophical). As a pithy, non-rigorous, statement, one can say the frequentist believes that the parameters are fixed and the data is random; the Bayesian believes the data is fixed and the parameters are random. Which is better or preferable? To answer that you have to dig in and realize just **what** assumptions each entails (e.g. are parameters asymptotically normal?).

While I'm no expert in repeated measures ANOVA, I have some familiarity with the `Anova()`

function in `car`

.

`Type I`

or sequential Anova estimates a sequence of models in an effectively arbitrary order, each time permanently removing the previously tested regressor from the subsequent step. Many of its steps are not necessarily interesting simply because the full model isn't being considered in the tests. While `Type III`

Anova seems overall like a snake pit, that you don't touch unless you absolutely know what you're doing (e.g. specify correct contrasts, correctly interpret coefficients, and assorted philosophical conundrums).

As for `Type II`

Anova, in my understanding and as a general principle it estimates a sequence of models with carefully chosen tests, each time removing a single regressor from the model *while respecting the principle of marginality*. The "principle of marginality" requires that when comparing a model that includes a variable with a model that doesn't include it, all higher-order terms that incorporate said variable (e.g. interactions) should be removed from both models. The full model is used in each step if it doesn't conflict with the principle of marginality. For a more detailed account of how `Anova(..., type=2)`

works and its theoretical underpinnings see Fox and Weisberg (2011), Fox (2016) or even Venables and Ripley (2002) (the relevant sections that tackle the principle of marginality are relatively short reads).

So without any other info (and unless `?Anova`

has indications to the contrary for these specific models), by looking at the table above I would assume that:

- the
`F-test`

associated with`diet:time_fac`

interaction term was estimated by comparing the full model against the model that doesn't include the interaction term (as usual). - the
`F-test`

associated with the`time_fac`

main-effect regressor was estimated by comparing two models that both had the interaction term removed: the model that includes*both*`diet`

and`time_fac`

vs the model that includes only`diet`

. - the
`F-test`

associated with the`diet`

main-effect regressor is similar to the above: the model that includes*both*`diet`

and`time_fac`

vs the model that includes only`time_fac`

.

So to answer your question, the interaction term is automatically removed as required by the principle of marginality, so the main effects are tested without the confounding effect of the interaction term. If the interaction term is significant, you disregard the main effects; otherwise, you consider the main effects alone.

## Best Answer

Simon Jackman has some working code for fitting ANOVA and regression models with JAGS (which is pretty like BUGS), e.g. two-way ANOVA via JAGS (R code) or maybe among his handouts on bayesian analysis for the social sciences.

A lot of WinBUGS code, including one- and two-way ANOVA, seem to be available on the companion website for Bayesian Modeling Using WinBUGS: An introduction.