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 ofn,sdsorlabels, or3when 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
batchtimes and returns a plainlistofbatchresults, each exactly what the same call withoutbatchreturns. With aseed, every dataset gets its own seed drawn fromseed, so the whole batch is reproducible; without one the datasets are consecutive draws from the session's random-number stream. The defaultNULLreturns 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)
#> <simulab_sim:anova> 6 rows x 3 columns
#> id group outcome
#> 1 1 Group 1 -0.6264538
#> 2 2 Group 1 0.1836433
#> 3 3 Group 1 -0.8356286
#> 4 4 Group 1 1.5952808
#> 5 5 Group 1 0.3295078
#> 6 6 Group 1 -0.8204684
#>
#> Truth (parameters):
#> group n mean sd
#> 1 Group 1 90 0.0 1
#> 2 Group 2 90 0.4 1
#> 3 Group 3 90 0.9 1
#>
#> Other tables: effects. Read one with as.data.frame(x, what = "effects").
as.data.frame(result, what = "parameters")
#> group n mean sd
#> 1 Group 1 90 0.0 1
#> 2 Group 2 90 0.4 1
#> 3 Group 3 90 0.9 1