PlasmodeBin: Performs the plasmode simulation

Description Usage Arguments Details Value Author(s) Examples

Description

Creates 'plasmode'simulated datasets based on a given dataset when the outcome variable and exposure variable are binary. Plasmode simulation samples subjects with replacement from the observed data, uses subjects’ covariate data as is, and simulates exposure, outcome, or both.

Usage

1
2
3
PlasmodeBin(formulaOut = NULL, objectOut = NULL, formulaExp = NULL,
  objectExp = NULL, data, idVar, effectOR = 1, MMOut = 1, MMExp = 1,
  nsim, size, eventRate = NULL, exposedPrev = NULL)

Arguments

formulaOut

An outcome model formula containing the binary outcome on the left-hand side and binary exposure along with potential confounders on the right-hand side.The functional form of the outcome model should be, Outcome ~ Exposure + Confounders. (Exposure main effect must be first independent variable)

objectOut

A fitted model for the outcome model. The functional form of the fitted model for the outcome variable should be of form, Outcome ~ Exposure + Confounders.

formulaExp

An exposure model formula containing the binary exposure on the left-hand side and potential confounders on the right-hand side. The functional form of the exposure model is, Exposure ~ Confounders.

objectExp

A fitted model object for the exposure model.

data

The dataset on which simulations are based. The data is required only when formulaOut or formulaExp or both are supplied to the argument.

idVar

Name of the ID variable.

effectOR

The desired treatment effect odds ratio. By default effectOR = 1.

MMOut

A multiplier of confounder effects on outcome applied to the estimated log ORs in the outcome model. By default MMOut = 1 but one can specify a vector of length equivalent to the number of variables on the right-hand side of the outcome model.

MMExp

A multiplier of confounder effects on exposure applied to the estimated log ORs in the exposure model. By default MMExp = 1 but one can specify a vector of length equivalent to the number of variables on the right-hand side of the exposure model.

nsim

Number of desired simulated datasets.

size

