effectsize (version 0.4.0)

eta_squared_posterior: Simulate Eta Squared from Posterior Predictive Distribution

Description

This function simulates data from the posterior predictive distribution (ppd) and for each simulation the Eta Squared is computed for the model's fixed effects. This means that the returned values are the population level effect size as implied by the posterior model (and not the effect size in the sample data). See rstantools::posterior_predict() for more info.

Effect sizes are computed using the sums of squares obtained from car::Anova(model, ...) which might not always be appropriate (Yeah... ANOVAs are hard...), e.g., when factors aren't 0-mean codded and covariates aren't centered; a warning will be given in such predictors are detected. See details section in eta_squared().

Usage

eta_squared_posterior(
  model,
  partial = TRUE,
  type = 3,
  draws = 500,
  verbose = TRUE,
  ...
)

Arguments

model

A Bayesian linear model, fit with brms or rstanarm.

partial

Whether Partial Eta should be returned.

type

Type of sum-of-squares to use. See car::Anova().

draws

An integer indicating the number of draws from the posterior predictive distribution to return. Larger numbers take longer to run, but provide estimates that are more stable.

verbose

Show messages / warning about centering.

...

Currently not used.

Value

A data frame containing the ppd of the Eta squared for each fixed effect, which can then be passed to bayestestR::describe_posterior() for summary stats.

Examples

Run this code
# NOT RUN {
if (require(rstanarm) && require(bayestestR)) {
  fit_bayes <- stan_glm(mpg ~ factor(cyl) * wt + qsec,
                        data = mtcars,
                        family = gaussian(),
                        refresh = 0)

  es <- eta_squared_posterior(fit_bayes)

  bayestestR::describe_posterior(es)
}

# compare to:
if (require(car)) {
  fit_freq <- lm(mpg ~ factor(cyl) * wt + qsec,
                 data = mtcars)
  aov_table <- car::Anova(fit_freq, type = 3)
  eta_squared(aov_table)
}
# }
# NOT RUN {

# }

Run the code above in your browser using DataLab