simulate_anova: Simulate a one-way group design

View source: R/statistical.R

simulate_anovaR Documentation

Simulate a one-way group design

Description

Simulate a one-way group design

Usage

simulate_anova(
  n = 30L,
  means = NULL,
  sds = 1,
  labels = NULL,
  outcome = "outcome",
  seed = NULL,
  batch = NULL
)

Arguments

n

Group sample size or one size per group, defaulting to 30.

means

Group means. NULL (the default) draws one mean per group from the standard normal distribution, rounded to two decimals, inside the same seeded draw as the data. The number of groups is then the length of n, sds or labels, or 3 when all of them have length one.

sds

Group standard deviations.

labels

Optional group labels.

outcome

Name of the outcome variable.

seed

Optional random seed.

batch

Optional single positive whole number. When given, the simulator runs batch times and returns a plain list of batch results, each exactly what the same call without batch returns. With a seed, every dataset gets its own seed drawn from seed, so the whole batch is reproducible; without one the datasets are consecutive draws from the session's random-number stream. The default NULL returns a single result.

Value

A simulab_sim base data.frame with one row per observation and columns id, group and outcome (renamed by outcome). Two tidy tables come from as.data.frame(): what = "parameters" has one row per group with columns group, n, mean and sd; what = "effects" has a single row with columns grand_mean, between_sum_squares (sum(n * (mean - grand_mean)^2)), within_sum_squares (sum((n - 1) * sd^2)) and eta_squared, their ratio between / (between + within). Because the within term uses the degrees of freedom n - 1 rather than n, eta_squared is the design's sum-of-squares eta-squared and differs slightly from the variance-ratio population eta-squared.

Examples

result <- simulate_anova(n = 90, means = c(0, 0.4, 0.9), seed = 1)
head(result)
as.data.frame(result, what = "parameters")

simulab documentation built on Oct. 15, 2026, 5:08 p.m.