This is an R Markdown html notebookdocument. 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)
getHdata(titanic3) # Get the dataset from the VU DataSets page
mu <- markupSpecs$html # markupSpecs is in Hmisc
subtext <- mu$subtext
code <- mu$code
html(contents(titanic3), maxlevels=10, levelType='table')
Name | Labels | Units | Levels | Storage | NAs |
---|---|---|---|---|---|
pclass | 3 | integer | 0 | ||
survived | Survived | integer | 0 | ||
name | Name | character | 0 | ||
sex | 2 | integer | 0 | ||
age | Age | Year | double | 263 | |
sibsp | Number of Siblings/Spouses Aboard | integer | 0 | ||
parch | Number of Parents/Children Aboard | integer | 0 | ||
ticket | Ticket Number | character | 0 | ||
fare | Passenger Fare | British Pound (\243) | double | 1 | |
cabin | 187 | integer | 0 | ||
embarked | 3 | integer | 2 | ||
boat | 28 | integer | 0 | ||
body | Body Identification Number | integer | 1188 | ||
home.dest | Home/Destination | character | 0 |
Variable | Levels |
---|---|
pclass | 1st |
2nd | |
3rd | |
sex | female |
male | |
cabin | |
A10 | |
A11 | |
A14 | |
A16 | |
A18 | |
A19 | |
A20 | |
A21 | |
A23 | |
... | |
embarked | Cherbourg |
Queenstown | |
Southampton | |
boat | |
1 | |
10 | |
11 | |
12 | |
13 | |
13 15 | |
13 15 B | |
14 | |
15 | |
... |
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)
s
Descriptive Statistics (N=1309)
+------------+----+-----------+-----------+
| |N |female |male |
| | |(N=466) |(N=843) |
+------------+----+-----------+-----------+
|Age [Year] |1046| 19/27/38 | 21/28/39 |
+------------+----+-----------+-----------+
|pclass : 1st|1309|0.31 (144)|0.21 (179)|
+------------+----+-----------+-----------+
| 2nd | |0.23 (106)|0.20 (171)|
+------------+----+-----------+-----------+
| 3rd | |0.46 (216)|0.58 (493)|
+------------+----+-----------+-----------+
plot(s)
Ignoring 2 observations
$Categorical
$Continuous
d <- describe(titanic3)
plot(d)
$Categorical
Numeric color variables cannot (yet) be mapped to text.
Feel free to make a feature request
https://github.com/plotly/plotly.jsNumeric color variables cannot (yet) be mapped to text.
Feel free to make a feature request
https://github.com/plotly/plotly.js
$Continuous
NA
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)
dd <- datadist(titanic3); options(datadist='dd')
f <- lrm(survived ~ rcs(sqrt(age),5) * sex, data=titanic3)
f
latex(f)
\[{\rm Prob}\{{\rm survived}=1\} = \frac{1}{1+\exp(-X\beta)}, {\rm \ \ where} \\ \]
\begin{eqnarray*}
X\hat{\beta}= & & \\
& & 0.6476552 \\
& & + 0.03027852 {\rm age}+0.01114664 ({\rm age}-2.236068)_{+}^{3}-0.08633279({\rm age}-4.582576)_{+}^{3} \\
& & +0.1857246 ({\rm age}-5.291503)_{+}^{3}-0.1516536 ({\rm age}-6.082763)_{+}^{3} \\
& & +0.04111512 ({\rm age}-7.549834)_{+}^{3} \\
& & +1.345826[{\rm male}] \\
& & +[{\rm male}][-1.036388 {\rm age}+0.06620937 ({\rm age}-2.236068)_{+}^{3} \\
& & -0.5363316 ({\rm age}-4.582576)_{+}^{3}+0.6312123 ({\rm age}-5.291503)_{+}^{3} \\
& & -0.1266968 ({\rm age}-6.082763)_{+}^{3}-0.03439327({\rm age}-7.549834)_{+}^{3} ] \\
\end{eqnarray*}
and \([c]=1\) if subject is in group \(c\), 0 otherwise; \((x)_{+}=x\) if \(x > 0\), 0 otherwise
\({\rm age}\) is pre--transformed as \({\rm \sqrt{age}}\).
a <- anova(f)
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
minimal value for n is 3, returning requested palette with 3 different levels
minimal value for n is 3, returning requested palette with 3 different levels
plot(nomogram(f, fun=plogis, funlabel='Prob(survive)'))
pbc
DatasetgetHdata(pbc)
pbc <- upData(pbc,
fu.yrs = fu.days / 365.25,
units = c(fu.yrs = 'year'))
Input object size: 76592 bytes; 19 variables 418 observations
Added variable fu.yrs
New object size: 80712 bytes; 20 variables 418 observations
f <- npsurv(Surv(fu.yrs, status) ~ spiders, data=pbc)
survplotp(f, time.inc=1, times=c(5, 10))
R version 3.3.3 (2017-03-06) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 16.04.2 LTS attached base packages: [1] stats graphics grDevices utils datasets [6] methods base other attached packages: [1] rms_5.1-1 SparseM_1.76 Hmisc_4.0-3 [4] ggplot2_2.2.1 Formula_1.2-1 survival_2.41-3 [7] lattice_0.20-35To cite R in publication use:
R Core Team (2017). R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing, Vienna, Austria. https://www.R-project.org/.