Learn R Programming

simglm (version 0.8.0)

sim_glm_single: Simulation single level logistic regression model

Description

Takes simulation parameters as inputs and returns simulated data.

Usage

sim_glm_single(
  fixed,
  fixed_param,
  cov_param,
  n,
  data_str,
  cor_vars = NULL,
  fact_vars = list(NULL),
  contrasts = NULL,
  outcome_type,
  knot_args = list(NULL),
  ...
)

Arguments

fixed

One sided formula for fixed effects in the simulation. To suppress intercept add -1 to formula.

fixed_param

Fixed effect parameter values (i.e. beta weights). Must be same length as fixed.

cov_param

List of arguments to pass to the continuous generating function, must be the same order as the variables specified in fixed. This list does not include intercept, time, factors, or interactions. Required arguments include:

  • dist_fun: This is a quoted R distribution function.

  • var_type: This is the level of variable to generate. Must be 'single'. Must be same order as fixed formula above.

Optional arguments to the distribution functions are in a nested list, see the examples or vignettes for example code.

n

Cluster sample size.

data_str

Type of data. Must be "cross", "long", or "single".

cor_vars

A vector of correlations between variables.

fact_vars

A nested list of factor, categorical, or ordinal variable specification, each list must include:

  • numlevels = Number of levels for ordinal or factor variables.

  • var_type = Must be 'single', 'lvl1', 'lvl2', or 'lvl3'.

Optional arguments include:

  • replace

  • prob

  • value.labels

See also sample for use of these optional arguments.

contrasts

An optional list that specifies the contrasts to be used for factor variables (i.e. those variables with .f or .c). See contrasts for more detail.

outcome_type

A vector specifying the type of outcome, must be either logistic or poisson. Logitstic outcome will be 0/1 and poisson outcome will be counts.

knot_args

A nested list of named knot arguments. See sim_knot for more details. Arguments must include:

  • var

  • knot_locations

...

Not currently used.

Details

Simulates data for the simple logistic regression models. Returns a data frame with ID variables, fixed effects, and many other variables to help when running simulation studies.

Examples

Run this code
# NOT RUN {
# generating parameters for single level regression
set.seed(2)
fixed <- ~1 + act + diff + numCourse + act:numCourse
fixed_param <- c(0.1, -0.2, 0.15, 0.5, -0.02)
cov_param <- list(dist_fun = c('rnorm', 'rnorm', 'rnorm'),
   var_type = c("single", "single", "single"),
   opts = list(list(mean = 0, sd = 4),
   list(mean = 0, sd = 3),
   list(mean = 0, sd = 3)))
n <- 150
temp_single <- sim_glm(fixed = fixed, fixed_param = fixed_param, 
  cov_param = cov_param, n = n, data_str = "single", 
  outcome_type = 'logistic')
  
# }

Run the code above in your browser using DataLab