simulate_gvm: Simulate a Gamma Variability Model

Description Usage Arguments Value Author(s) Examples

View source: R/helpers.R

Description

This function facilitates simulation of a Gamma Variability Model and allows the number of units and repeated measures to be varied as well as the degree of variability.

Usage

1
simulate_gvm(n, k, mu, mu.sigma, sigma.shape, sigma.rate, seed = 5346)

Arguments

n

The number of repeated measures on each unit

k

The number of units

mu

The grand mean of the variable

mu.sigma

The standard deviation of the random mean of the variable

sigma.shape

the shape (alpha) parameter of the Gamma distribution controlling the residual variability

sigma.rate

the rate (beta) parameter of the Gamma distribution controlling the residual variability

seed

the random seed, used to make simulations reproductible. Defaults to 5346 (arbitrarily).

Value

a list of the data, IDs, and the parameters used for the simulation

Author(s)

Joshua F. Wiley <[email protected]>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
raw.sim <- simulate_gvm(12, 140, 0, 1, 4, .1, 94367)
sim.data <- with(raw.sim, {
  set.seed(265393)
  x2 <- MASS::mvrnorm(k, c(0, 0), matrix(c(1, .3, .3, 1), 2))
  y2 <- rnorm(k, cbind(Int = 1, x2) %*% matrix(c(3, .5, .7)) + sigma, sd = 3)
  data.frame(
    y = Data$y,
    y2 = y2[Data$ID2],
    x1 = x2[Data$ID2, 1],
    x2 = x2[Data$ID2, 2],
    ID = Data$ID2)
})

varian documentation built on May 29, 2017, 7:14 p.m.