Learn R Programming

ASMbook (version 1.0.2)

simDat9: Simulate data for Chapter 9: ANCOVA or general linear model

Description

Simulate mass ~ length regressions in 3 populations of asp vipers

Usage

simDat9(
  nPops = 3,
  nSample = 10,
  beta.vec = c(80, -30, -20, 6, -3, -4),
  sigma = 10
)

Value

A list of simulated data and parameters.

nPops

Number of populations

nSample

Number of samples per population

beta.vec

Regression parameter values

sigma

Residual SD

x

Indicator for population number

pop

Population name (factor)

lengthC

Centered body length for each viper

mass

Simulated body mass for each viper

Arguments

nPops

Number of populations

nSample

Samples from each population

beta.vec

Vector of regression parameter values

sigma

Value for the residual standard deviation

Author

Marc Kéry

Examples

Run this code
# Implicit default arguments (with interaction of length and pop)
str(dat <- simDat9())

# Revert to main-effects model with parallel lines
str(dat <- simDat9(beta.vec = c(80, -30, -20, 6, 0, 0)))

# Revert to main-effects model with parallel lines 
# (larger sample size to better show patterns)
str(dat <- simDat9(nSample = 100, beta.vec = c(80, -30, -20, 6, 0, 0)))

# Revert to simple linear regression: no effect of population 
# (larger sample size to better show patterns)
str(dat <- simDat9(nSample = 100, beta.vec = c(80, 0, 0, 6, 0, 0)))

# Revert to one-way ANOVA model: no effect of body length 
# (larger sample size to better show patterns)
str(dat <- simDat9(nSample = 100, beta.vec = c(80, -30, -20, 0, 0, 0)))

# Revert to "model-of-the-mean": no effects of either body length or population)
str(dat <- simDat9(nSample = 100, beta.vec = c(80, 0, 0, 0, 0, 0)))

Run the code above in your browser using DataLab