## Load the data
data("mtcars")
## Load the library that has the plotting function
library('corrplot')
## Calculate the correlations and make the plot
mcor <- cor(mtcars)
corrplot(mcor)
## Extract the pair wise correlations.
mcor.range <- range(mcor[upper.tri(mcor)])
The above plot shows the correlation for the mtcars data set that has 32 rows and 11 variables. The non-diagonal correlations range from -0.868 to 0.902.
## 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
ggplot(cas, aes(read, math)) + geom_point() + geom_smooth() + geom_smooth(method=lm, se = FALSE, col = 'orange')
## Fit a simple linear regression
fit <- lm(math ~ read, data = cas)
## Extract slope, p-value, and calculate 95% CI
beta1 <- fit$coefficients['read']
pvalue <- summary(fit)$coefficients['read', 4]
ci <- beta1 + c(-1.96, 1.96) * summary(fit)$coefficients['read', 2]
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 0.861 units which is significantly different from zero (95 percent confidence interval (0.826, 0.895), P-value: \(2.32\times 10^{-175}\)).
Based on:
## 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)
## labeling 0.3 2014-08-23 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 15:07:34.