sim.data: Simulates data to use for the 'glmmPen' package

View source: R/sim_generation.R

sim.dataR Documentation

Simulates data to use for the glmmPen package

Description

Simulates data to use for testing the glmmPen package. sim.data simulates data for glmmPen, sim.data.FA simulates data for glmmPen_FA, and sim.data.piecewise.exp simulates data for phmmPen and phmmPen_FA. Possible parameters to specify includes number of total covariates, number of non-zero fixed and random effects, and the magnitude of the random effect covariance values.

Usage

sim.data(
  n,
  ptot,
  pnonzero,
  nstudies,
  sd_raneff = 1,
  family = "binomial",
  corr = NULL,
  seed,
  imbalance = 0,
  beta = NULL,
  pnonzerovar = 0,
  sd_x = 1
)

sim.data.FA(
  n,
  ptot,
  pnonzero,
  nstudies,
  sd_raneff = 0,
  family = "binomial",
  B = NULL,
  r = 2,
  corr = NULL,
  seed,
  imbalance = 0,
  beta = NULL,
  pnonzerovar = 0,
  sd_x = 1
)

sim.data.piecewise.exp(
  n,
  ptot,
  pnonzero,
  nstudies,
  sd_raneff = 0,
  B = NULL,
  r = 2,
  cut_points = c(0, 0.5, 1, 1.5, 2),
  lhaz_vals = c(-1.5, 1, 2.7, 3.7, 6.8),
  cens_type = c("exp", "unif"),
  cens_max = 5,
  exp_rate = 0.15,
  seed,
  imbalance = 0,
  beta = NULL,
  pnonzerovar = 0,
  sd_x = 1
)

Arguments

n

integer specifying total number of samples to generate

ptot

integer specifying total number of covariates to generate (values randomly generated from the standard normal distribution)

pnonzero

integer specifying how may of the covariates should have non-zero fixed and random effects

nstudies

number of studies/groups to have in the data

sd_raneff

non-negative value specifying the standard deviation of the random effects covariance matrix (applied to the non-zero random effects)

family

character string specifying which family to generate data from. Family options include "binomial" (default), "poisson", and "gaussian".

corr

optional value to specify correlation between covariates in the model matrix. Default NULL, only available within sim.data.

seed

integer to use for the setting of a random seed

imbalance

integer of 0 or 1 indicating whether the observations should be equally distributed among the groups (0) or unequally distributed (1).

beta

numeric vector of the fixed effects (including intercept)

pnonzerovar

non-negative integer specifying the number of covariates with a zero-valued fixed effect but a non-zero random effect.

sd_x

non-negative value specifying the standard deviation of the simulated covariates (drawn from a normal distribution with mean 0, standard deviation sd_x)

B

matrix specifying the factor loadings matrix for the random effects, only used within sim.data.FA. Dimensions: number of columns is the number of random effects (including the intercept), and number of rows is the number of latent common factors (r). The random effect covariance matrix is specified as Sigma = B x t(B) + diag(sd_raneff)

r

positive integer specifying number of latent common factors that describe the random effects, only used within sim.data.FA

cut_points

vector of cut points to use for the time intervals when simulating piecewise exponential data. Length of cut points must equal length of lhaz_vals, and the value of the first cut point must be 0.

lhaz_vals

vector of the log baseline hazard values for each time interval (which correspond to the time intervals defined by the cut_points argument) within piecewise exponential data. Hazards are assumed to be constant within each time interval.

cens_type

character specifying type of censoring to implement. Default "unif" specifies uniform censoring from 0 to cens_max. The option "exp" specifies exponential censoring with rate exp_rate

cens_max

numeric value used to characterize the range of the uniform censoring procedure (from 0 to cens_max)

exp_rate

numeric value used to characterize the exponential censoring rate (where rate is defined as the rate used in rexp)

Value

list containing the following elements:

y

vector of the response

X

model matrix for the fixed effects

Z

model matrix for the random effects, organized first by variable and then by group

pnonzero

number of non-zero fixed effects

z1

values of the random effects for each variable for each level of the grouping factor

group

grouping factor

X0

model matrix for just the non-zero fixed effects


hheiling/glmmPen documentation built on Jan. 15, 2024, 11:47 p.m.