gvcm.cat (version 1.9)

simulation: Simulates data with categorial covariates

Description

Simulates data with categorial covariates/categorial effect modifiers

Usage

simulation(n, covariates, correlation = NULL, formula, coefficients, family, sd = 1, seed = rpois(1, 2348) * rnorm(1))

Arguments

n
number of observations; must be large enough, so that all categories of all factor variables exist and therefore vector coefficients fits
covariates
description of the covariates and effect modifiers included in the model; format: list( name of variable 1 = list("distribution", c(parameters), "level of measurement"), name of variable 2 = ...)
correlation
optional matrix, specifies the correlation of Gaussian covariates
formula
formula like in gvcm.cat (all variables contained in formula must be defined in covariates)
coefficients
true parameter vector
family
a family object; currently only gaussian, binomial, poisson, Gamma
sd
if family = gaussian, standard deviation of response; if family = Gamma the rate parameter like in rgamma
seed
specifies the to be used seed

Value

formula) and the response (named y)

Details

Remarks on covariates:
  • all parameterizations like default in Distributions.
  • possible distributions of covariates (required as characters), their parameters (required as vectors) and constraints (in parentheses):
    • beta : shape1 (>0), shape2 (>0)
    • exp : rate (>0)
    • gamma : shape (>0)
    • lnorm : mean , sd (>0)
    • multinom: vector of the categories' probabilities (all elements must be >0, sum over all elements must be 1)
    • norm : mean, sd (>0)
    • pois : lambda (>0)
    • unif : min, max

  • level of measurement is only needed for distribution = "multinom", must be "nominal" or "ordinal".
  • If any, the covariates' correlation is specified by argument correlation. Correlations are defined for Gaussian covariates only. Matrix correlation refers to these covariates according to the order they are listed in covariates. So that the dimensions of correlation must fit to the number of normal distributed variables in covariates.

See Also

Function gvcm.cat

Examples

Run this code
## example function simulation
covariates <- list(x1=list("unif", c(0,2)),
                  x2=list("unif", c(0,2)),
                  x3=list("unif", c(0,2)),
                  u=list("multinom",c(0.3,0.4,0.3), "nominal")
                  )
true.f <- y ~ 1 + v(x1,u) + x2
true.coefs <- c(0.2,  0.3,.7,.7, -.5)
data <- simulation(400, covariates, NULL, true.f, true.coefs , binomial(), seed=456)

Run the code above in your browser using DataLab