modComp | R Documentation |
Compare different subsets of covariates within a model
modComp(resp, vars, model, covars, data = NULL, uni = TRUE, ci = TRUE, ...)
resp |
the response variable |
vars |
character vector containing the names of all variables of interest |
model |
name of the model |
covars |
a list containing index vectors on |
data |
location of the variables in |
uni |
logical: should univariate analyses be performed. If integer, this is used as an index on |
ci |
if TRUE confidence intervals are included |
... |
arguments passed to |
This function cannot yet incorporate interactions.
Henrik Renlund
# Comparing two set of covariates in model 'lm'
DF <- data.frame(x1=c(1,2,3,4),x2=c(3,4,0,1))
DF$y <- 2*DF$x1 + DF$x2 + c(0.1, -0.2, 0.05,0.05)
modComp(
resp = "y",
vars = c("x1", "x2"),
model = lm,
covars = list(1, 1:2),
data = DF,
uni = FALSE,
ci = TRUE,
round=2
)
# Comparing different covariates in model 'coxph'
library(survival)
DF <- data.frame(
x = c(3,1,2,3,2,4,5,6,4,5,3,2,4,1,1,2,3,4,6,7,8,1,1,2,6,4,2,1,1,3,4),
y = c(0,1,1,0,1,0,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,0,1,1,0,1,0,0,1,0,0),
z = rep(letters[1:2], length.out=31),
u = rep(c(1:5), length.out=31)
)
cox_endp <- with(DF, Surv(x,y))
modComp(resp = "cox_endp",
vars = c("z", "u"),
model=coxph,
covars=list(1:2),
data = DF,
uni=TRUE,
ci=FALSE,
round=1,
fun=exp
)
# Comparing different covariates in model 'glm' NOTE: must incorporate
# the argument "family='binomial'" by defining a function such that this is
# true
Model <- function(formula, data) glm(formula=formula,
family="binomial",data=data)
modComp(resp = "y",
vars = c("x", "z"),
model=Model,
covars=list(1:2, 2),
data = DF,
uni=TRUE,
ci=FALSE,
signif=3,
fun=exp
)
rm(Model, cox_endp, DF)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.