Last chance! 50% off unlimited learning
Sale ends in
printCrudeAndAdjustedModel(model, order, digits = 2, ci_lim = c(-Inf, Inf), sprintf_ci_str = getOption("sprintf_ci_str", "%s to %s"), add_references, add_references_pos, reference_zero_effect, groups, rowname.fn, use_labels = TRUE, desc_column = FALSE, desc_args = caDescribeOpts(digits = digits), impute_args, ...)
rbind.printCrudeAndAdjusted(..., alt.names, deparse.level = 1)
"print"(x, css.rgroup = "", ...)
"htmlTable"(x, css.rgroup = "", ...)
"["(x, i, j, ...)
cbind.printCrudeAndAdjusted(..., alt.names, deparse.level = 1)
"knit_print"(x, css.rgroup = "", ...)
"latex"(object, ...)
getCrudeAndAdjustedModelData
> -1000
for a value of 1001. This gives
a prettier table when you have very wide confidence intervals.sprintf
to
write the confidence interval where the first %s is the lower and
the second the upper. You can choose to set this through setting the option
sprintf_ci_str
, e.g. options(sprintf_ci_str = "%s - %s")
.age_groups
as add_references_pos = list(age_groups = 2)
so that you have the second group as the position for the reference.exp(0) = 1
, or in regular format,
i.e. 0 = 0
(can be set to any value)rgroup
names
for the grouping parametercaDescribeOpts
function.coef_change
and
variance.inflation
are supported. If you want both columns then
the simplest way is to provide the list:
list(coef_change=TRUE, variance.inflation=TRUE)
.
The coef_change
adds a column with the change in coefficients due to
the imputation, the the "raw" model is subtracted from the imputed results.
The "raw" model is the unimputed model, coef(imputed_model) - coef(raw_model)
.
The variance.inflation
adds the variance.inflation.impute
from the
fit.mult.impute
to a separate column. See the description
for the variance.inflation.impute
in in the fit.mult.impute
description.
Both arguments can be customized by providing a list
. The list can have
the elements type
, name
, out_str
, and/or digits
.
The type
can for coef_change
/variance.impute
be either
"percent" or "ratio", note that variance.inflation.impute
was not
originally intended to be interpreted as %. The default for coef_change
is to
have "diff", that gives the absolute difference in the coefficient.
The name
provides the column name, the out_str
should be a string
that is compatible with sprintf
and also contains an argument
for accepting a float value, e.g. "
column. The digits
can be used if you are not using the out_str
argument, it simply specifies the number of digits to show. See the example
for how for a working example.
Note that currently only the fit.mult.impute
is supported by this option.latex
function, or to
the htmlTable
via the print call. Any variables that match
the formals of getCrudeAndAdjustedModelData
are identified
and passed on in case you have provided a model and not the returned element
from the getCrudeAndAdjustedModelData
call.htmlTable
.matrix
Returns a matrix of class printCrudeAndAdjusted that
has a default print method associated with
latex
for details regarding the latex()
function.Other printCrudeAndAdjusted functions: prCaAddRefAndStat
,
prCaAddReference
,
prCaAddUserReferences
,
prCaGetImputationCols
,
prCaGetRowname
,
prCaGetVnStats
,
prCaPrepareCrudeAndAdjusted
,
prCaReorderReferenceDescribe
,
prCaReorder
,
prCaSelectAndOrderVars
,
prCaSetRownames
# simulated data to use
set.seed(10)
ds <- data.frame(
ftime = rexp(200),
fstatus = sample(0:1,200,replace=TRUE),
Variable1 = runif(200),
Variable2 = runif(200),
Variable3 = runif(200),
Variable4 = factor(sample(LETTERS[1:4], size=200, replace=TRUE)))
library(rms)
dd <- datadist(ds)
options(datadist="dd")
fit <- cph(Surv(ftime, fstatus) ~ Variable1 + Variable3 + Variable2 + Variable4,
data=ds, x=TRUE, y=TRUE)
printCrudeAndAdjustedModel(fit, order = c("Variable[12]", "Variable3"))
printCrudeAndAdjustedModel(fit,
order=c("Variable3", "Variable4"),
add_references = TRUE,
desc_column=TRUE)
# Now to a missing example
n <- 500
ds <- data.frame(
x1 = factor(sample(LETTERS[1:4], size = n, replace = TRUE)),
x2 = rnorm(n, mean = 3, 2),
x3 = factor(sample(letters[1:3], size = n, replace = TRUE)))
ds$Missing_var1 <- factor(sample(letters[1:4], size=n, replace=TRUE))
ds$Missing_var2 <- factor(sample(letters[1:4], size=n, replace=TRUE))
ds$y <- rnorm(nrow(ds)) +
(as.numeric(ds$x1)-1) * 1 +
(as.numeric(ds$Missing_var1)-1)*1 +
(as.numeric(ds$Missing_var2)-1)*.5
# Create a messy missing variable
non_random_missing <- sample(which(ds$Missing_var1 %in% c("b", "d")),
size = 150, replace=FALSE)
# Restrict the non-random number on the x2 variables
non_random_missing <- non_random_missing[non_random_missing %in%
which(ds$x2 > mean(ds$x2)*1.5) &
non_random_missing %in%
which(ds$x2 > mean(ds$y))]
ds$Missing_var1[non_random_missing] <- NA
# Simple missing variable
ds$Missing_var2[sample(1:nrow(ds), size=50)] <- NA
# Setup the rms environment
ddist <- datadist(ds)
options(datadist = "ddist")
impute_formula <-
as.formula(paste("~",
paste(colnames(ds),
collapse="+")))
imp_ds <- aregImpute(impute_formula, data = ds, n.impute = 10)
fmult <- fit.mult.impute(y ~ x1 + x2 + x3 +
Missing_var1 + Missing_var2,
fitter = ols, xtrans = imp_ds, data = ds)
printCrudeAndAdjustedModel(fmult,
impute_args = list(variance.inflation=TRUE,
coef_change=list(type="diff",
digits=3)))
# Use some labels to prettify the output
# fro the mtcars dataset
data("mtcars")
label(mtcars$mpg) <- "Gas"
units(mtcars$mpg) <- "Miles/(US) gallon"
label(mtcars$wt) <- "Weight"
units(mtcars$wt) <- "10^3 kg" # not sure the unit is correct
mtcars$am <- factor(mtcars$am, levels=0:1, labels=c("Automatic", "Manual"))
label(mtcars$am) <- "Transmission"
mtcars$gear <- factor(mtcars$gear)
label(mtcars$gear) <- "Gears"
# Make up some data for making it slightly more interesting
mtcars$col <- factor(sample(c("red", "black", "silver"), size=NROW(mtcars), replace=TRUE))
label(mtcars$col) <- "Car color"
require(splines)
fit_mtcar <- lm(mpg ~ wt + gear + col, data=mtcars)
printCrudeAndAdjustedModel(fit_mtcar,
add_references=TRUE,
ctable=TRUE,
desc_column = TRUE,
digits=1,
desc_args = caDescribeOpts(digits = 1,
colnames = c("Avg.")))
printCrudeAndAdjustedModel(fit_mtcar,
add_references=TRUE,
desc_column=TRUE,
order=c("Interc", "gear"))
# Alterntive print - just an example, doesn't make sense to skip reference
printCrudeAndAdjustedModel(fit_mtcar,
order=c("col", "gear"),
groups=c("Color", "Gears"),
add_references=c("Black", NA),
ctable=TRUE)
# Now we can also combine models into one table using rbind()
mpg_model <- printCrudeAndAdjustedModel(lm(mpg ~ wt + gear + col, data=mtcars),
add_references=TRUE,
ctable=TRUE,
desc_column = TRUE,
digits=1,
desc_args = caDescribeOpts(digits = 1,
colnames = c("Avg.")))
wt_model <- printCrudeAndAdjustedModel(lm(wt ~ mpg + gear + col, data=mtcars),
add_references=TRUE,
ctable=TRUE,
desc_column = TRUE,
digits=1,
desc_args = caDescribeOpts(digits = 1,
colnames = c("Avg.")))
library(magrittr)
rbind(Miles = mpg_model, Weight = wt_model) %>%
htmlTable(caption="Combining models together with a table spanner element separating each model")
Run the code above in your browser using DataLab