Description Usage Arguments Details Value References See Also Examples
View source: R/coxsimInteract.R
coxsimInteract
simulates quantities of interest for linear
multiplicative interactions using multivariate normal distributions.
These can be plotted with simGG
.
1 2 3 
obj 
a 
b1 
character string of the first constitutive variable's name.
Note 
b2 
character string of the second constitutive variable's name. 
qi 
quantity of interest to simulate. Values can be

X1 
numeric vector of fitted values of 
X2 
numeric vector of fitted values of 
means 
logical, whether or not to use the mean values to fit the
hazard rate for covaraiates other than 
expMarg 
logical. Whether or not to exponentiate the marginal effect. 
nsim 
the number of simulations to run per value of X. Default is

ci 
the proportion of middle simulations to keep. The default is

spin 
logical, whether or not to keep only the shortest probability interval rather than the middle simulations. Currently not supported for hazard rates. 
extremesDrop 
logical whether or not to drop simulated quantity of
interest values that are 
Simulates marginal effects, first differences, hazard ratios, and
hazard rates for linear multiplicative interactions.
Marginal effects are calculated as in Brambor et al. (2006) with the
addition that we take the exponent, so that it resembles a hazard ratio.
You can choose not to take the exponent by setting the argument
expMarg = FALSE
. For an interaction between variables X and
Z the marginal effect for X is:
ME[X] = exp(β[X] + β[XZ]Z)
Note that for First Differences the comparison is not between two values of the same variable but two values of the constitute variable and 0 for the two variables.
a siminteract
class object
Gandrud, Christopher. 2015. simPH: An R Package for Illustrating Estimates from Cox Proportional Hazard Models Including for Interactive and Nonlinear Effects. Journal of Statistical Software. 65(3)120.
Brambor, Thomas, William Roberts Clark, and Matt Golder. 2006. ”Understanding Interaction Models: Improving Empirical Analyses.” Political Analysis 14(1): 6382.
King, Gary, Michael Tomz, and Jason Wittenberg. 2000. ”Making the Most of Statistical Analyses: Improving Interpretation and Presentation.” American Journal of Political Science 44(2): 34761.
Liu, Ying, Andrew Gelman, and Tian Zheng. 2013. ”SimulationEfficient Shortest Probability Intervals.” Arvix. http://arxiv.org/pdf/1302.2142v1.pdf.
simGG
, survival
, strata
,
and coxph
,
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  # Load Carpenter (2002) data
data("CarpenterFdaData")
# Load survival package
library(survival)
# Run basic model
M1 < coxph(Surv(acttime, censor) ~ lethal*prevgenx,
data = CarpenterFdaData)
# Simulate Marginal Effect of lethal for multiple
# values of prevgenx
Sim1 < coxsimInteract(M1, b1 = "lethal", b2 = "prevgenx",
X2 = seq(2, 115, by = 5), spin = TRUE)
## Not run:
# Change the order of the covariates to make a more easily
# interpretable relative hazard graph.
M2 < coxph(Surv(acttime, censor) ~ prevgenx*lethal +
orphdum, data = CarpenterFdaData)
# Simulate Hazard Ratio of lethal for multiple
# values of prevgenx
Sim2 < coxsimInteract(M2, b1 = "prevgenx", b2 = "lethal",
X1 = seq(2, 115, by = 2),
X2 = c(0, 1),
qi = "Hazard Ratio", ci = 0.9)
# Simulate First Difference
Sim3 < coxsimInteract(M2, b1 = "prevgenx", b2 = "lethal",
X1 = seq(2, 115, by = 2),
X2 = c(0, 1),
qi = "First Difference", spin = TRUE)
# Simulate Hazard Rate
Sim4 < coxsimInteract(M2, b1 = "prevgenx", b2 = "lethal",
X1 = 90, X2 = 1, qi = "Hazard Rate",
means = TRUE)
## End(Not run)
# Example with a categorical variable
# Download data
data(hmohiv)
# Create category lables
hmohiv$drug < factor(hmohiv$drug, labels = c('not treated', 'treated'))
M3 < coxph(Surv(time,censor) ~ drug*age, data = hmohiv)
# Note: Use relevant coefficient name as shown in model summary, e.g.
# 'drugtreated'.
Sim5 < coxsimInteract(M3, b1 = "drugtreated", b2 = 'age', X2 = 20:54)

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
Please suggest features or report bugs in the GitHub issue tracker.
All documentation is copyright its authors; we didn't write any of that.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.