Learn R Programming

gvcm.cat (version 1.3)

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
sd
if needed, i.e. if family = gaussian, standard deviation of response
seed
specifies the to be used seed

Value

  • A data frame containing all specified covariates (even if they are not included in formula) and the response (named y)

Details

Remarks on covariates:
  • all parameterizations like default inDistributions.
  • 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 measurementis only needed fordistribution = "multinom", must be"nominal"or"ordinal".
  • If any, the covariates' correlation is specified by argumentcorrelation. Correlations are defined for Gaussian covariates only. Matrixcorrelationrefers to these covariates according to the order they are listed incovariates. So that the dimensions ofcorrelationmust fit to the number of normal distributed variables incovariates.

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