Learn R Programming

DMAR (version 1.0.0)

simulate_anova_data: Simulate Data From a One-Way Fixed-Effects ANOVA Model

Description

Generates random data appropriate for a one-way fixed-effects analysis of variance. Each group's observations are drawn from a normal distribution with that group's population mean and a common (or per-group) standard deviation. Per-group sample sizes may be equal or unequal.

Usage

simulate_anova_data(mu, sigma, a, n, seed = NULL)

Value

A long-format data.frame with one row per simulated subject and two columns:

group

A factor with a levels.

y

Numeric simulated outcome.

Arguments

mu

A numeric vector of length a giving the population mean in each group.

sigma

Within-group population standard deviation. Either a single number (homoscedastic; common across groups) or a numeric vector of length a (heteroscedastic; one SD per group).

a

The number of fixed levels of the grouping factor (per the convention used throughout DMAR for fixed-factor designs).

n

A single number (equal sample size per group) or a numeric vector of length a giving the sample size in each group.

seed

Optional integer random seed for reproducibility (default NULL; supply an integer such as 113 for reproducible output).

Author

Ken Kelley [email protected]

Details

The fixed-effects ANOVA model assumes group-specific means and a common within-group variance. Setting sigma to a vector relaxes the homoscedasticity assumption; in that case the simulated data violate the standard ANOVA assumption (a useful feature for studying robustness or the performance of Welch-style alternatives).

See Also

simulate_ancova_data, simulate_regression_data, contrast_test, ss_power_contrast

Other data simulators: simulate_ancova_data(), simulate_ancova_factorial_data(), simulate_longitudinal_gompertz(), simulate_longitudinal_logistic(), simulate_longitudinal_negative_exponential(), simulate_longitudinal_polynomial(), simulate_longitudinal_richards(), simulate_regression_data()

Examples

Run this code
# Three-group ANOVA, equal n per group.
set.seed(113)
d <- simulate_anova_data(mu = c(50, 55, 60), sigma = 8, a = 3, n = 30)
aggregate(y ~ group, data = d, FUN = mean)

# Same design with unequal n per group.
simulate_anova_data(mu = c(50, 55, 60), sigma = 8, a = 3,
                    n = c(40, 30, 20), seed = 113)

# Heteroscedastic case: each group has its own SD.
simulate_anova_data(mu = c(50, 55, 60), sigma = c(5, 8, 12),
                    a = 3, n = 30, seed = 113)

Run the code above in your browser using DataLab