This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.

About Rmd file

Text

Text can be decorated with bold or italics. It is also possible to

  • create links
  • include mathematics like \(e=mc^2\) or \[y = \beta_0 + \beta_1 x_1 + \beta_2 x_2\]

Be sure to put a space after the * when you are creating bullets and a space after # when creating section headers, but not between $ and the mathematical formulas.

You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

head(cars)
##   speed dist
## 1     4    2
## 2     4   10
## 3     7    4
## 4     7   22
## 5     8   16
## 6     9   10

knitr settings to control how R chunks work.

require(knitr) opts_chunk$set( tidy=FALSE, # display code as typed size=“small” # slightly smaller font for code )

The most important template is

  • goal(y~x,data=mydata)
  • What you want R to do is Goal : This determines the function to use(favstat, mean, SD, lm)
  • What must R know to do that: This determines the inputs to the function, must identify variables and data frame
  • it produces single and multiple variable graphical summaries
  • it produces single and multiple variable numerical summaries
  • linear models

Univariate Summaries

Numerical Summaries for one variable

favstats(~ age, data=HELPrct)
##  min Q1 median Q3 max     mean       sd   n missing
##   19 30     35 40  60 35.65342 7.710266 453       0
tally(~ sex, data=HELPrct)
## sex
## female   male 
##    107    346

Graphical Summaries one variable

#graphing quantitative numeric variable
histogram(~age,data=HELPrct)

densityplot(~age,data=HELPrct)

bwplot(~age,data=HELPrct)