Learn R Programming

simglm (version 0.8.0)

sim_reg_single: Master function to simulate single level data.

Description

Takes simulation parameters as inputs and returns simulated data.

Usage

sim_reg_single(
  fixed,
  fixed_param,
  cov_param,
  n,
  error_var,
  with_err_gen,
  arima = FALSE,
  data_str,
  cor_vars = NULL,
  fact_vars = list(NULL),
  lvl1_err_params = NULL,
  arima_mod = list(NULL),
  contrasts = NULL,
  homogeneity = TRUE,
  heterogeneity_var = NULL,
  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.

error_var

Scalar of error variance.

with_err_gen

Simulated within cluster error distribution. Must be a quoted 'r' distribution function.

arima

TRUE/FALSE flag indicating whether residuals should be correlated. If TRUE, must specify a valid model to pass to arima.sim via the arima_mod argument. See arima.sim for examples.

data_str

Type of data. Must be "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'.

Optional arguments include:

  • replace

  • prob

  • value.labels

See also sample for use of these optional arguments.

lvl1_err_params

Additional parameters passed as a list on to the level one error generating function

arima_mod

A list indicating the ARIMA model to pass to arima.sim. See arima.sim for examples.

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.

homogeneity

Either TRUE (default) indicating homogeneity of variance assumption is assumed or FALSE to indicate desire to generate heterogeneity of variance.

heterogeneity_var

Variable name as a character string to use for heterogeneity of variance simulation.

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 regression models. Returns a data frame with ID variables, fixed effects, and many other variables useful to help when running simulation studies.

See Also

sim_reg for a convenient wrapper for all data conditions.

Examples

Run this code
# NOT RUN {
#' # generating parameters for single level regression
fixed <- ~1 + act + diff + numCourse + act:numCourse
fixed_param <- c(2, 4, 1, 3.5, 2)
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
error_var <- 3
with_err_gen <- 'rnorm'
temp_single <- sim_reg(fixed = fixed, fixed_param = fixed_param, 
   cov_param = cov_param, 
   n = n, error_var = error_var, with_err_gen = with_err_gen, 
   data_str = "single")
   
# }

Run the code above in your browser using DataLab