Setup

To run this document you will need to install the following packages:

## Run manually if you need to install these packages
install.packages(c("rmarkdown", "AER", "corrplot", "ggplot2", "devtools"))

TODO

Correlation plot

## Load the data
data("mtcars")

## Load the library that has the plotting function
library('corrplot')

## Calculate the correlations and make the plot
# TODO: check http://cran.r-project.org/web/packages/knitrBootstrap/vignettes/two-D.html for code

## TODO: calculate the range of the correlations excluding the ones from the
## diagonal and save them into a vector called "mcor.range". You might want to use the upper.tri() and range() functions.
## You will be able to access the "mcor.range" object by inline R code after
## this chunk. For example, the following would print the smallest correlation:
## `r min(mcor.range)`

The above plot shows the correlation for the mtcars data set that has TODO rows and TODO variables. The non-diagonal correlations range from TODO (use 3 significant digits) to TODO (use 3 significant digits).

Math vs reading scores

## Load the school data
library('AER')
data('CASchools')

## Load the plotting library
library('ggplot2')

## Give it a shorter name
cas <- CASchools

## Reproduce figure Q4 from 
## http://jeromyanglim.blogspot.com/2012/05/example-reproducile-report-using-r.html
# However, we'll tweak the original figure by adding a linear regression line
# (with no spread for the regression line) and color it "orange".
# Check the "Basic scatterplots with regression lines" section from 
# http://www.cookbook-r.com/Graphs/Scatterplots_(ggplot2)/
# You'll want the original code and add a second geom_smooth() call that will
# kind of look like this:
# ggplot(cas, aes(read, math)) + geom_point() + geom_smooth() + geom_smooth(TO_COMPLETE, col = 'orange')

## Fit a simple linear regression where your outcome Y is the math scores and 
## your predictor X are the reading scores.
# You'll want to use the lm() function and save your results into an object.
# Call this object "fit".

## Extract slope, p-value, and calculate 95% confidence interval
# Remember that the output from lm() is like a list with different names. Check
# them using:
# names(fit)

# For the slope, you will want the coefficient that corresponds to the "read"
# variable. Save it in an object called "beta1".

# For the p-value, notice that you can extract it from the summary results.
# That is, look at:
# summary(fit)
# names(summary(fit))
# summary(fit)$coefficients ## ultimate hint :P
# Then extract the p-value for the "read" coefficient.

# Finally, for the 95% confidence interval, you will want to extract the
# standard error of the "read" coefficient. Lets call it se. Then use:
# beta1 + c(-1.96, 1.96) * se
# and save it into an object called "ci".

This plot shows the relationship between reading and math scores for K-6 and K-8 districts in California from 1998 and 1999. The blue line shows the smoothed relationship with its spread in grey. This line is quite similar to the linear relationship shown in orange. For 1 unit increase in the read score, the math score increases by TODO (use 3 significant digits) units which is significantly different from zero (95 percent confidence interval (TODO (use 3 significant digits), TODO (use 3 significant digits)), P-value: \(TODO (use 3 significant digits)\)).

References

Based on:

Reproducibility

library('devtools')
session_info()
## Session info --------------------------------------------------------------
##  setting  value                                      
##  version  R version 3.2.0 Patched (2015-05-18 r68382)
##  system   x86_64, darwin10.8.0                       
##  ui       X11                                        
##  language (EN)                                       
##  collate  en_US.UTF-8                                
##  tz       America/New_York
## Packages ------------------------------------------------------------------
##  package    * version    date       source                         
##  AER        * 1.2-4      2015-06-06 CRAN (R 3.2.0)                 
##  car        * 2.0-25     2015-03-03 CRAN (R 3.2.0)                 
##  colorspace   1.2-6      2015-03-11 CRAN (R 3.2.0)                 
##  corrplot   * 0.73       2013-10-15 CRAN (R 3.2.0)                 
##  curl         0.8        2015-06-06 CRAN (R 3.2.0)                 
##  devtools   * 1.8.0      2015-05-09 CRAN (R 3.2.0)                 
##  digest       0.6.8      2014-12-31 CRAN (R 3.2.0)                 
##  evaluate     0.7        2015-04-21 CRAN (R 3.2.0)                 
##  formatR      1.2        2015-04-21 CRAN (R 3.2.0)                 
##  Formula      1.2-1      2015-04-07 CRAN (R 3.2.0)                 
##  ggplot2    * 1.0.1.9000 2015-06-12 Github (hadley/ggplot2@3b6a126)
##  git2r        0.10.1     2015-05-07 CRAN (R 3.2.0)                 
##  gtable       0.1.2      2012-12-05 CRAN (R 3.2.0)                 
##  htmltools    0.2.6      2014-09-08 CRAN (R 3.2.0)                 
##  knitr        1.10.5     2015-05-06 CRAN (R 3.2.0)                 
##  lattice      0.20-31    2015-03-30 CRAN (R 3.2.0)                 
##  lme4         1.1-7      2014-07-19 CRAN (R 3.2.0)                 
##  lmtest     * 0.9-34     2015-06-06 CRAN (R 3.2.0)                 
##  magrittr     1.5        2014-11-22 CRAN (R 3.2.0)                 
##  MASS         7.3-40     2015-03-21 CRAN (R 3.2.0)                 
##  Matrix       1.2-1      2015-06-01 CRAN (R 3.2.0)                 
##  memoise      0.2.1      2014-04-22 CRAN (R 3.2.0)                 
##  mgcv         1.8-6      2015-03-31 CRAN (R 3.2.0)                 
##  minqa        1.2.4      2014-10-09 CRAN (R 3.2.0)                 
##  munsell      0.4.2      2013-07-11 CRAN (R 3.2.0)                 
##  nlme         3.1-120    2015-02-20 CRAN (R 3.2.0)                 
##  nloptr       1.0.4      2014-08-04 CRAN (R 3.2.0)                 
##  nnet         7.3-9      2015-02-11 CRAN (R 3.2.0)                 
##  pbkrtest     0.4-2      2014-11-13 CRAN (R 3.2.0)                 
##  plyr         1.8.3      2015-06-12 CRAN (R 3.2.0)                 
##  proto        0.3-10     2012-12-22 CRAN (R 3.2.0)                 
##  quantreg     5.11       2015-01-11 CRAN (R 3.2.0)                 
##  Rcpp         0.11.6     2015-05-01 CRAN (R 3.2.0)                 
##  reshape2     1.4.1      2014-12-06 CRAN (R 3.2.0)                 
##  rmarkdown  * 0.7        2015-06-13 CRAN (R 3.2.0)                 
##  rversions    1.0.1      2015-06-06 CRAN (R 3.2.0)                 
##  sandwich   * 2.3-3      2015-03-26 CRAN (R 3.2.0)                 
##  scales       0.2.5      2015-06-12 CRAN (R 3.2.0)                 
##  SparseM      1.6        2015-01-05 CRAN (R 3.2.0)                 
##  stringi      0.4-1      2014-12-14 CRAN (R 3.2.0)                 
##  stringr      1.0.0      2015-04-30 CRAN (R 3.2.0)                 
##  survival   * 2.38-2     2015-06-12 CRAN (R 3.2.0)                 
##  xml2         0.1.1      2015-06-02 CRAN (R 3.2.0)                 
##  yaml         2.1.13     2014-06-12 CRAN (R 3.2.0)                 
##  zoo        * 1.7-12     2015-03-16 CRAN (R 3.2.0)

Date this report was generated: 2015-06-18 14:37:35.