Title: | Calculate Estimates in Models with Interaction |
---|---|
Description: | A tool to calculate and plot estimates from models in which an interaction between the main predictor and a continuous covariate has been specified. Methods used in the package refer to Harrell Jr FE (2015, ISBN:9783319330396); Durrleman S, Simon R. (1989) <doi:10.1002/sim.4780080504>; Greenland S. (1995) <doi:10.1097/00001648-199507000-00005>. |
Authors: | Giorgio Melloni [aut, cre] |
Maintainer: | Giorgio Melloni <[email protected]> |
License: | GPL-3 |
Version: | 0.1.1 |
Built: | 2025-02-11 05:13:29 UTC |
Source: | https://github.com/gmelloni/interactionrcs |
This function is a dispatcher that generate OR, HR or linear estimates values for a simple or restricted cubic spline interaction model from a logistic, Cox or linear regression
intEST( var2values, model, data, var1, var2, ci = TRUE, conf = 0.95, ci.method = "delta", ci.boot.method = "perc", R = 100, parallel = "multicore", ... )
intEST( var2values, model, data, var1, var2, ci = TRUE, conf = 0.95, ci.method = "delta", ci.boot.method = "perc", R = 100, parallel = "multicore", ... )
var2values |
numeric vector of var2 points to estimate |
model |
model of class cph, coxph, lrm, glm or Glm. If data is NULL, the function expects to find the data in model$x. |
data |
data used in the model. If absent, we will attempt to recover the data from the model. Only used for bootstrap and glm class models |
var1 |
variable that increases by 1 unit from 0 |
var2 |
variable to spline. var2values belong to var2 |
ci |
calculate 95% CI? |
conf |
confidence level. Default 0.95 |
ci.method |
confidence interval method. "delta" performs delta method. "bootstrap" performs bootstrapped CI (slower) |
ci.boot.method |
one of the available bootstrap CI methods from |
R |
number of bootstrap samples if ci.method = "bootstrap". Default 100 |
parallel |
can take values "no", "multicore", "snow" if ci.method = "bootstrap". Default multicore |
... |
other parameters for boot |
if ci = FALSE, a dataframe with initial values and OR/HR/linear estimates , if ci = TRUE a dataframe with 5 columns, initial values, OR/HR/linear estimates, lower CI, upper CI and SE
library(rms) library(mlbench) data(PimaIndiansDiabetes) # Set age on a 5-year scale PimaIndiansDiabetes$age <- PimaIndiansDiabetes$age/5 # Recode diabetes as 0/1 PimaIndiansDiabetes$diabetes <- ifelse(PimaIndiansDiabetes$diabetes=="pos" , 1 , 0) # Logistic model predicting diabetes over BMI, age and glucose myformula <- diabetes ~ mass + age * rcs( glucose , 3 ) model <- lrm(myformula , data = PimaIndiansDiabetes ) intEST( var2values = 20:80 , model = model , data = PimaIndiansDiabetes , var1 ="age", var2="glucose" , ci=TRUE , conf = 0.95 , ci.method = "delta") # Linear model predicting BMI over diabetes, age and glucose myformula2 <- mass ~ diabetes + age * rcs( glucose , 3 ) model2 <- glm(myformula2 , data = PimaIndiansDiabetes , family = "gaussian") intEST( var2values = 20:80 , model = model2 , data = PimaIndiansDiabetes , var1 ="age", var2="glucose" , ci=TRUE , conf = 0.95 , ci.method = "delta")
library(rms) library(mlbench) data(PimaIndiansDiabetes) # Set age on a 5-year scale PimaIndiansDiabetes$age <- PimaIndiansDiabetes$age/5 # Recode diabetes as 0/1 PimaIndiansDiabetes$diabetes <- ifelse(PimaIndiansDiabetes$diabetes=="pos" , 1 , 0) # Logistic model predicting diabetes over BMI, age and glucose myformula <- diabetes ~ mass + age * rcs( glucose , 3 ) model <- lrm(myformula , data = PimaIndiansDiabetes ) intEST( var2values = 20:80 , model = model , data = PimaIndiansDiabetes , var1 ="age", var2="glucose" , ci=TRUE , conf = 0.95 , ci.method = "delta") # Linear model predicting BMI over diabetes, age and glucose myformula2 <- mass ~ diabetes + age * rcs( glucose , 3 ) model2 <- glm(myformula2 , data = PimaIndiansDiabetes , family = "gaussian") intEST( var2values = 20:80 , model = model2 , data = PimaIndiansDiabetes , var1 ="age", var2="glucose" , ci=TRUE , conf = 0.95 , ci.method = "delta")
Generate linear estimates for a 1 unit increase in a variable at specified points of another interacting variable in a linear interaction model
linLIN( var2values, model, data, var1, var2, ci = TRUE, conf = 0.95, ci.method = "delta", ci.boot.method = "perc", R = 100, parallel = "multicore", ... )
linLIN( var2values, model, data, var1, var2, ci = TRUE, conf = 0.95, ci.method = "delta", ci.boot.method = "perc", R = 100, parallel = "multicore", ... )
var2values |
numeric vector of var2 points to estimate |
model |
model of class rms::Glm or stats::glm family gaussian. If data is NULL, the function expects to find the data in model$x |
data |
data used in the model. If absent, it will attempt to recover the data from the model object. Only used for bootstrap CI |
var1 |
variable that increases by 1 unit from 0 |
var2 |
variable to spline. var2values belong to var2 |
ci |
calculate 95% CI? |
conf |
confidence level. Default 0.95 |
ci.method |
confidence interval method. "delta" performs delta method. "bootstrap" performs bootstrapped CI (slower) |
ci.boot.method |
one of the available bootstrap CI methods from |
R |
number of bootstrap samples if ci.method = "bootstrap". Default 100 |
parallel |
can take values "no", "multicore", "snow" if ci.method = "bootstrap". Default multicore |
... |
other parameters for boot |
if ci = FALSE, a vector of estimate of length(var2values), if ci = TRUE a dataframe with 5 columns, initial values, linear estimates, lower CI, upper CI and SE
library(rms) library(mlbench) data(PimaIndiansDiabetes) # Recode diabetes as 0/1 PimaIndiansDiabetes$diabetes <- ifelse(PimaIndiansDiabetes$diabetes=="pos" , 1 , 0) myformula <- glucose ~ mass + diabetes * age model <- glm(myformula , data = PimaIndiansDiabetes ,family=gaussian) # Show the effect on glucose of being diabetic at age 20 to 80 linLIN( var2values = 20:80 , model = model , data = PimaIndiansDiabetes , var1 ="diabetes", var2="age" , ci=TRUE , conf = 0.95 , ci.method = "delta")
library(rms) library(mlbench) data(PimaIndiansDiabetes) # Recode diabetes as 0/1 PimaIndiansDiabetes$diabetes <- ifelse(PimaIndiansDiabetes$diabetes=="pos" , 1 , 0) myformula <- glucose ~ mass + diabetes * age model <- glm(myformula , data = PimaIndiansDiabetes ,family=gaussian) # Show the effect on glucose of being diabetic at age 20 to 80 linLIN( var2values = 20:80 , model = model , data = PimaIndiansDiabetes , var1 ="diabetes", var2="age" , ci=TRUE , conf = 0.95 , ci.method = "delta")
Generate HR values for a 1 unit increase in a variable at specified points of another interacting variable in a simple Cox interaction model
loglinHR( var2values, model, data, var1, var2, ci = TRUE, conf = 0.95, ci.method = "delta", ci.boot.method = "perc", R = 100, parallel = "multicore", ... )
loglinHR( var2values, model, data, var1, var2, ci = TRUE, conf = 0.95, ci.method = "delta", ci.boot.method = "perc", R = 100, parallel = "multicore", ... )
var2values |
numeric vector of var2 points to estimate |
model |
model of class coxph or cph. If data is NULL, the function expects to find the data in model$x |
data |
data used in the model. If absent, it will attempt to recover the data from the model object. Only used for bootstrap CI |
var1 |
variable that increases by 1 unit from 0 |
var2 |
variable to spline. var2values belong to var2 |
ci |
calculate 95% CI? |
conf |
confidence level. Default 0.95 |
ci.method |
confidence interval method. "delta" performs delta method. "bootstrap" performs bootstrapped CI (slower) |
ci.boot.method |
one of the available bootstrap CI methods from |
R |
number of bootstrap samples if ci.method = "bootstrap". Default 100 |
parallel |
can take values "no", "multicore", "snow" if ci.method = "bootstrap". Default multicore |
... |
other parameters for boot |
if ci = FALSE, a vector of estimate of length(var2values), if ci = TRUE a dataframe with 5 columns, initial values, HR, lower CI, upper CI and SE
library(survival) data(cancer) myformula <- Surv(time, status) ~ ph.karno + ph.ecog + age*sex model <- coxph(myformula , data = lung ) loglinHR( var2values = 40:80 , model = model , data = lung , var1 ="sex", var2="age" , ci=TRUE , conf = 0.95 , ci.method = "delta")
library(survival) data(cancer) myformula <- Surv(time, status) ~ ph.karno + ph.ecog + age*sex model <- coxph(myformula , data = lung ) loglinHR( var2values = 40:80 , model = model , data = lung , var1 ="sex", var2="age" , ci=TRUE , conf = 0.95 , ci.method = "delta")
Generate OR values for a 1 unit increase in a variable at specified points of another interacting variable in a simple logistic interaction model
loglinOR( var2values, model, data, var1, var2, ci = TRUE, conf = 0.95, ci.method = "delta", ci.boot.method = "perc", R = 100, parallel = "multicore", ... )
loglinOR( var2values, model, data, var1, var2, ci = TRUE, conf = 0.95, ci.method = "delta", ci.boot.method = "perc", R = 100, parallel = "multicore", ... )
var2values |
numeric vector of var2 points to estimate |
model |
model of class lrm Glm or glm. If data is NULL, the function expects to find the data in model$x |
data |
data used in the model. If absent, it will attempt to recover the data from the model object. Only used for bootstrap CI |
var1 |
variable that increases by 1 unit from 0 |
var2 |
variable to spline. var2values belong to var2 |
ci |
calculate 95% CI? |
conf |
confidence level. Default 0.95 |
ci.method |
confidence interval method. "delta" performs delta method. "bootstrap" performs bootstrapped CI (slower) |
ci.boot.method |
one of the available bootstrap CI methods from |
R |
number of bootstrap samples if ci.method = "bootstrap". Default 100 |
parallel |
can take values "no", "multicore", "snow" if ci.method = "bootstrap". Default multicore |
... |
other parameters for boot |
if ci = FALSE, a vector of estimate of length(var2values), if ci = TRUE a dataframe with 5 columns, initial values, OR, lower CI, upper CI and SE
library(rms) library(mlbench) data(PimaIndiansDiabetes) # Set age on a 5-year scale PimaIndiansDiabetes$age <- PimaIndiansDiabetes$age/5 # Recode diabetes as 0/1 PimaIndiansDiabetes$diabetes <- ifelse(PimaIndiansDiabetes$diabetes=="pos" , 1 , 0) myformula <- diabetes ~ mass + age * glucose model <- glm(myformula , data = PimaIndiansDiabetes , family = binomial()) loglinOR( var2values = 20:80 , model = model , data = PimaIndiansDiabetes , var1 ="age", var2="glucose" , ci=TRUE , conf = 0.95 , ci.method = "delta")
library(rms) library(mlbench) data(PimaIndiansDiabetes) # Set age on a 5-year scale PimaIndiansDiabetes$age <- PimaIndiansDiabetes$age/5 # Recode diabetes as 0/1 PimaIndiansDiabetes$diabetes <- ifelse(PimaIndiansDiabetes$diabetes=="pos" , 1 , 0) myformula <- diabetes ~ mass + age * glucose model <- glm(myformula , data = PimaIndiansDiabetes , family = binomial()) loglinOR( var2values = 20:80 , model = model , data = PimaIndiansDiabetes , var1 ="age", var2="glucose" , ci=TRUE , conf = 0.95 , ci.method = "delta")
Create a spline var2 by 1 unit increase of var1
plotINT( x, xlab = "", main = "", log = FALSE, ylab = NULL, line1 = TRUE, linecolor = "dodgerblue", cicolor = "darkgray", ... )
plotINT( x, xlab = "", main = "", log = FALSE, ylab = NULL, line1 = TRUE, linecolor = "dodgerblue", cicolor = "darkgray", ... )
x |
data.frame calculated using any of the function of this package |
xlab |
xlab name |
main |
plot title |
log |
if TRUE, plot the estimate in log scale |
ylab |
ylab name. Default is the estimate column name if log=FALSE otherwise Estimate(log scale) |
line1 |
if TRUE, plot horizontal line on 1 or 0 (if log=TRUE) |
linecolor |
line color. Default dodgerblue |
cicolor |
confidence intervals color. Default gray |
... |
other parameters for plot |
simple pspline smoothed splined plot of estimates of 1 unit increase in var1 at var2 values
library(rms) library(survival) data(cancer) myformula <- Surv(time, status) ~ ph.karno + ph.ecog + rcs(age, 3)*sex model <- cph(myformula , data = lung ) myHR <- rcsHR( var2values = 40:80 , model = model , data = lung , var1 ="sex", var2="age" , ci=TRUE , conf = 0.95 , ci.method = "delta") plotINT(myHR , ylab = "HR of male VS female" , xlab = "Age")
library(rms) library(survival) data(cancer) myformula <- Surv(time, status) ~ ph.karno + ph.ecog + rcs(age, 3)*sex model <- cph(myformula , data = lung ) myHR <- rcsHR( var2values = 40:80 , model = model , data = lung , var1 ="sex", var2="age" , ci=TRUE , conf = 0.95 , ci.method = "delta") plotINT(myHR , ylab = "HR of male VS female" , xlab = "Age")
Generate HR values in a Cox model for a 1 unit increase in a variable at specified points of another interacting variable splined with rcs(df >= 3)
rcsHR( var2values, model, data = NULL, var1, var2, ci = TRUE, conf = 0.95, ci.method = "delta", ci.boot.method = "perc", R = 100, parallel = "multicore", ... )
rcsHR( var2values, model, data = NULL, var1, var2, ci = TRUE, conf = 0.95, ci.method = "delta", ci.boot.method = "perc", R = 100, parallel = "multicore", ... )
var2values |
numeric vector of var2 points to estimate |
model |
model of class cph or coxph. If data is NULL, the function expects to find the data in model$x. |
data |
data used in the model. If absent, we will attempt to recover the data from the model. Only used for bootstrap and coxph models |
var1 |
variable that increases by 1 unit from 0. |
var2 |
variable to spline. var2values belong to var2 |
ci |
calculate 95% CI? |
conf |
confidence level. Default 0.95 |
ci.method |
confidence interval method. "delta" performs delta method. "bootstrap" performs bootstrapped CI (slower) |
ci.boot.method |
one of the available bootstrap CI methods from |
R |
number of bootstrap samples if ci.method = "bootstrap". Default 100 |
parallel |
can take values "no", "multicore", "snow" if ci.method = "bootstrap". Default multicore |
... |
other parameters for boot |
if ci = FALSE, a dataframe with initial values and HR , if ci = TRUE a dataframe with 5 columns, initial values, HR, lower CI, upper CI and SE
library(survival) library(rms) data(cancer) myformula <- Surv(time, status) ~ ph.karno + ph.ecog + rcs(age,4)*sex model <- cph(myformula , data = lung ) rcsHR( var2values = 40:80 , model = model , data = lung , var1 ="sex", var2="age" , ci=TRUE , conf = 0.95 , ci.method = "delta")
library(survival) library(rms) data(cancer) myformula <- Surv(time, status) ~ ph.karno + ph.ecog + rcs(age,4)*sex model <- cph(myformula , data = lung ) rcsHR( var2values = 40:80 , model = model , data = lung , var1 ="sex", var2="age" , ci=TRUE , conf = 0.95 , ci.method = "delta")
Generate estimates in a linear model for a 1 unit increase in a variable at specified points of another interacting variable splined with rcs(df >= 3)
rcsLIN( var2values, model, data = NULL, var1, var2, ci = TRUE, conf = 0.95, ci.method = "delta", ci.boot.method = "perc", R = 100, parallel = "multicore", ... )
rcsLIN( var2values, model, data = NULL, var1, var2, ci = TRUE, conf = 0.95, ci.method = "delta", ci.boot.method = "perc", R = 100, parallel = "multicore", ... )
var2values |
numeric vector of var2 points to estimate |
model |
model of class rms::Glm or stats::glm family gaussian. If data is NULL, the function expects to find the data in model$x. |
data |
data used in the model. If absent, we will attempt to recover the data from the model. Only used for bootstrap |
var1 |
variable that increases by 1 unit from 0 |
var2 |
variable to spline. var2values belong to var2 |
ci |
calculate 95% CI? |
conf |
confidence level. Default 0.95 |
ci.method |
confidence interval method. "delta" performs delta method. "bootstrap" performs bootstrapped CI (slower) |
ci.boot.method |
one of the available bootstrap CI methods from |
R |
number of bootstrap samples if ci.method = "bootstrap". Default 100 |
parallel |
can take values "no", "multicore", "snow" if ci.method = "bootstrap". Default multicore |
... |
other parameters for boot |
if ci = FALSE, a dataframe with initial values and linear estimates , if ci = TRUE a dataframe with 5 columns, initial values, linear estimates, lower CI, upper CI and SE
library(rms) library(mlbench) data(PimaIndiansDiabetes) # Recode diabetes as 0/1 PimaIndiansDiabetes$diabetes <- ifelse(PimaIndiansDiabetes$diabetes=="pos" , 1 , 0) myformula <- glucose ~ mass + diabetes * rcs(age, 4) model <- glm(myformula , data = PimaIndiansDiabetes , family="gaussian") # Show the effect on glucose of being diabetic at age 20 to 80 rcsLIN( var2values = 20:80 , model = model , data = PimaIndiansDiabetes , var1 ="diabetes", var2="age" , ci=TRUE , conf = 0.95 , ci.method = "delta")
library(rms) library(mlbench) data(PimaIndiansDiabetes) # Recode diabetes as 0/1 PimaIndiansDiabetes$diabetes <- ifelse(PimaIndiansDiabetes$diabetes=="pos" , 1 , 0) myformula <- glucose ~ mass + diabetes * rcs(age, 4) model <- glm(myformula , data = PimaIndiansDiabetes , family="gaussian") # Show the effect on glucose of being diabetic at age 20 to 80 rcsLIN( var2values = 20:80 , model = model , data = PimaIndiansDiabetes , var1 ="diabetes", var2="age" , ci=TRUE , conf = 0.95 , ci.method = "delta")
Generate OR values in a logistic model for a 1 unit increase in a variable at specified points of another interacting variable splined with rcs(df >= 3)
rcsOR( var2values, model, data = NULL, var1, var2, ci = TRUE, conf = 0.95, ci.method = "delta", ci.boot.method = "perc", R = 100, parallel = "multicore", ... )
rcsOR( var2values, model, data = NULL, var1, var2, ci = TRUE, conf = 0.95, ci.method = "delta", ci.boot.method = "perc", R = 100, parallel = "multicore", ... )
var2values |
numeric vector of var2 points to estimate |
model |
model of class lrm, Glm or glm family binomial. If data is NULL, the function expects to find the data in model$x. |
data |
data used in the model. If absent, we will attempt to recover the data from the model. Only used for bootstrap and glm class models |
var1 |
variable that increases by 1 unit from 0 |
var2 |
variable to spline. var2values belong to var2 |
ci |
calculate 95% CI? |
conf |
confidence level. Default 0.95 |
ci.method |
confidence interval method. "delta" performs delta method. "bootstrap" performs bootstrapped CI (slower) |
ci.boot.method |
one of the available bootstrap CI methods from |
R |
number of bootstrap samples if ci.method = "bootstrap". Default 100 |
parallel |
can take values "no", "multicore", "snow" if ci.method = "bootstrap". Default multicore |
... |
other parameters for boot |
if ci = FALSE, a dataframe with initial values and OR
library(rms) library(mlbench) data(PimaIndiansDiabetes) # Set age on a 5-year scale PimaIndiansDiabetes$age <- PimaIndiansDiabetes$age/5 # Recode diabetes as 0/1 PimaIndiansDiabetes$diabetes <- ifelse(PimaIndiansDiabetes$diabetes=="pos" , 1 , 0) myformula <- diabetes ~ mass + age * rcs( glucose , 4 ) model <- glm(myformula , data = PimaIndiansDiabetes , family = "binomial") rcsOR( var2values = 20:80 , model = model , data = PimaIndiansDiabetes , var1 ="age", var2="glucose" , ci=TRUE , conf = 0.95 , ci.method = "delta")
library(rms) library(mlbench) data(PimaIndiansDiabetes) # Set age on a 5-year scale PimaIndiansDiabetes$age <- PimaIndiansDiabetes$age/5 # Recode diabetes as 0/1 PimaIndiansDiabetes$diabetes <- ifelse(PimaIndiansDiabetes$diabetes=="pos" , 1 , 0) myformula <- diabetes ~ mass + age * rcs( glucose , 4 ) model <- glm(myformula , data = PimaIndiansDiabetes , family = "binomial") rcsOR( var2values = 20:80 , model = model , data = PimaIndiansDiabetes , var1 ="age", var2="glucose" , ci=TRUE , conf = 0.95 , ci.method = "delta")
A subset of data from the University of Massachusets Aids Research Unit (UMARU) IMPACT study.
umaru
umaru
A data frame with 575 rows and 10 variables
observation count
identification code
Age in years
Beck Depression Score at admission
Number of prior drug treatments
treat
site
los
time to event
censor event
heroin use at admission
cocaine use at admission
Prior Drug treatment, yes/no
Prior IV drug treatment
1 if non white, 0 otherwise
ftp://ftp.wiley.com/public/sci_tech_med/logistic