create_cohort: Simulate Case-Control Data with Correlated Predictors

Description Usage Arguments Value See Also Examples

View source: R/sim_create_cohort.R

Description

This function uses simstudy package and creates a dataset of a cohort based on given parameter.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
create_cohort(
  nobs,
  npred,
  ccr,
  nassoc,
  marginal_prob,
  true_beta,
  corr_param = NULL,
  bal = FALSE
)

Arguments

nobs

Integer, number of observations.

npred

Integer, number of predictor variables.

ccr

Numeric, case-control ratio

nassoc

Integer, number of predictors that are truely associated with the outcome.

marginal_prob

A numeric vector of size npred that determines the marginal probabilities of the predictor variables.

true_beta

numeric vector of true effects.

corr_param

either a correlation structure between predictor variables as numeric. matrix or rho as numeric for genCorGen() (Default: NULL).

bal

if TRUE, the case-to-control ratio is printed (Default: FALSE).

Value

A data.table object of size nobs x (npred + 2).

See Also

genCorGen.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
library(simstudy)

set.seed(4875)
nobs <- 1000
npred <- 100
ccr <- 0.5
nassoc <- 5
marginal_prob <- rep(0.15, npred)
true_beta <- rep(c(log(5), 0), c(nassoc, npred - nassoc))

# -- simulate data
cohort <- create_cohort(nobs = nobs, npred = npred, nassoc = nassoc, ccr = ccr,
                        marginal_prob = marginal_prob, true_beta = true_beta)

# -- test marginals and effects
apply(cohort, 2, mean)
summary(glm(out ~ ., data = cohort[,-1], family = "binomial", maxit = 100))$coefficients


# -- simulate correlated data (positive-definite)
corr_param <- outer(1:npred, 1:npred,
                     function(x,y) {(-1)^(1+abs(x-y)) * 0.95^abs(x-y)})

# -- or provide rho
corr_param <- 0.1

cohort <- create_cohort(nobs = nobs, npred = npred, nassoc = nassoc,
                        ccr = ccr, marginal_prob = marginal_prob,
                        true_beta = true_beta, corr_param = corr_param)

bips-hb/rgp documentation built on Feb. 3, 2021, 11:31 a.m.