simDat8: Simulate data for Chapter 8: Two-way ANOVA

View source: R/dataSimulation.R

simDat8R Documentation

Simulate data for Chapter 8: Two-way ANOVA

Description

Simulate wing length measurements of mourning cloak butterflies with two factors (habitat and population) including their interaction if so wished (simulation under a fixed-effects model)

Usage

simDat8(
  nPops = 5,
  nHab = 3,
  nSample = 12,
  baseline = 40,
  pop.eff = c(-10, -5, 5, 10),
  hab.eff = c(5, 10),
  interaction.eff = c(-2, 3, 0, 4, 4, 0, 3, -2),
  sigma = 3
)

Arguments

nPops

Number of populations

nHab

Number of habitats

nSample

Samples from each population-habitat combination

baseline

Grand mean length

pop.eff

Population effects, should be nPops - 1 values

hab.eff

Habitat effects, should be nHab - 1 values

interaction.eff

Interaction effects, should be (nPops-1)*(nHab-1) values

sigma

Value for the residual standard deviation

Value

A list of simulated data and parameters.

nPops

Number of populations

nSample

Number of samples per population

baseline

Grand mean length

pop.eff

Population effects

hab.eff

Habitat effects

interaction.eff

Interaction effects

sigma

Residual SD

all.eff

All effects

pop

Indicator for population number

hab

Indicator for habitat number

eps

Simulated residuals

wing

Simulated wing lengths

Author(s)

Marc Kéry

Examples

str(dat <- simDat8())      # Implicit default arguments (for the model with interactions)
# Model with main effects only (and very large sample size; to minimize sampling error 
# and clarify structure of main effects in plot)
str(dat <- simDat8(nSample = 1000, interaction.eff = c(0,0,0,0, 0,0,0,0)))
str(dat <- simDat8(nSample = 10000, interaction.eff = rep(0, 8))) # same, even larger sample size

# Revert to one-way ANOVA model with only effects of pop (with much larger sample size)
str(dat <- simDat8(nSample = 10000, pop.eff = c(-10, -5, 5, 10),
    hab.eff = c(0, 0), interaction.eff = rep(0, 8)))  # note no effect of habitat

# Revert to one-way ANOVA model with only effects of hab
str(dat <- simDat8(nSample = 10000, pop.eff = c(0, 0, 0, 0),
    hab.eff = c(5, 10), interaction.eff = rep(0, 8)))  # note no effect of pop

# Revert to "model-of-the-mean"
str(dat <- simDat8(nSample = 10000, pop.eff = c(0, 0, 0, 0), 
    hab.eff = c(0, 0), interaction.eff = rep(0, 8)))  # note no effect of pop nor of h


ASMbook documentation built on Sept. 11, 2024, 5:38 p.m.

Related to simDat8 in ASMbook...