Examples for rms Package

Introduction

Markdown

This is an R Markdown html document using the template that is here. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

require(rms)
knitrSet(lang='markdown')

The following (r hidingTOC(buttonLabel="Outline")) uses the Hmisc hidingTOC function to define HTML styles related to a floating table of contents that can be minimized or be collapsed to major outline levels. For more details see this.

r hidingTOC(buttonLabel="Outline")

Data {.tabset}

Setup

getHdata(titanic3)  # Get the dataset from the VU DataSets page
mu <- markupSpecs$html   # markupSpecs is in Hmisc
subtext <- mu$subtext
code    <- mu$code

Data Dictionary

html(contents(titanic3), maxlevels=10, levelType='table')

Descriptive Statisticsr subtext('for the', code('titanic3'), 'dataset')

# Set graphics type so that Hmisc and rms packages use plotly
# Chunk header height=150 is in pixels
# For certain print methods set to use html
options(grType='plotly', prType='html')
s <- summaryM(age + pclass ~ sex, data=titanic3)
html(s)
plot(s)
d <- describe(titanic3)
plot(d)

The following doesn't work because it overlays two different legends

# Try combining two plots into one
p <- plot(d)
plotly::subplot(p[[1]], p[[2]],
                nrows=2, heights=c(.3, .7), which_layout=1)

Logistic Regression Model

dd <- datadist(titanic3); options(datadist='dd')
f <- lrm(survived ~ rcs(sqrt(age),5) * sex, data=titanic3)
print(f)
latex(f)
a <- anova(f)
print(a)
plot(a)
s <- summary(f, age=c(2, 21))
plot(s, log=TRUE)
print(s, dec=2)
ggplot(Predict(f, age, sex), height=500, width=650)  # uses ggplotly()
plotp(Predict(f, age, sex))                          # uses plotly directly
plot(nomogram(f, fun=plogis, funlabel='Prob(survive)'))

Survival Plots for r mu$code('pbc') Dataset

Hover over the curves to see particular probability estimates and numbers at risk. Click on legend components to show/hide components.

getHdata(pbc)
pbc <- upData(pbc, 
              fu.yrs = fu.days / 365.25,
              units = c(fu.yrs = 'year'))
f <- npsurv(Surv(fu.yrs, status) ~ spiders, data=pbc)
survplotp(f, time.inc=1, times=c(5, 10), fun=function(y) 1 - y)

Computing Environment

r mu$session()



Try the rms package in your browser

Any scripts or data that you put into this service are public.

rms documentation built on Sept. 12, 2023, 9:07 a.m.