simDat102: Simulate data for Chapter 10.2: Linear mixed-effects model

View source: R/dataSimulation.R

simDat102R Documentation

Simulate data for Chapter 10.2: Linear mixed-effects model

Description

Simulate mass ~ length regressions in 56 populations of snakes with random population effects for intercepts and slopes. There is no correlation between the intercept and slope random variables.

Usage

simDat102(
  nPops = 56,
  nSample = 10,
  mu.alpha = 260,
  sigma.alpha = 20,
  mu.beta = 60,
  sigma.beta = 30,
  sigma = 30
)

Arguments

nPops

Number of populations

nSample

Samples from each population

mu.alpha

Mean of random intercepts

sigma.alpha

SD of random intercepts

mu.beta

Mean of random slopes

sigma.beta

SD of random slopes

sigma

Residual standard deviation

Value

A list of simulated data and parameters.

nPops

Number of populations

nSample

Number of samples per population

mu.alpha

Mean of random intercepts

sigma.alpha

SD of random intercepts

mu.beta

Mean of random slopes

sigma.beta

SD of random slopes

sigma

Residual SD

pop

Indicator for population number

orig.length

Snake body length, not standardized

lengthN

Snake body length, standardized

alpha

Random intercepts

beta

Random slopes

eps

Residuals

mass

Simulated body mass for each snake

Author(s)

Marc Kéry

Examples

library(lattice)
str(dat <- simDat102())      # Implicit default arguments
xyplot(dat$mass ~ dat$lengthN | dat$pop, xlab = 'Length', ylab = 'Mass', 
       main = 'Realized mass-length relationships', pch = 16, cex = 1.2, 
       col = rgb(0, 0, 0, 0.4))

# Fewer populations, more snakes (makes patterns perhaps easier to see ?)
str(dat <- simDat102(nPops = 16, nSample = 100))
xyplot(dat$mass ~ dat$lengthN | dat$pop, xlab = 'Length', ylab = 'Mass', 
       main = 'Realized mass-length relationships
       (default random-coefficients model)', 
       pch = 16, cex = 1.2, col = rgb(0, 0, 0, 0.4))

# Revert to random intercept model (and less residual variation), fewer pops 
# and more snakes. Increased sigma.alpha to emphasize the random intercepts part
str(dat <- simDat102(nPops = 16, nSample = 100, sigma.alpha = 50, sigma.beta = 0, sigma = 10))
xyplot(dat$mass ~ dat$lengthN | dat$pop, xlab = 'Length', ylab = 'Mass', 
       main = 'Realized mass-length relationships (random-intercepts model)', 
       pch = 16, cex = 1.2, col = rgb(0, 0, 0, 0.4))

# Revert to random-effects one-way ANOVA model, only random intercepts, but zero slopes
str(dat <- simDat102(nPops = 16, nSample = 100, sigma.alpha = 50, 
                     mu.beta = 0, sigma.beta = 0, sigma = 10))
xyplot(dat$mass ~ dat$lengthN | dat$pop, xlab = 'Length', ylab = 'Mass', 
       main = 'Realized mass-length relationships
       (one-way ANOVA model with random pop effects)', 
       pch = 16, cex = 1.2, col = rgb(0, 0, 0, 0.4))

# Revert to simple linear regression (= no effects of pop on either intercepts or slopes)
str(dat <- simDat102(nPops = 16, nSample = 100, sigma.alpha = 0, sigma.beta = 0, sigma = 10))
xyplot(dat$mass ~ dat$lengthN | dat$pop, xlab = 'Length', ylab = 'Mass', 
       main = 'Realized mass-length relationships
       (de-facto a simple linear regression now)', 
       pch = 16, cex = 1.2, col = rgb(0, 0, 0, 0.4))

# Revert to "model-of-the-mean": no effects of either population or body length
str(dat <- simDat102(nPops = 16, nSample = 100, sigma.alpha = 0, mu.beta = 0, 
                     sigma.beta = 0, sigma = 10))
xyplot(dat$mass ~ dat$lengthN | dat$pop, xlab = 'Length', ylab = 'Mass', 
       main = 'Realized mass-length relationships
       ("model-of-the-mean", no effects of pop or length)', 
       pch = 16, cex = 1.2, col = rgb(0, 0, 0, 0.4))


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

Related to simDat102 in ASMbook...