marginal_likelihood: Compute the marginal likelihood of an observed t-value

View source: R/Visualizations.R

marginal_likelihoodR Documentation

Compute the marginal likelihood of an observed t-value

Description

This function can be used to compute a Bayes factor as the ratio of two marginal likelihoods.

Usage

marginal_likelihood(observed_t, prior = function(x) dcauchy(x, scale =
  sqrt(2)/2), n1, n2)

Arguments

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

Value

The marginal likelihood of the observed t-value given the prior on Cohen's d.

Examples

## 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)


m-Py/bayesEd documentation built on Feb. 25, 2023, 5:35 p.m.