This is my R Markdown Project
day_2_Rmarkdown
Kerry McGowan
Collaborator
11/17/2020
Abstract
This is an abstract.
It consists of 2 paragraphs.
The above text is called a YAML header.
Set up defalts for all chunks in document, <include=FALSE>
means it won’t show up in final HTML. <echo=FALSE>
means code won’t appear by default. “Global” means it will be applied to entire Markdown.
Header 1
Biggest, RMarkdown format
Header 1
Biggest, HTML format
Header 2
Big
Header 3
Pretty big
Header 4
Bold header line
Intro to Markdown Syntax
No line breaks
Here is an example of bold text. Another example of bold. Here is an example of italic text. Another example of italic. Here is an example of bold italic. What about superscript? x2 What about subscript? x2 Underlining text in RMarkdown isn’t advised. When we incorporate URLs, those links show up as being underlined. But here is how to do it in HTML. Underlined text = no!
No difference
Here is an example of bold text. Another example of bold. Here is an example of italic text. Another example of italic. Here is an example of bold italic. What about superscript? x2 What about subscript? x2 Underlining text in RMarkdown isn’t advised. When we incorporate URLs, those links show up as being underlined. But here is how to do it in HTML. Underlined text = no!
Line breaks
Ctrl+Shift+C
Hidden line break (two spaces):
Line 1
Line 2
Obvious way (break escape):
Line 1
Line 2
* Note: that <br>
does a line break and not a new paragraph. Enclosed in back ticks.
Body of document
This is our report introduction and we want to include supporting information in the form of a blockquote from an important person in our field.
This is a quote from an important person.
This person is really important.
This will nest a quote.
Paragraph 2
Paragraph 3
Lists
A numbered list
- item 1
- item 2
- item 3
A symbol list, doesn’t matter what symbol you use
item 1
item 2
item 3
item 1
item 2
item 3
item 1
item 2
item 3
A list with a sublist
- item 1
- subitem 1
- item 2
- subitem 2
- item 3
- subitem 3
This is my super important list
- item 1
- item 2
- item 3
Paragraphs or descriptions under list items
Item 1
This is a description for item 1. Requires 2 tabs in.
Item 2
This is a description for item 2.
Item 3
This is a description for item 3.
Tables in Markdown
Col 1 | Col 2 | Col 3 | Col 4 |
---|---|---|---|
1 | 1 | 1 | 1 |
12 | 12 | 12 | 12 |
123 | 123 | 123 | 123 |
Col 1 | Col 2 | Col 3 | Col 4 |
---|---|---|---|
1 | 1 | 1 | 1 |
12 | 12 | 12 | 12 |
123 | 123 | 123 | 123 |
Links and graphics
Let’s say we want to include a link to another source of information. We can easily do that by including the link. http://rmarkdown.rstudio.com/lesson-1.html or we can include hyperlinks with link.
Let’s include a graphic!
That’s WAY too big.
Code chunks in Markdown
Also another way to include a graphic, echo hides the code and only shows the graphic<include=FALSE>
wouldn’t include the figureGenerate data
x <- rnorm(n = 100, mean = 5, sd = 1)
y <- 2 + 2 * x + rnorm(n = length(x))
plot(x, y, main = 'y = f(x)')
Include information between (x, y). LaTeX
Our response variable is \(y\) is distributed \(N(\mu, \sigma^2_y)\), where \[\begin{align} \mu &= 2 + 2*E[x] + E(e) \\ \sigma^2 &= 2^Var[x] + Var[e] + 2(2)Cov(x, e) \end{align}\] The <&=>
sign aligns the equation by equals sign. <\\>
signals new equation line.
We see that \(\mu =\) 11.8318928 and \(\sigma^2 =\) 3.4451727. Let’s round the output.
\(\mu =\) 11.83
\(\sigma^2 =\) 3.45
Single equation in the center instead of in=line equations: \[ y = f(x) \]
Working with Data
df_all <- read_csv('data/daily_bike_data.csv')
dftemp <- df_all %>% select(cnt, temp)
ss_dftemp <- sapply(dftemp,
function(x) c(mean(x), min(x), max(x), sd(x))) %>%
data.frame() %>%
round(digits = 2)
row.names(ss_dftemp) <- c('mean', 'min', 'max', 'sd')
ss_dftemp %>% knitr::kable(caption = 'Summary Statistics')
cnt | temp | |
---|---|---|
mean | 4504.35 | 0.50 |
min | 22.00 | 0.06 |
max | 8714.00 | 0.86 |
sd | 1937.21 | 0.18 |
ggplot(dftemp, aes(temp, cnt)) +
geom_point() +
labs(title = 'Daily Bike Rental and Temp',
x = 'Temperature (F, normalized)',
y = 'Bike Rentals')
dftemp <- dftemp %>%
mutate(temp2 = temp^2)
mod1 <- lm(formula = cnt ~ temp,
data = dftemp)
mod2 <- lm(formula = cnt ~ temp + temp2,
data = dftemp)
pred_mod1 <- predict(mod1, dftemp['temp'])
pred_mod2 <- predict(mod2, dftemp[c('temp', 'temp2')])
dftemp <- dftemp %>%
mutate(cnt_mod1 = pred_mod1,
cnt_mod2 = pred_mod2)
ggplot(dftemp, aes(temp, cnt)) +
geom_point() +
geom_line(aes(temp, pred_mod1), colour = 'red', size = 1) +
geom_line(aes(temp, pred_mod2), colour = 'blue', size = 1) +
labs(title = 'Daily Bike Rental and Temp',
x = 'Temperature (F, normalized)',
y = 'Bike Rentals')
To try running a Markdown file on Kamiak:
Use an idev and load kitr and markdown before running things. And only output as HTML not PDF.