11  Math

For a scientific report to be completely credible, it must be reproducible. The full computational environment used to derive the results, including the data and code used for statistical analysis should be available for others to reproduce. quarto is a tool that allows you integrate your code, text and figures in a single file in order to make high quality, reproducible reports. A paper published with an included quarto file and data sets can be reproduced by anyone with a computer.

Want to include equations in your writing? Easy. rmarkdown supports LaTeX style equation writing. This section introduces the two types equations, inline, and display form, and how to number equations.

11.1 Overview

  • Teaching: 10 minutes
  • Exercises: 10 minutes

11.2 Questions

  • How to I create an equation?
  • LaTeX is funky, what are the basic math commands?

11.3 Objectives

11.4 Some history

Equation editing was first made available in TeX, which later become LaTeX, named after Leslie Lamport.

11.5 Anatomy of Equations

This section shows you some basic equations types that you want to be familiar with.

Inline equations are referenced by a pair of dollar signs: $.

So this text would have an equation here $ E = mc^2$

Generates:

So this text would have an equation here $ E = mc^2$

Display equations are referenced by two pairs of dollar signs:

$$
E = mc^2
$$

\[ E = mc^2 \]

11.5.0.1 Viewing equations

Understanding whether or not you have created the right equation can be difficult. Rstudio provides previews of your equations in text (demo).

11.6 Example math commands

LaTeX is an amazing language, but understanding how to create the equations can be (more than) a bit confusing at times. This section demonstrates some example equations that you might be familiar with.

11.6.0.1 Fractions

$$
\frac{1}{2}
$$

\[ \frac{1}{2} \]

11.6.0.2 Sub and Super Scripts

$$
Y = X_1 + X_2
$$



$$
a^2 + b^2 = c^2
$$

\[ Y = X_1 + X_2 \]

\[ a^2 + b^2 = c^2 \]

11.6.0.3 Square roots

$$
\sqrt{p}
$$



$$
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
$$

\[ \sqrt{p} \]

\[ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} \]

11.6.0.4 Summations

$$
\sum_{i = 1}^{n}{(\bar{x} - x_i)^2}
$$

\[ \sum_{i = 1}^{n}{(\bar{x} - x_i)^2} \]

11.6.0.5 Bayes Rule

$$
Pr(\theta | y) = \frac{Pr(y | \theta) Pr(\theta)}{Pr(y)}
$$



$$
Pr(\theta | y) \propto Pr(y | \theta) Pr(\theta)
$$

\[ Pr(\theta | y) = \frac{Pr(y | \theta) Pr(\theta)}{Pr(y)} \]

\[ Pr(\theta | y) \propto Pr(y | \theta) Pr(\theta) \]

11.6.0.6 Linear Model

$$
Y \sim X\beta_0 + X\beta_1 + \epsilon
$$



$$
\epsilon \sim N(0,\sigma^2)
$$

\[ Y \sim X\beta_0 + X\beta_1 + \epsilon \]

\[ \epsilon \sim N(0,\sigma^2) \]

11.7 Exercise

  1. Add some math to your example document

11.8 Further Reading:

https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html#equations https://oeis.org/wiki/List_of_LaTeX_mathematical_symbols