--- title: "STAT704 Homework Template" date: "`r Sys.Date()`" author: John Doe output: pdf_document --- ```{r setup, include=FALSE, echo=FALSE} knitr::opts_chunk$set( warning = FALSE, message=FALSE, fig.height = 4, fig.width = 8) library(knitr) ``` ##Problem 1 Remember to say something to comment on the findings in your analysis. To write a mathematical formula in this document, you can do this: $x=\sqrt{3}$ or to have the equation centered: $$ f(x; \mu, \sigma)= \frac{1}{\sqrt{2\pi\sigma^2}} e^{-\frac{(x-\mu)^2}{2\sigma^2}} $$ To learn more about how to write mathematical expressions, google ``write mathematical expressions in latex''. ## Problem 2 Here is how to create a table in R markdown. ```{r ktable} mat<-matrix(1:9, nrow=3) rownames(mat)<-c("a", "b", "c") colnames(mat)<-c("n=5", "n=10", "n=30") kable(mat) ``` ## Probelem 3 ```{r faithful and iris data} data(faithful) data(iris) ##histograms for faithful and iris par(mfrow=c(1,2)) Hmisc::hist.data.frame(faithful,freq=FALSE) plot(faithful$eruptions, faithful$waiting, pch=16, main="Old Faithful", xlab="eruption time", ylab="waiting time") Hmisc::hist.data.frame(iris[,-5],freq=FALSE) attach(iris) plot(Sepal.Length, Petal.Length, col=Species) ##boxplots for faithful and iris par(mfrow=c(1,2)) boxplot(faithful) boxplot(iris[,-5]) ``` ##Problem 4 ```{r O-ring} x<-c(0,1,0,NA,0,0,0,0,0,1,1,1,0,0,3,0,0,0,0,0,2,0,1) table(x[!is.na(x)]) mean(x[!is.na(x)]) ``` ###Problem 5 ```{r, fig.height=6, fig.width=6} library(viridis) image(volcano, col=viridis(200)) ``` ```{r, fig.height=6, fig.width=6} library(viridis) image(volcano, col=viridis(200, option="A")) ``` #### Getting R code from .Rmd file Extract R code using purl function ```{r Extract R code, eval=FALSE} library(knitr) purl("Stat704_HWtemplate.Rmd") ``` To knit part of your Rmd file, `r knitr::knit_exit()`