View source: R/survival-coxph.R
tidy.coxph | R Documentation |
Tidy summarizes information about the components of a model. A model component might be a single term in a regression, a single hypothesis, a cluster, or a class. Exactly what tidy considers to be a model component varies across models but is usually self-evident. If a model has several distinct types of components, you will need to specify which components to return.
## S3 method for class 'coxph'
tidy(x, exponentiate = FALSE, conf.int = FALSE, conf.level = 0.95, ...)
x |
A |
exponentiate |
Logical indicating whether or not to exponentiate the
the coefficient estimates. This is typical for logistic and multinomial
regressions, but a bad idea if there is no log or logit link. Defaults
to |
conf.int |
Logical indicating whether or not to include a confidence
interval in the tidied output. Defaults to |
conf.level |
The confidence level to use for the confidence interval
if |
... |
For |
A tibble::tibble()
with columns:
estimate |
The estimated value of the regression term. |
p.value |
The two-sided p-value associated with the observed statistic. |
statistic |
The value of a T-statistic to use in a hypothesis that the regression term is non-zero. |
std.error |
The standard error of the regression term. |
tidy()
, survival::coxph()
Other coxph tidiers:
augment.coxph()
,
glance.coxph()
Other survival tidiers:
augment.coxph()
,
augment.survreg()
,
glance.aareg()
,
glance.cch()
,
glance.coxph()
,
glance.pyears()
,
glance.survdiff()
,
glance.survexp()
,
glance.survfit()
,
glance.survreg()
,
tidy.aareg()
,
tidy.cch()
,
tidy.pyears()
,
tidy.survdiff()
,
tidy.survexp()
,
tidy.survfit()
,
tidy.survreg()
# load libraries for models and data
library(survival)
# fit model
cfit <- coxph(Surv(time, status) ~ age + sex, lung)
# summarize model fit with tidiers
tidy(cfit)
tidy(cfit, exponentiate = TRUE)
lp <- augment(cfit, lung)
risks <- augment(cfit, lung, type.predict = "risk")
expected <- augment(cfit, lung, type.predict = "expected")
glance(cfit)
# also works on clogit models
resp <- levels(logan$occupation)
n <- nrow(logan)
indx <- rep(1:n, length(resp))
logan2 <- data.frame(
logan[indx, ],
id = indx,
tocc = factor(rep(resp, each = n))
)
logan2$case <- (logan2$occupation == logan2$tocc)
cl <- clogit(case ~ tocc + tocc:education + strata(id), logan2)
tidy(cl)
glance(cl)
library(ggplot2)
ggplot(lp, aes(age, .fitted, color = sex)) +
geom_point()
ggplot(risks, aes(age, .fitted, color = sex)) +
geom_point()
ggplot(expected, aes(time, .fitted, color = sex)) +
geom_point()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.