library(ggplot2)
library(rms)Loading required package: Hmisc
Attaching package: 'Hmisc'
The following objects are masked from 'package:base':
format.pval, units
library(Hmisc)For this introduction, I used three R packages. If you have never used these before, they will need to be installed once, e.g.
install.packages("ggplot2")
install.packages("rms")
install.packages("Hmisc")If they have already been installed, you can load these packages.
library(ggplot2)
library(rms)Loading required package: Hmisc
Attaching package: 'Hmisc'
The following objects are masked from 'package:base':
format.pval, units
library(Hmisc)Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.
Quarto includes many more features than I will cover in this course. It is not a learning objective of this course that you learn all of the features included in Quarto. Instead, I want to cover a few of the most useful things and provide a starting point for those interested in learning more.
When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:
1 + 1[1] 2
You can add options to executable code like this
[1] 4
The echo: false option disables the printing of code (only output is displayed).
You can include plots
ggplot(cars, aes(x=speed, y=dist)) +
geom_smooth() +
xlab("Speed (mph)") +
ylab("Stopping Distance (feet)")`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
Speed and stopping distance of cars
And tables that are simple text
# Create some data
set.seed(12345) # Fpr reproducibility
exampledata <- data.frame(age=rnorm(500,50,5),
sbp=rnorm(500,120,12),
trt=factor(sample(c("Drug","Placebo"), 500, replace=TRUE))
)
f <- summaryM(age + sbp ~ trt, data=exampledata, test=TRUE)
print(f, digits=2)
Descriptive Statistics (N=500)
+---+------------------+------------------+------------------------+
| |Drug |Placebo | Test |
| |(N=260) |(N=240) |Statistic |
+---+------------------+------------------+------------------------+
|age| 47/50/53 | 47/51/54 | F=0.5 d.f.=1,498 P=0.48|
+---+------------------+------------------+------------------------+
|sbp| 113/120/129| 112/120/128|F=0.02 d.f.=1,498 P=0.89|
+---+------------------+------------------+------------------------+
Table can also be formatted to improve appearance. Here is an html version of the same table.
html(f, digits=3)| Descriptive Statistics (N=500). | |||
|---|---|---|---|
| Drug N=260 |
Placebo N=240 |
Test Statistic |
|
| age | 47.4 50.3 53.2 | 47.0 50.7 54.0 | F1 498=0.5, P=0.479 |
| sbp | 113 120 129 | 112 120 128 | F1 498=0.02, P=0.89 |
| a b c represent the lower quartile a, the median b, and the upper quartile c for continuous variables. Test used: Wilcoxon test . |
|||
The beginning of this document of the document contains metadata that controls the document appearance, output format, and many other options. The current lines were automatically generated when I create a new document (File > New File > Quarto Document…)
For longer documents, it can be useful to add a table of contents. A simple toc can added with the line.
toc: trueAlso, the default output type is an html document. This is a good choice, but if you prefer other options, you can alter the yaml to produce Word files, PDFs, or many other options. Tab-completion is supported to see the various options.
In order to create PDFs you will need to install a recent distribution of TeX. We recommend the use of TinyTeX (which is based on TexLive), which you can install with the following command:
quarto install tinytex
More details on authoring Quarto documents in Rstudio are available elsewhere.