View source: R/Visualizations.R
marginal_likelihood | R Documentation |
This function can be used to compute a Bayes factor as the ratio of two marginal likelihoods.
marginal_likelihood(observed_t, prior = function(x) dcauchy(x, scale = sqrt(2)/2), n1, n2)
observed_t |
The observed t-value. |
prior |
A function object describing the a-priori plausibility of all effect sizes. The default is a Cauchy prior as in package BayesFactor (Morey & Rouder, 2015). Can also be a scalar, in which case it is assumed that the alternative is a point hypothesis on Cohen's d (with value 'prior'). |
n1 |
The sample size in group 1 |
n2 |
The sample size in group 2 |
The marginal likelihood of the observed t-value given the prior on Cohen's d.
## Compute Bayes factor for standard Cauchy prior: n1 <- 100 n2 <- 100 sample1 <- rnorm(n1, 0.2, 1) sample2 <- rnorm(n1, 0.2, 1) tvalue <- t.test(sample1, sample2)$statistic ml_alt <- marginal_likelihood(tvalue, n1 = n1, n2 = n2) bf10 <- ml_alt / dt(tvalue, n1 + n2 - 2) # Compare: BayesFactor::ttestBF(sample1, sample2) ## Normal prior - N(0, 0.3) marginal_likelihood(3, function(x) dnorm(x, 0, 0.3), n1 = 30, n2 = 30)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.