Usage
Here we will walk through some basic analyses from the point of view
of a new R user. Along the way we will highlight the main features of
pseval. pseval supports both binary
outcomes and time-to-event, thus we will also need to load the
survival package.
library(pseval)
library(survival)
First let’s create an example dataset. The package provides the
function generate_example_data
which takes a single
argument: the sample size.
set.seed(1492)
fakedata <- generate_example_data(n = 800)
head(fakedata)
0 |
0.3353179 |
1.4851399 |
0.4596161 |
0.3526810 |
0.3301972 |
0 |
0 |
(-0.198,0.503] |
(0.0574,0.766] |
0 |
1.4536863 |
2.6379400 |
1.3959104 |
1.4668891 |
0.1195136 |
1 |
0 |
(1.36, Inf] |
(0.766, Inf] |
0 |
-0.7243934 |
NA |
-0.6272350 |
-0.7319076 |
0.2631222 |
1 |
1 |
(-Inf,-0.198] |
(-Inf,-0.678] |
0 |
-0.1183592 |
0.9421504 |
0.0773831 |
-0.0183341 |
0.1373458 |
1 |
0 |
(-0.198,0.503] |
(-0.678,0.0574] |
0 |
-0.2352566 |
NA |
-0.1497145 |
-0.1847024 |
0.8543703 |
1 |
1 |
(-0.198,0.503] |
(-0.678,0.0574] |
0 |
-0.7782851 |
0.1159434 |
-0.6572161 |
-0.6631371 |
0.2200481 |
1 |
0 |
(-Inf,-0.198] |
(-Inf,-0.678] |
The example data includes both a time-to-event outcome, a binary
outcome, a surrogate, a BIP, CPV, and BSM, and a categorical version of
the surrogate. The true model for the time is exponential, with
parameters (intercept) = -1, S(1) = 0.0, Z = 0.0, S(1):Z = -0.75. The
true model for binary is logistic, with the same parameter values.
In the above table S.obs.cat and BIP.cat are formed as
S.obs.cat <- factor(S.obs,levels=c(-Inf, quantile(c(S.0, S.1), c(.25, .5, .75), na.rm = TRUE), Inf))
and similarly for BIP.cat. Alternatively a user could input arbitrary
numeric values to represent different discrete subgroups (e.g., 0s and
1s to denote 2 subgroups).
The "psdesign"
object
We begin by creating a "psdesign"
object with the
synonymous function. This is the object that combines the raw dataset
with information about the study design and the structure of the data.
Subsequent analysis will operate on this psdesign object. It is designed
to be analogous to the svydesign
function in the
survey package (https://CRAN.R-project.org/package=survey). The first
argument is the data frame where the data are stored. All subsequent
arguments describe the mappings from the variable names in the data
frame to important variables in the PS analysis, using the same notation
as above. An optional weights argument describes the sampling weights,
if present. Our first analysis will use the binary version of the
outcome, with continuous S.1
and the BIP labeled BIP. The object
has a print method, so we can inspect the result.
binary.ps <- psdesign(data = fakedata, Z = Z, Y = Y.obs, S = S.obs, BIP = BIP)
binary.ps
## Augmented data frame: 800 obs. by 6 variables.
## Z Y S.1 S.0 cdfweights BIP
## 1 0 0 NA 0.3527 1 0.335
## 2 0 0 NA 1.4669 1 1.454
## 3 0 1 NA -0.7319 1 -0.724
## 4 0 0 NA -0.0183 1 -0.118
## 5 0 1 NA -0.1847 1 -0.235
## 6 0 0 NA -0.6631 1 -0.778
##
## Empirical TE: 0.526
##
## Mapped variables:
## Z -> Z
## Y -> Y.obs
## S -> S.obs
## BIP -> BIP
##
## Integration models:
## None present, see ?add_integration for information on integration models.
##
## Risk models:
## None present, see ?add_riskmodel for information on risk models.
## No estimates present, see ?ps_estimate.
## No bootstraps present, see ?ps_bootstrap.
The printout displays a brief description of the data, including the
empirical treatment efficacy estimate, the variables used in the
analysis and their corresponding variables in the original dataset.
Finally the printout invites the user to see the help page for
add_integration
, in order to add an integration model to
the psdesign object, the next step in the analysis.
Missing values in the S
variable are allowed. Note that any cases where S(1) is missing will be integrated
over in the likelihood or score equations. Thus any cases that
experienced an event prior to the time τ when the surrogate was measured
should be excluded from the dataset. The equal individual risk
assumption allows us to make causal inferences even after excluding such
cases.
psdesign
easily accommodates case-control or case-cohort
sampling. In this case, the surrogate S is only measured on a subset of
the data, inducing missingness in S by design. Let’s modify the fake
dataset to see how it works. We’re going to sample all of the cases, and
20% of the controls for measurement of S.
fakedata.cc <- fakedata
missdex <- sample((1:nrow(fakedata.cc))[fakedata.cc$Y.obs == 0],
size = floor(sum(fakedata.cc$Y.obs == 0) * .8))
fakedata.cc[missdex, ]$S.obs <- NA
fakedata.cc$weights <- ifelse(fakedata.cc$Y.obs == 1, 1, .2)
Now we can create the "psdesign"
object, using the
entire dataset (including those missing S.obs
) and passing
the weights to the weights
field.
binary.cc <- psdesign(data = fakedata.cc, Z = Z, Y = Y.obs, S = S.obs,
BIP = BIP, weights = weights)
The other augmentation types can be defined by mapping variables to
the names BIP
, CPV
, and/or BSM
.
The augmentations are handled as described in the previous section: CPV
is used as a direct imputation for S(1), and BSM is used as a direct
imputation for S(0). BIPs and
BSMs are made available in the augmented dataset for use in the
integration models which we describe in the next subsection.
For survival outcomes, a key assumption is that the potential
surrogate is measured at a fixed time τ after entry into the study. Any
subjects who have a clinical outcome prior to τ will be removed from the analysis,
with a warning. If tau
is not specified in the
psdesign
object, then it is assumed to be 0. Survival
outcomes are specified by mapping Y
to a Surv
object, which requires the survival package:
surv.ps <- psdesign(data = fakedata, Z = Z, Y = Surv(time.obs, event.obs), S = S.obs,
BIP = BIP, CPV = CPV, BSM = BSM)
## Warning in psdesign(data = fakedata, Z = Z, Y = Surv(time.obs, event.obs), :
## tau missing in psdesign: assuming that the surrogate S was measured at time 0.
Integration models
The EML procedure requires an estimate of FS(1)|W,
and we refer to this as the integration model. Details are available in
the help page for add_integration
, shown below. Several
integration models are implemented, including a parametric model that
uses a formula interface to define a regression model, a semiparametric
model that specifies a location and a scale model is robust to the
specification of the distribution, and a non-parametric model that uses
empirical conditional probability estimates for discrete W and S(1).
add_integration | R Documentation |
Integration models
Description
Add integration model to a psdesign object
Usage
add_integration(psdesign, integration)
Arguments
psdesign |
A psdesign object
|
integration |
An integration object
|
Details
This is a list of the available integration models. The fundamental problem in surrogate evaluation is that there are unobserved values of the counterfactual surrogate responses S(1). In the estimated maximum likelihood framework, for subjects missing the S(1) values, we use an auxiliary pre-treatment variable or set of variables W that is observed for every subject to estimate the distribution of S(1) | W. Typically, this W is a BIP. Then for each missing S(1), we integrate likelihood contributions over each non-missing S(1) given their value of W, and average over the contributions.
-
integrate_parametric This is a parametric integration model that fits a linear model for the mean of S(1) | W and assumes a Gaussian distribution.
-
integrate_bivnorm This is another parametric integration model that assumes that S(1) and W are jointly normally distributed. The user must specify their mean, variances and correlation.
-
integrate_nonparametric This is a non-parametric integration model that is only valid for categorical S(1) and W. It uses the observed proportions to estimate the joint distribution of S(1), W.
-
integrate_semiparametric This is a semi-parametric model that uses the semi-parametric location scale model of Heagerty and Pepe (1999). Models are specified for the location of S(1) | W and the scale of S(1) | W. Then integrations are drawn from the empirical distribution of the residuals from that model, which are then transformed to the appropriate location and scale.
Examples
test <- psdesign(generate_example_data(n = 100), Z = Z, Y = Y.obs, S = S.obs, BIP = BIP)
add_integration(test, integrate_parametric(S.1 ~ BIP))
test + integrate_parametric(S.1 ~ BIP) # same as above
For this first example, let’s use the parametric integration model.
We specify the mean model for S(1)|W as a formula. The
predictor is generally a function of the BIP and the BSM, if available.
We can add the integration model directly to the psdesign object and
inspect the results. Note that in the formula, we refer to the variable
names in the augmented dataset.
binary.ps <- binary.ps + integrate_parametric(S.1 ~ BIP)
binary.ps
## Augmented data frame: 800 obs. by 6 variables.
## Z Y S.1 S.0 cdfweights BIP
## 1 0 0 NA 0.3527 1 0.335
## 2 0 0 NA 1.4669 1 1.454
## 3 0 1 NA -0.7319 1 -0.724
## 4 0 0 NA -0.0183 1 -0.118
## 5 0 1 NA -0.1847 1 -0.235
## 6 0 0 NA -0.6631 1 -0.778
##
## Empirical TE: 0.526
##
## Mapped variables:
## Z -> Z
## Y -> Y.obs
## S -> S.obs
## BIP -> BIP
##
## Integration models:
## integration model for S.1 :
## integrate_parametric(formula = S.1 ~ BIP )
##
## Risk models:
## None present, see ?add_riskmodel for information on risk models.
## No estimates present, see ?ps_estimate.
## No bootstraps present, see ?ps_bootstrap.
We can add multiple integration models to a psdesign object, say we
want a model for S(0)|W:
binary.ps + integrate_parametric(S.0 ~ BIP)
## Augmented data frame: 800 obs. by 6 variables.
## Z Y S.1 S.0 cdfweights BIP
## 1 0 0 NA 0.3527 1 0.335
## 2 0 0 NA 1.4669 1 1.454
## 3 0 1 NA -0.7319 1 -0.724
## 4 0 0 NA -0.0183 1 -0.118
## 5 0 1 NA -0.1847 1 -0.235
## 6 0 0 NA -0.6631 1 -0.778
##
## Empirical TE: 0.526
##
## Mapped variables:
## Z -> Z
## Y -> Y.obs
## S -> S.obs
## BIP -> BIP
##
## Integration models:
## integration model for S.1 :
## integrate_parametric(formula = S.1 ~ BIP )
## integration model for S.0 :
## integrate_parametric(formula = S.0 ~ BIP )
##
## Risk models:
## None present, see ?add_riskmodel for information on risk models.
## No estimates present, see ?ps_estimate.
## No bootstraps present, see ?ps_bootstrap.
In a future version of the package, we will allow for estimation of
the joint risk estimands that depend on both S(0) and S(1). We can also use splines, other
transformations, and other variables in the formula:
library(splines)
binary.ps + integrate_parametric(S.1 ~ BIP^2)
binary.ps + integrate_parametric(S.1 ~ bs(BIP, df = 3))
binary.ps + integrate_parametric(S.1 ~ BIP + BSM + BSM^2)
These are shown as examples, we will proceed with the simple linear
model for integration. The other integration models are called
integrate_bivnorm
, integrate_nonparametric
,
and integrate_semiparametric
. See their help files for
details on the models and their specification.
The next step is to define the risk model. We will proceed with the
simple parametric integration model.
Risk models and likelihoods
The risk model is the specification of the distribution for the
outcome Y given S(1) and Z. We accommodate a variety of
flexible specifications for this model, for binary, time-to-event, and
count outcomes. We have implemented exponential and weibull survival
models, and a flexible specification for binary models, allowing for
standard or custom link functions. See the help file for
add_riskmodel
for more details.
add_riskmodel | R Documentation |
Add risk model to a psdesign object
Description
Add risk model to a psdesign object
Usage
add_riskmodel(psdesign, riskmodel)
Arguments
psdesign |
A psdesign object
|
riskmodel |
A risk model object, from the list above
|
Details
The risk model component specifies the likelihood for the data. This involves specifying the distribution of the outcome variable, whether it is binary or time-to-event, and specifying how the surrogate S(1) and the treatment Z interact and affect the outcome. We use the formula notation to be consistent with other regression type models in R. Below is a list of available risk models.
-
risk_binary This is a generic risk model for binary outcomes. The user can specify the formula, and link function using either risk.logit for the logistic link, or risk.probit for the probit link. Custom link functions may also be specified, which take a single numeric vector argument, and returns a vector of corresponding probabilities.
-
risk_weibull This is a parameterization of the Weibull model for time-to-event outcomes that is consistent with that of rweibull. The user specifies the formula for the linear predictor of the scale parameter.
-
risk_exponential This is a simple exponential model for a time-to-event outcome.
-
risk_poisson This is a Poisson model for count outcomes. It allows for offsets in the formula.
-
risk_continuous This is a Gaussian model for continuous outcomes. It assumes that larger values of the outcome are harmful (e.g. blood pressure)
Examples
test <- psdesign(generate_example_data(n = 100), Z = Z, Y = Y.obs, S = S.obs, BIP = BIP) +
integrate_parametric(S.1 ~ BIP)
add_riskmodel(test, risk_binary())
test + risk_binary() # same as above
Let’s add a simple binary risk model using the logit link. The
argument D
specifies the number of samples to use for the
simulated annealing, also known as empirical integration, in the EML
procedure. In general, D should be set to something reasonably large,
like 2 or 3 times the sample size.
binary.ps <- binary.ps + risk_binary(model = Y ~ S.1 * Z, D = 5, risk = risk.logit)
binary.ps
## Augmented data frame: 800 obs. by 6 variables.
## Z Y S.1 S.0 cdfweights BIP
## 1 0 0 NA 0.3527 1 0.335
## 2 0 0 NA 1.4669 1 1.454
## 3 0 1 NA -0.7319 1 -0.724
## 4 0 0 NA -0.0183 1 -0.118
## 5 0 1 NA -0.1847 1 -0.235
## 6 0 0 NA -0.6631 1 -0.778
##
## Empirical TE: 0.526
##
## Mapped variables:
## Z -> Z
## Y -> Y.obs
## S -> S.obs
## BIP -> BIP
##
## Integration models:
## integration model for S.1 :
## integrate_parametric(formula = S.1 ~ BIP )
##
## Risk models:
## risk_binary(model = Y ~ S.1 * Z, D = 5, risk = risk.logit )
##
## No estimates present, see ?ps_estimate.
## No bootstraps present, see ?ps_bootstrap.
Estimation and Bootstrap
We estimate the parameters and bootstrap using the same type of
syntax. We can add a "ps_estimate"
object, which takes
optional arguments start
for starting values, and other
arguments that are passed to the optim
function. The
method
argument determines the optimization method, we have
found that “BFGS” works well in these types of problems and it is the
default. Use "pseudo-score"
as the method
argument for pseudo-score estimation for binary risk models with
categorical BIPs.
The ps_bootstrap
function takes the additional arguments
n.boots
for the number of bootstrap replicates, and
progress.bar
which is a logical that displays a progress
bar in the R console if true. It is helpful to pass the estimates as
starting values in the bootstrap resampling. With estimates and
bootstrap replicates present, printing the psdesign object displays
additional information. In real examples you should use more than 10
bootstrap replicates.
binary.est <- binary.ps + ps_estimate(method = "BFGS")
binary.boot <- binary.est + ps_bootstrap(n.boots = 10, progress.bar = FALSE,
start = binary.est$estimates$par, method = "BFGS")
binary.boot
## Augmented data frame: 800 obs. by 6 variables.
## Z Y S.1 S.0 cdfweights BIP
## 1 0 0 NA 0.3527 1 0.335
## 2 0 0 NA 1.4669 1 1.454
## 3 0 1 NA -0.7319 1 -0.724
## 4 0 0 NA -0.0183 1 -0.118
## 5 0 1 NA -0.1847 1 -0.235
## 6 0 0 NA -0.6631 1 -0.778
##
## Empirical TE: 0.526
##
## Mapped variables:
## Z -> Z
## Y -> Y.obs
## S -> S.obs
## BIP -> BIP
##
## Integration models:
## integration model for S.1 :
## integrate_parametric(formula = S.1 ~ BIP )
##
## Risk models:
## risk_binary(model = Y ~ S.1 * Z, D = 5, risk = risk.logit )
##
## Estimated parameters:
## (Intercept) S.1 Z S.1:Z
## -0.919 -0.028 -0.221 -1.133
## Convergence: TRUE
##
## Bootstrap replicates:
## Estimate boot.se lower.CL.2.5. upper.CL.97.5. p.value
## (Intercept) -0.919 0.131 -1.286 -0.884 2.69e-12
## S.1 -0.028 0.142 -0.130 0.306 8.44e-01
## Z -0.221 0.152 -0.269 0.195 1.46e-01
## S.1:Z -1.133 0.272 -1.668 -0.870 3.12e-05
##
## Out of 10 bootstraps, 10 converged ( 100 %)
##
## Test for wide effect modification on 1 degree of freedom. 2-sided p value < .0001
Do it all at once
The next code chunk shows how the model can be defined and estimated
all at once.
binary.est <- psdesign(data = fakedata, Z = Z, Y = Y.obs, S = S.obs, BIP = BIP) +
integrate_parametric(S.1 ~ BIP) +
risk_binary(model = Y ~ S.1 * Z, D = 50, risk = risk.logit) +
ps_estimate(method = "BFGS")
Plots and summaries
We provide summary and plotting methods for the psdesign object. If
bootstrap replicates are present, the summary method does a test for
wide effect modification. Under the parametric risk models implemented
in this package, the test for wide effect modification is equivalent to
a test that the S(1) : Z coefficient is
different from 0. This is implemented using a Wald test using the
bootstrap estimate of the variance.
Another way to assess wide effect modification is to compute the
standardized total gain (STG) (Erin E. Gabriel,
Sachs, and Gilbert 2015). This is implemented in the
calc_STG
function. The standardized total gain can be
interpreted as the area sandwiched between the risk difference curve and
the horizontal line at the marginal risk difference. It is a measure of
the spread of the distribution of the risk difference, and is a less
parametric way to test for wide effect modification. The
calc_STG
function computes the STG at the estimated
parameters, at the bootstrap samples, if present. The function prints
the results and invisibly returns a list containing the observed STG,
and the bootstrapped STGS.
calc_STG(binary.boot, progress.bar = FALSE)
The summary method also computes the marginal treatment efficacy
marginalized over S(1) and
compares it to the average treatment efficacy conditional on S(1). This is an assessment of model
fit. A warning will be given if the two estimates are dramatically
different. These estimates are presented in the summary along with the
empirical marginal treatment efficacy.
smary <- summary(binary.boot)
## Augmented data frame: 800 obs. by 6 variables.
## Z Y S.1 S.0 cdfweights BIP
## 1 0 0 NA 0.3527 1 0.335
## 2 0 0 NA 1.4669 1 1.454
## 3 0 1 NA -0.7319 1 -0.724
## 4 0 0 NA -0.0183 1 -0.118
## 5 0 1 NA -0.1847 1 -0.235
## 6 0 0 NA -0.6631 1 -0.778
##
## Empirical TE: 0.526
##
## Mapped variables:
## Z -> Z
## Y -> Y.obs
## S -> S.obs
## BIP -> BIP
##
## Integration models:
## integration model for S.1 :
## integrate_parametric(formula = S.1 ~ BIP )
##
## Risk models:
## risk_binary(model = Y ~ S.1 * Z, D = 5, risk = risk.logit )
##
## Estimated parameters:
## (Intercept) S.1 Z S.1:Z
## -0.919 -0.028 -0.221 -1.133
## Convergence: TRUE
##
## Bootstrap replicates:
## Estimate boot.se lower.CL.2.5. upper.CL.97.5. p.value
## (Intercept) -0.919 0.131 -1.286 -0.884 2.69e-12
## S.1 -0.028 0.142 -0.130 0.306 8.44e-01
## Z -0.221 0.152 -0.269 0.195 1.46e-01
## S.1:Z -1.133 0.272 -1.668 -0.870 3.12e-05
##
## Out of 10 bootstraps, 10 converged ( 100 %)
##
## Test for wide effect modification on 1 degree of freedom. 2-sided p value < .0001
##
## Treatment Efficacy:
## empirical marginal model
## 0.526 0.526 0.534
## Model-based average TE is 1.6 % different from the empirical and 1.6 % different from the marginal.
The calc_risk
function computes the risk in each
treatment arm, and contrasts of the risks. By default it computes the
treatment efficacy, but there are other contrast functions available.
The contrast function is a function that takes 2 inputs, the risk0
and risk1,
and returns some one dimensional function of those two inputs. It must
be vectorized. Some built-in functions are “TE” for treatment efficacy
= 1 − risk1(s)/risk0(s),
“RR” for relative risk = risk1(s)/risk0(s),
“logRR” for log of the relative risk, and “RD” for the risk difference
= risk1(s) − risk0(s).
You can pass the name of the function, or the function itself to
calc_risk
. See ?calc_risk
for more information
about contrast functions.
Other arguments of the calc_risk
function include
t
, the time at which to calculate the risk for
time-to-event outcomes, n.samps
which is the number of
samples over the range of S.1 at which the risk will be calculated, and
CI.type
, which can be set to "pointwise"
for
pointwise confidence intervals or "band"
for a simultaneous
confidence band. sig.level
is the significance level for
the bootstrap confidence intervals. If the outcome is time-to-event and
t is not present, then it will
use the restricted mean survival time.
head(calc_risk(binary.boot, contrast = "TE", n.samps = 20), 3)
V1 |
-0.8567331 |
-0.5987036 |
0.2900268 |
0.4636670 |
0.4790395 |
-0.3980377 |
-1.2642732 |
0.0424780 |
0.3022725 |
0.2185511 |
0.0680346 |
0.4997864 |
0.4078591 |
V2 |
-0.3768993 |
-0.1531511 |
0.2872703 |
0.3312661 |
0.2398953 |
-0.0526225 |
-0.5642967 |
0.0323329 |
0.2976192 |
0.2288122 |
0.0405746 |
0.3598227 |
0.2986408 |
V3 |
-0.3768993 |
-0.1531511 |
0.2872703 |
0.3312661 |
0.2398953 |
-0.0526225 |
-0.5642967 |
0.0323329 |
0.2976192 |
0.2288122 |
0.0405746 |
0.3598227 |
0.2986408 |
head(calc_risk(binary.boot, contrast = function(R0, R1) 1 - R1/R0, n.samps = 20), 3)
V1 |
-0.2907799 |
-0.0792698 |
0.2867772 |
0.3095100 |
0.2058057 |
0.0050699 |
-0.4378068 |
0.0305413 |
0.2967884 |
0.2306893 |
0.0353754 |
0.3382743 |
0.2808802 |
V2 |
-0.0136424 |
0.1400180 |
0.2851939 |
0.2452617 |
0.1164425 |
0.1784430 |
-0.0585296 |
0.0249749 |
0.2941240 |
0.2368027 |
0.0206818 |
0.2736347 |
0.2272614 |
V3 |
0.0660364 |
0.1973375 |
0.2847397 |
0.2285499 |
0.0969680 |
0.2245060 |
0.0394667 |
0.0234684 |
0.2933606 |
0.2385809 |
0.0174160 |
0.2565410 |
0.2119097 |
It is easy to plot the risk estimates. By default, the plot method
displays the TE contrast, but this can be changed using the same syntax
as in calc_risk
.
plot(binary.boot, contrast = "TE", lwd = 2)
abline(h = smary$TE.estimates[2], lty = 3)
expit <- function(x) exp(x)/(1 + exp(x))
trueTE <- function(s){
r0 <- expit(-1 - 0 * s)
r1 <- expit(-1 - .75 * s)
1 - r1/r0
}
rug(binary.boot$augdata$S.1)
## Warning in rug(binary.boot$augdata$S.1): some values will be clipped
curve(trueTE(x), add = TRUE, col = "red")
legend("bottomright", legend = c("estimated TE", "95\\% CB", "marginal TE", "true TE"),
col = c("black", "black", "black", "red"), lty = c(1, 2, 3, 1), lwd = c(2, 2, 1, 1))
By default, plots of psdesign objects with bootstrap samples will
display simultaneous confidence bands for the curve. These bands Lα satisfy
$$
P\left\{\sup_{s \in B} | \hat{VE}(s) - VE(s) | \leq L_\alpha \right\}
\leq 1 - \alpha,
$$
for confidence level α. The
alternative is to use pointwise confidence intervals, with the option
CI.type = "pointwise"
. These intervals satisfy
P{L̂α ≤ VE(s) ≤ Ûα} ≤ 1 − α,
for all s.
Different summary measures are available for plotting. The options
are “TE” for treatment efficacy = 1 − risk1(s)/risk0(s),
“RR” for relative risk = risk1(s)/risk0(s),
“logRR” for log of the relative risk, “risk” for the risk in each
treatment arm, and “RD” for the risk difference = risk1(s) − risk0(s).
We can also transform using the log
option of
plot
.
plot(binary.boot, contrast = "logRR", lwd = 2, col = c("black", "grey75", "grey75"))
plot(binary.boot, contrast = "RR", log = "y", lwd = 2, col = c("black", "grey75", "grey75"))
plot(binary.boot, contrast = "RD", lwd = 2, col = c("black", "grey75", "grey75"))
plot(binary.boot, contrast = "risk", lwd = 2, lty = c(1, 0, 0, 2, 0, 0))
legend("topright", legend = c("R0", "R1"), lty = c(1, 2), lwd = 2)
The calc_risk
function is the workhorse that creates the
plots. You can call this function directly to obtain estimates, standard
errors, and confidence intervals for the estimated risk in each
treatment arm and transformations of the risk like TE. The parameter
n.samps
determines the number of points at which to
calculate the risk. The points are evenly spaced over the range of S.1.
Use this function to compute other summaries, make plots using
ggplot2 or lattice and more.
te.est <- calc_risk(binary.boot, CI.type = "pointwise", n.samps = 200)
head(te.est, 3)
V1 |
-2.275699 |
-1.741665 |
0.2982692 |
0.8177541 |
1.647418 |
-6.113559 |
-1.341239 |
0.0714416 |
0.1249966 |
0.3230252 |
0.0648381 |
0.7425365 |
0.9315855 |
V2 |
-2.275699 |
-1.741665 |
0.2982692 |
0.8177541 |
1.647418 |
-6.113559 |
-1.341239 |
0.0714416 |
0.1249966 |
0.3230252 |
0.0648381 |
0.7425365 |
0.9315855 |
V3 |
-2.275699 |
-1.741665 |
0.2982692 |
0.8177541 |
1.647418 |
-6.113559 |
-1.341239 |
0.0714416 |
0.1249966 |
0.3230252 |
0.0648381 |
0.7425365 |
0.9315855 |