This report was automatically generated with the R package knitr (version 1.5).
library(faraway)
data(gala, package = "faraway")
lmod <- lm(Species ~ Area + Elevation + Nearest + Scruz + Adjacent, gala)
sumary(lmod)
Estimate Std. Error t value Pr(>|t|)
(Intercept) 7.06822 19.15420 0.37 0.7154
Area -0.02394 0.02242 -1.07 0.2963
Elevation 0.31946 0.05366 5.95 3.8e-06
Nearest 0.00914 1.05414 0.01 0.9932
Scruz -0.24052 0.21540 -1.12 0.2752
Adjacent -0.07480 0.01770 -4.23 0.0003
n = 30, p = 6, Residual SE = 60.98, R-Squared = 0.77
sumary(lm(Species ~ Elevation, gala))
Estimate Std. Error t value Pr(>|t|)
(Intercept) 11.3351 19.2053 0.59 0.56
Elevation 0.2008 0.0346 5.80 3.2e-06
n = 30, p = 2, Residual SE = 78.66, R-Squared = 0.55
plot(Species ~ Elevation, gala)
abline(11.3, 0.201)
colMeans(gala)
Species Endemics Area Elevation Nearest Scruz Adjacent
85.23 26.10 261.71 368.03 10.06 56.98 261.10
p <- predict(lmod, data.frame(Area = 261.7, Elevation = gala$Elevation, Nearest = 10.06,
Scruz = 56.98, Adjacent = 261.1))
i <- order(gala$Elevation)
lines(gala$Elevation[i], p[i], lty = 2)
data(newhamp, package = "faraway")
colSums(newhamp[newhamp$votesys == "D", 2:3])
Obama Clinton
86353 96890
colSums(newhamp[newhamp$votesys == "H", 2:3])
Obama Clinton
16926 14471
newhamp$trt <- ifelse(newhamp$votesys == "H", 1, 0)
lmodu <- lm(pObama ~ trt, newhamp)
sumary(lmodu)
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.35252 0.00517 68.15 < 2e-16
trt 0.04249 0.00851 4.99 1.1e-06
n = 276, p = 2, Residual SE = 0.07, R-Squared = 0.08
lmodz <- lm(pObama ~ trt + Dean, newhamp)
sumary(lmodz)
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.22112 0.01125 19.65 <2e-16
trt -0.00475 0.00776 -0.61 0.54
Dean 0.52290 0.04165 12.55 <2e-16
n = 276, p = 3, Residual SE = 0.05, R-Squared = 0.42
sumary(lm(Dean ~ trt, newhamp))
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.25129 0.00599 41.99 <2e-16
trt 0.09034 0.00985 9.18 <2e-16
n = 276, p = 2, Residual SE = 0.08, R-Squared = 0.24
require(Matching)
Loading required package: Matching
Loading required package: MASS
##
## Matching (Version 4.8-3.4, Build Date: 2013/10/28)
## See http://sekhon.berkeley.edu/matching for additional documentation.
## Please cite software as:
## Jasjeet S. Sekhon. 2011. ``Multivariate and Propensity Score Matching
## Software with Automated Balance Optimization: The Matching package for R.''
## Journal of Statistical Software, 42(7): 1-52.
##
set.seed(123)
mm <- GenMatch(newhamp$trt, newhamp$Dean, ties = FALSE, caliper = 0.05, pop.size = 1000)
Loading required package: rgenoud
Loading required package: parallel
## rgenoud (Version 5.7-12, Build Date: 2013-06-28)
## See http://sekhon.berkeley.edu/rgenoud for additional documentation.
## Please cite software as:
## Walter Mebane, Jr. and Jasjeet S. Sekhon. 2011.
## ``Genetic Optimization Using Derivatives: The rgenoud package for R.''
## Journal of Statistical Software, 42(11): 1-26.
##
Mon Jun 16 14:01:25 2014
Domains:
0.000000e+00 <= X1 <= 1.000000e+03
Data Type: Floating Point
Operators (code number, name, population)
(1) Cloning........................... 122
(2) Uniform Mutation.................. 125
(3) Boundary Mutation................. 125
(4) Non-Uniform Mutation.............. 125
(5) Polytope Crossover................ 125
(6) Simple Crossover.................. 126
(7) Whole Non-Uniform Mutation........ 125
(8) Heuristic Crossover............... 126
(9) Local-Minimum Crossover........... 0
SOFT Maximum Number of Generations: 100
Maximum Nonchanging Generations: 4
Population size : 1000
Convergence Tolerance: 1.000000e-03
Not Using the BFGS Derivative Based Optimizer on the Best Individual Each Generation.
Not Checking Gradients before Stopping.
Using Out of Bounds Individuals.
Maximization Problem.
GENERATION: 0 (initializing the population)
Lexical Fit..... 2.056421e-01 9.987660e-01
#unique......... 1000, #Total UniqueCount: 1000
var 1:
best............ 1.000000e+00
mean............ 5.085426e+02
variance........ 8.178870e+04
GENERATION: 1
Lexical Fit..... 3.732776e-01 9.987660e-01
#unique......... 600, #Total UniqueCount: 1600
var 1:
best............ 4.466534e-03
mean............ 3.105404e+02
variance........ 8.628378e+04
GENERATION: 2
Lexical Fit..... 9.987660e-01 9.993474e-01
#unique......... 602, #Total UniqueCount: 2202
var 1:
best............ 1.603673e-03
mean............ 9.326741e+01
variance........ 4.261583e+04
GENERATION: 3
Lexical Fit..... 9.987660e-01 9.993474e-01
#unique......... 622, #Total UniqueCount: 2824
var 1:
best............ 1.603673e-03
mean............ 7.865585e+01
variance........ 3.542311e+04
GENERATION: 4
Lexical Fit..... 9.987660e-01 9.993474e-01
#unique......... 431, #Total UniqueCount: 3255
var 1:
best............ 1.603673e-03
mean............ 7.472079e+01
variance........ 3.081586e+04
GENERATION: 5
Lexical Fit..... 9.987660e-01 9.993474e-01
#unique......... 435, #Total UniqueCount: 3690
var 1:
best............ 1.603673e-03
mean............ 7.505392e+01
variance........ 3.198554e+04
GENERATION: 6
Lexical Fit..... 9.987660e-01 9.993474e-01
#unique......... 430, #Total UniqueCount: 4120
var 1:
best............ 1.603673e-03
mean............ 6.608551e+01
variance........ 2.743237e+04
GENERATION: 7
Lexical Fit..... 9.987660e-01 9.993474e-01
#unique......... 415, #Total UniqueCount: 4535
var 1:
best............ 1.603673e-03
mean............ 7.352388e+01
variance........ 3.293366e+04
'wait.generations' limit reached.
No significant improvement in 4 generations.
Solution Lexical Fitness Value:
9.987660e-01 9.993474e-01
Parameters at the Solution:
X[ 1] : 1.603673e-03
Solution Found Generation 2
Number of Generations Run 7
Mon Jun 16 14:01:34 2014
Total run time : 0 hours 0 minutes and 9 seconds
head(mm$matches[, 1:2])
[,1] [,2]
[1,] 4 168
[2,] 17 169
[3,] 18 53
[4,] 19 83
[5,] 21 246
[6,] 22 95
newhamp[c(4, 218), c("Dean", "pObama", "trt")]
Dean pObama trt
CenterHarbor 0.2849 0.3433 1
Northwood 0.2826 0.3369 0
plot(pObama ~ Dean, newhamp, pch = trt + 1)
with(newhamp, segments(Dean[mm$match[, 1]], pObama[mm$match[, 1]], Dean[mm$match[,
2]], pObama[mm$match[, 2]]))
pdiff <- newhamp$pObama[mm$matches[, 1]] - newhamp$pObama[mm$matches[, 2]]
t.test(pdiff)
One Sample t-test
data: pdiff
t = -1.693, df = 86, p-value = 0.09413
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
-0.033341 0.002674
sample estimates:
mean of x
-0.01533
plot(pdiff ~ newhamp$Dean[mm$matches[, 1]], xlab = "Dean", ylab = "Hand-Digital")
abline(h = 0)
plot(pObama ~ Dean, newhamp, pch = trt + 1)
abline(h = c(0.353, 0.353 + 0.042), lty = 1:2)
abline(0.221, 0.5229)
abline(0.221 - 0.005, 0.5229, lty = 2)
with(newhamp, segments(Dean[mm$match[, 1]], pObama[mm$match[, 1]], Dean[mm$match[,
2]], pObama[mm$match[, 2]], col = gray(0.75)))
The R session information (including the OS info, R version and all packages used):
sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-apple-darwin13.1.0 (64-bit)
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] parallel graphics grDevices utils datasets methods stats
[8] base
other attached packages:
[1] rgenoud_5.7-12 Matching_4.8-3.4 MASS_7.3-31 faraway_1.0.6
[5] knitr_1.5 ggplot2_0.9.3.1
loaded via a namespace (and not attached):
[1] colorspace_1.2-4 dichromat_2.0-0 digest_0.6.4
[4] evaluate_0.5.3 formatR_0.10 grid_3.1.0
[7] gtable_0.1.2 labeling_0.2 munsell_0.4.2
[10] plyr_1.8.1 proto_0.3-10 RColorBrewer_1.0-5
[13] Rcpp_0.11.1 reshape2_1.2.2 scales_0.2.3
[16] stringr_0.6.2 tools_3.1.0
Sys.time()
[1] "2014-06-16 14:01:34 BST"