Desired size of simulated datasets (i.e., # of individuals).

eventRate

Desired average event rate. Default is the event rate in the observed data.

exposedPrev

Desired average exposure rate. Default is the esposure prevalence in the observed data.

Details

At least one of formulaOut, formulaExp, objectOut, and objectExp must be specified, and which of these are specified will determine what gets simulated and how. If objectOut or objectExp are specified, these objects are used as the base model for outcome and exposure simulation. If formulaOut or formulaExp are specified, then data should be given and base models are fit in the data using glm2 with the given formulas. If formulaOut or objectOut is specified, outcome will be simulated based on subjects’ observed exposure. If formulaExp or objectExp is specified, exposure will be simulated. And if models are specified for both outcome and exposure, both variables will be simulated with simulated outcome dependent on the simulated exposure.

Value

PlasmodeBin returns true beta coefficients used to generate the outcome and the exposure. It also returns the relative risk and risk difference estimated by the plasmode simulated data along with the data frame with the simulated data, including sampled IDs for each of nsim datasets along with simulated outcomes, exposure, or both.

TrueOutBeta

True beta coefficients used to generate the outcome.

TrueExpBeta

True beta coefficients used to generate the exposure.

RR

True relative risk estimated using the plasmode simulated data.

RD

True risk difference estimated using the plasmode simulated data.

Sim_Data

Plasmode simulated data, including sampled IDs for each of nsim datasets along with simulated outcomes, exposure, or both.

Author(s)

Jessica M. Franklin, Younathan Abdia, and Shirley Wang

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
{
library(mgcv)
library(nlme)
library(glm2)
library(arm)
library(MASS)
library(lme4)
library(epiDisplay)
library(foreign)
library(nnet)

data("Compaq")
levels(Compaq$stage) <- c(1,2,3,4)
Compaq$stage<-as.numeric(levels(Compaq$stage))[Compaq$stage]
## Creating the binary exposure variable
Compaq$exposure<-ifelse(Compaq$hospital == "Public hospital",1,0)
## Creating binary variables for some confounders
Compaq$ses1<-ifelse(Compaq$ses == "Poor",1,0)
Compaq$ses2<-ifelse(Compaq$ses == "Poor-middle",1,0)
Compaq$ses3<-ifelse(Compaq$ses == "High-middle",1,0)

Compaq$age1<-ifelse(Compaq$agegr == "<40",1,0)
Compaq$age2<-ifelse(Compaq$agegr == "40-49",1,0)
Compaq$age3<-ifelse(Compaq$agegr == "50-59",1,0)


## Creating the formulas for the outcome and the exposure model
form1<- status~ exposure + stage + ses1 + ses2 + ses3 + age1 + age2 + age3
form2<- exposure ~ stage + ses1 + ses2 + ses3 + age1 + age2 + age3

set.seed(111)
Bin_Form1<-PlasmodeBin(formulaOut=form1, objectOut=NULL,formulaExp=form2,
                     objectExp= NULL,data=Compaq,idVar="id",effectOR =1,
                     MMOut=c(1,1,2,1,1,2,1,2),MMExp=c(1,1,1,1,1,1,1),
                     nsim=2, size=nrow(Compaq), eventRate=NULL, exposedPrev=NULL)

Bin_Form2<-PlasmodeBin(formulaOut=form1, objectOut=NULL,formulaExp=NULL,
                      objectExp= NULL,data=Compaq,idVar="id",effectOR =1,
                      MMOut=c(1,1,2,1,1,2,1,2),MMExp=1, nsim=2,
                      size=nrow(Compaq), eventRate=NULL, exposedPrev=NULL)

Bin_Form3<-PlasmodeBin(formulaOut=NULL, objectOut=NULL,formulaExp=form2,
                      objectExp= NULL,data=Compaq,idVar="id",effectOR =1,
                      MMOut=1,MMExp=c(1,1,1,1,1,1,1), nsim=2,
                      size=nrow(Compaq), eventRate=NULL, exposedPrev=NULL)


###################################################################################################
## One can provide the fitted model for the outcome model and the exposure model estimated by
## glm, gam, and bayesglm. The functional form of the fitted model for the outcome variable should
## of the form Outcome ~ Exposure + Confounders. The functional form of the exposure model is,
## Exposure ~ Confounders.
####################################################################################################

Coeff1<- bayesglm(form1, family = "binomial", data=Compaq,control=glm.control(trace=TRUE))
Coeff2<- bayesglm(form2, family = "binomial", data=Compaq,control=glm.control(trace=TRUE))
sizesim<-nrow(model.matrix(Coeff1))
sizesim1<-nrow(model.matrix(Coeff2))

Bin_Obj1<-PlasmodeBin(formulaOut=NULL, objectOut=Coeff1,formulaExp=NULL,
                     objectExp = Coeff2, idVar=Compaq$id,effectOR =1,
                     MMOut=c(1.5,1,2,1,1,1,1,1),MMExp=c(1,1,1,1,1,1,1),
                     nsim=2, size=sizesim, eventRate=NULL, exposedPrev=NULL)

Bin_Obj2<-PlasmodeBin(formulaOut=NULL, objectOut=Coeff1,formulaExp=NULL,
                     objectExp = NULL,idVar=Compaq$id,effectOR =1,
                     MMOut=c(1.5,1,2,1,1,1,1,1),MMExp=1,
                     nsim=2, size=sizesim, eventRate=NULL, exposedPrev=NULL)

Bin_Obj3<-PlasmodeBin(formulaOut=NULL, objectOut=NULL,formulaExp=NULL,
                     objectExp = Coeff2,idVar=Compaq$id,effectOR =1, MMOut=1,
                     MMExp=c(1,1,1,1,1,1,1),
                     nsim=2, size=sizesim1, eventRate=NULL, exposedPrev=NULL)
}

Example output

Loading required package: nlme
This is mgcv 1.8-33. For overview type 'help("mgcv-package")'.
Loading required package: MASS

Attaching package:MASSThe following object is masked frompackage:glm2:

    crabs

Loading required package: Matrix
Loading required package: lme4

Attaching package:lme4The following object is masked frompackage:nlme:

    lmList


arm (Version 1.11-2, built: 2020-7-27)

Working directory is /work/tmp

Loading required package: foreign
Loading required package: survival

Attaching package:survivalThe following object is masked frompackage:glm2:

    heart

Loading required package: nnet

Attaching package:nnetThe following object is masked frompackage:mgcv:

    multinom

Deviance = 1126.95 Iterations - 1 
Deviance = 1125.02 Iterations - 2 
Deviance = 1125.016 Iterations - 3 
Deviance = 1125.016 Iterations - 4 
Deviance = 1205.795 Iterations - 1 
Deviance = 1203.757 Iterations - 2 
Deviance = 1203.756 Iterations - 3 
Deviance = 1203.756 Iterations - 4 
Deviance = 1126.95 Iterations - 1 
Deviance = 1125.02 Iterations - 2 
Deviance = 1125.016 Iterations - 3 
Deviance = 1125.016 Iterations - 4 
Deviance = 1205.795 Iterations - 1 
Deviance = 1203.757 Iterations - 2 
Deviance = 1203.756 Iterations - 3 
Deviance = 1203.756 Iterations - 4 
Deviance = 1127.095 Iterations - 1
Deviance = 1125.099 Iterations - 2
Deviance = 1125.075 Iterations - 3
Deviance = 1125.074 Iterations - 4
Deviance = 1125.074 Iterations - 5
Deviance = 1205.852 Iterations - 1
Deviance = 1203.768 Iterations - 2
Deviance = 1203.768 Iterations - 3
Deviance = 1203.768 Iterations - 4

Plasmode documentation built on May 1, 2019, 7:55 p.m.