From f51206d3b2329e590344059f200f9952a7ada390 Mon Sep 17 00:00:00 2001 From: mjpalacios Date: Mon, 18 Jan 2016 20:09:00 -0600 Subject: [PATCH] Updates: LittleInferenceBook.Rmd: When knitting to PDF, was failing to include a title page. Added reference to new file title.tex for that title.tex: Uses titling package to pull the quincunx figure 02_probability.md: When knitting to PDF, {eqnarray*} was failing to knit using MikTex on Windows. Replaced it with {aligned} 03_conditional.md: When knitting to PDF, {eqnarray*} was failing to knit using MikTex on Windows. Replaced it with {aligned} --- manuscript/02_probability.md | 16 ++--- manuscript/03_conditional.md | 12 ++-- manuscript/LittleInferenceBook.Rmd | 110 +++++++++++++++-------------- manuscript/title.tex | 8 +++ 4 files changed, 79 insertions(+), 67 deletions(-) create mode 100755 manuscript/title.tex diff --git a/manuscript/02_probability.md b/manuscript/02_probability.md index 6426788..c995074 100644 --- a/manuscript/02_probability.md +++ b/manuscript/02_probability.md @@ -109,20 +109,20 @@ Answer: No, the events can simultaneously occur and so exclusive. To elaborate let: {$$} - \begin{eqnarray*} - A_1 & = & \{\mbox{Person has sleep apnea}\} \\ -A_2 & = & \{\mbox{Person has RLS}\} - \end{eqnarray*} + \begin{aligned} + A_1 & = \{\mbox{Person has sleep apnea}\} \\ +A_2 & = \{\mbox{Person has RLS}\} + \end{aligned} {/$$} Then {$$} - \begin{eqnarray*} - P(A_1 \cup A_2 ) & = & P(A_1) + P(A_2) - P(A_1 \cap + \begin{aligned} + P(A_1 \cup A_2 ) & = P(A_1) + P(A_2) - P(A_1 \cap A_2) \\ - & = & 0.13 - \mbox{Probability of having both} - \end{eqnarray*} + & = 0.13 - \mbox{Probability of having both} + \end{aligned} {/$$} Given the scenario, it's likely that some fraction of the population has both. diff --git a/manuscript/03_conditional.md b/manuscript/03_conditional.md index 967c881..3f8edc2 100644 --- a/manuscript/03_conditional.md +++ b/manuscript/03_conditional.md @@ -132,12 +132,12 @@ the specificity, {$$}P(- ~|~ D^c) =.985{/$$} and the prevalence {$$}P(D) = .001{/$$}. {$$} -\begin{eqnarray*} -P(D ~|~ +) & = &\frac{P(+~|~D)P(D)}{P(+~|~D)P(D) + P(+~|~D^c)P(D^c)}\\ - & = & \frac{P(+~|~D)P(D)}{P(+~|~D)P(D) + \{1-P(-~|~D^c)\}\{1 - P(D)\}} \\ - & = & \frac{.997\times .001}{.997 \times .001 + .015 \times .999}\\ - & = & .062 -\end{eqnarray*} +\begin{aligned} +P(D ~|~ +) & = \frac{P(+~|~D)P(D)}{P(+~|~D)P(D) + P(+~|~D^c)P(D^c)}\\ + & = \frac{P(+~|~D)P(D)}{P(+~|~D)P(D) + \{1-P(-~|~D^c)\}\{1 - P(D)\}} \\ + & = \frac{.997\times .001}{.997 \times .001 + .015 \times .999}\\ + & = .062 +\end{aligned} {/$$} In this population a positive test result only suggests a 6% probability that diff --git a/manuscript/LittleInferenceBook.Rmd b/manuscript/LittleInferenceBook.Rmd index 92b223f..ee5d2df 100644 --- a/manuscript/LittleInferenceBook.Rmd +++ b/manuscript/LittleInferenceBook.Rmd @@ -1,53 +1,57 @@ ---- -output: - html_document: - toc: true - toc_depth: 2 - includes: - before_body: frontmatter.html ---- - - -```{r book, results='asis', echo = FALSE} - -# Get list of .md files from the LeanPub configuration file -chapters <- readLines(con = "Book.txt") - -# Set the encoding -encoding <- "Latin1" - -# Output the content of every file -invisible( - sapply(X = chapters, encoding = encoding, - FUN = function(file, encoding){ - # Read in file contents - contents <- readLines(con = file, encoding = encoding) - - # Replace with correct equation markers - contents <- gsub(pattern = "([{][$]{2}[}] *)|( *[{]/[$]{2}[}])", - replacement = "$$", - x = contents) - - # Fix code blocks - contents <- paste(contents, collapse = "\n") - contents <- gsub(pattern = " ~ ", replacement = " \tilde ", x = contents) - contents <- gsub(pattern = paste0("\n[{](title ?= ?\"([^\"]*)\")?", - "[^~]*~~*[[:space:]]*", - "([^~]*)", - "~~*\n"), - replacement = "\n**\\2**\n\n```\n\\3\n```\n\n", - x = contents) - contents <- gsub(pattern = " \\tilde ", replacement = " ~ ", x = contents) - - # Identify inline equations - contents <- gsub(pattern = "[$]{2}", replacement = "$", x = contents) - contents <- gsub(pattern = "(\n{2,})[$]([^$]*)[$]", - replacement = "\\1$$\\2$$", - x = contents) - - # Output file contents - cat(contents, "\n\n", sep = "") - }) -) -``` - +--- +output: + pdf_document: + toc: true + includes: + in_header: title.tex + html_document: + toc: true + toc_depth: 2 + includes: + before_body: frontmatter.html +--- + + +```{r book, results='asis', echo = FALSE} + +# Get list of .md files from the LeanPub configuration file +chapters <- readLines(con = "Book.txt") + +# Set the encoding +encoding <- "Latin1" + +# Output the content of every file +invisible( + sapply(X = chapters, encoding = encoding, + FUN = function(file, encoding){ + # Read in file contents + contents <- readLines(con = file, encoding = encoding) + + # Replace with correct equation markers + contents <- gsub(pattern = "([{][$]{2}[}] *)|( *[{]/[$]{2}[}])", + replacement = "$$", + x = contents) + + # Fix code blocks + contents <- paste(contents, collapse = "\n") + contents <- gsub(pattern = " ~ ", replacement = " \tilde ", x = contents) + contents <- gsub(pattern = paste0("\n[{](title ?= ?\"([^\"]*)\")?", + "[^~]*~~*[[:space:]]*", + "([^~]*)", + "~~*\n"), + replacement = "\n**\\2**\n\n```\n\\3\n```\n\n", + x = contents) + contents <- gsub(pattern = " \\tilde ", replacement = " ~ ", x = contents) + + # Identify inline equations + contents <- gsub(pattern = "[$]{2}", replacement = "$", x = contents) + contents <- gsub(pattern = "(\n{2,})[$]([^$]*)[$]", + replacement = "\\1$$\\2$$", + x = contents) + + # Output file contents + cat(contents, "\n\n", sep = "") + }) +) +``` + diff --git a/manuscript/title.tex b/manuscript/title.tex new file mode 100755 index 0000000..477b1ee --- /dev/null +++ b/manuscript/title.tex @@ -0,0 +1,8 @@ +\usepackage{titling} +\setlength{\droptitle}{-1in} +\pretitle{% + \begin{center} + \LARGE + \includegraphics{images/title_page.png}\\[\bigskipamount] +} +\posttitle{\end{center}} \ No newline at end of file