Exploratory Data Analysis

Libraries

print("Loading libraries for state analysis...")
## [1] "Loading libraries for state analysis..."
#############################################################################
knitr::opts_chunk$set(echo = FALSE)  
library(Amelia)
library(car)
library(corrplot)
library(ggcorrplot)
library(ggplot2)
library(kableExtra)
library(knitr)
library(leaflet)   
library(leaflet.extras)
## Warning: package 'leaflet.extras' was built under R version 4.0.3
library(maptools)    
library(MASS)
library(psych)
library(QuantPsyc)
library(raster)      
library(sf)          
library(shiny)       
library(sp)          
library(spatialEco)
library(spatialreg)  
library(spData)      
library(spdep)       
library(tmap)        
library(tmaptools)   
library(rmapshaper)
#############################################################################

Functions

## [1] "Loading functions for state analysis..."

Load State-Level Data / Merge

## Warning in sp::proj4string(sp): CRS object has comment, which is lost in output
## Deleting rows: 1438394546

Correlation Matrix, State Data

Principal Components Analysis

## [1] "We find a single PC that accounts for 98% of the variance for workload-related variables..."
x
PC1 %Var 0.9821355
PC2 %Var 0.0098255
PC3 %Var 0.0038796
PC4 %Var 0.0022415
PC5 %Var 0.0011427
PC6 %Var 0.0006567
PC7 %Var 0.0001184

Re-Check Correlations

Min Max Scale of State Data

vars n mean sd median trimmed mad min max range skew kurtosis se
AdmitRate 1 51 0.525 0.244 0.584 0.536 0.225 0.000 1.000 1.00 -0.401 -0.701 0.034
SumIncome 2 51 0.458 0.149 0.424 0.444 0.068 0.000 1.000 1.00 0.874 3.626 0.021
MeanProfitMgn 3 51 0.048 0.136 0.028 0.029 0.009 0.000 1.000 1.00 6.652 43.440 0.019
MeanCash 4 51 0.374 0.221 0.300 0.341 0.101 0.000 1.000 1.00 1.282 0.983 0.031
MeanEquity 5 51 0.164 0.177 0.126 0.133 0.101 0.000 1.000 1.00 2.881 9.961 0.025
MeanCare 6 51 0.520 0.219 0.471 0.512 0.194 0.000 1.000 1.00 0.251 -0.341 0.031
MeanCaid 7 51 0.283 0.231 0.234 0.255 0.223 0.000 1.000 1.00 0.967 0.400 0.032
MeanVol 8 51 0.494 0.286 0.469 0.496 0.371 0.000 1.000 1.00 -0.084 -1.259 0.040
MeanMedSch 9 51 0.232 0.209 0.148 0.192 0.101 0.000 1.000 1.00 1.906 3.466 0.029
MeanSTAC 10 51 0.574 0.261 0.592 0.586 0.268 0.000 1.000 1.00 -0.381 -0.827 0.037
PC1 11 51 0.204 0.225 0.136 0.159 0.151 0.000 1.000 1.00 1.790 2.854 0.031
AdmitRate2 12 51 0.210 0.061 0.224 0.213 0.056 0.079 0.328 0.25 -0.401 -0.701 0.009

Models

Linear Model

Marginal Models

## [1] "Run individual models to look at residuals..."

Residual Testing

## [1] "Residual Analysis..."
Queen Rook
Moran’s I Value 0.3119017 0.3092417
Moran’s I p-value 0.0000577 0.0000799
LMerror 0.0014441 0.0016997
LMLag 0.0000012 0.0000023
RLMerr 0.5453109 0.5965623
RLMlag 0.0002011 0.0003505

Queen Contiguity

## [1] "Queen FOC..."
## Warning: Function stsls moved to the spatialreg package
## 
## Call:spatialreg::stsls(formula = formula, data = data, listw = listw, 
##     zero.policy = zero.policy, na.action = na.action, robust = robust, 
##     HC = HC, legacy = legacy, W2X = W2X)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.2149065 -0.0715304  0.0010923  0.0844202  0.2508452 
## 
## Coefficients: 
##                Estimate Std. Error t value  Pr(>|t|)
## Rho            0.992076   0.123149  8.0559 8.882e-16
## (Intercept)   -0.120339   0.133293 -0.9028 0.3666220
## SumIncome      0.018952   0.150950  0.1256 0.9000867
## MeanProfitMgn -0.479184   0.154507 -3.1014 0.0019263
## MeanCash       0.046579   0.104446  0.4460 0.6556201
## MeanEquity     0.045081   0.132425  0.3404 0.7335380
## MeanCare       0.238029   0.137659  1.7291 0.0837888
## MeanCaid       0.045490   0.094063  0.4836 0.6286607
## MeanVol       -0.134376   0.077041 -1.7442 0.0811196
## MeanMedSch     0.427285   0.124247  3.4390 0.0005839
## MeanSTAC      -0.011944   0.128139 -0.0932 0.9257329
## PC1           -0.172018   0.110505 -1.5566 0.1195546
## 
## Residual variance (sigma squared): 0.013794, (sigma: 0.11745)

Rook Contiguity

## [1] "Rook FOC..."
## Warning: Function stsls moved to the spatialreg package
## 
## Call:spatialreg::stsls(formula = formula, data = data, listw = listw, 
##     zero.policy = zero.policy, na.action = na.action, robust = robust, 
##     HC = HC, legacy = legacy, W2X = W2X)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.2112067 -0.0683218  0.0010739  0.0835374  0.2490660 
## 
## Coefficients: 
##                Estimate Std. Error t value  Pr(>|t|)
## Rho            0.992828   0.126324  7.8594 3.775e-15
## (Intercept)   -0.141525   0.135392 -1.0453 0.2958840
## SumIncome      0.018472   0.153570  0.1203 0.9042559
## MeanProfitMgn -0.479125   0.157191 -3.0480 0.0023034
## MeanCash       0.054542   0.106565  0.5118 0.6087789
## MeanEquity     0.034381   0.134924  0.2548 0.7988664
## MeanCare       0.256163   0.139112  1.8414 0.0655618
## MeanCaid       0.048081   0.095842  0.5017 0.6158966
## MeanVol       -0.128689   0.078178 -1.6461 0.0997431
## MeanMedSch     0.437130   0.126463  3.4566 0.0005471
## MeanSTAC      -0.011228   0.130545 -0.0860 0.9314567
## PC1           -0.161608   0.112210 -1.4402 0.1498026
## 
## Residual variance (sigma squared): 0.014277, (sigma: 0.11949)

Comparison

R2
OLS 0.5293880
Queen 0.8191170
Rook 0.8127841

Graphical Residual Analysis

Be sure to recycle overlays!

Coefficients for State Analysis

Linear Model SE t p Queen Est SE t p Rook Est SE t p
Rho 0.000 0.000 0.000 0.000 0.992 0.123 8.056 0.000 0.993 0.126 7.859 0.000
(Intercept) -0.219 0.211 -1.036 0.306 -0.120 0.133 -0.903 0.367 -0.142 0.135 -1.045 0.296
SumIncome -0.055 0.240 -0.231 0.819 0.019 0.151 0.126 0.900 0.018 0.154 0.120 0.904
MeanProfitMgn -0.418 0.246 -1.701 0.097 -0.479 0.155 -3.101 0.002 -0.479 0.157 -3.048 0.002
MeanCash -0.162 0.161 -1.006 0.320 0.047 0.104 0.446 0.656 0.055 0.107 0.512 0.609
MeanEquity 0.183 0.209 0.874 0.387 0.045 0.132 0.340 0.734 0.034 0.135 0.255 0.799
MeanCare 0.842 0.184 4.575 0.000 0.238 0.138 1.729 0.084 0.256 0.139 1.841 0.066
MeanCaid -0.163 0.144 -1.134 0.263 0.045 0.094 0.484 0.629 0.048 0.096 0.502 0.616
MeanVol 0.129 0.111 1.160 0.253 -0.134 0.077 -1.744 0.081 -0.129 0.078 -1.646 0.100
MeanMedSch 0.386 0.198 1.952 0.058 0.427 0.124 3.439 0.001 0.437 0.126 3.457 0.001
MeanSTAC 0.483 0.179 2.696 0.010 -0.012 0.128 -0.093 0.926 -0.011 0.131 -0.086 0.931
PC1 -0.004 0.173 -0.025 0.980 -0.172 0.111 -1.557 0.120 -0.162 0.112 -1.440 0.150

Citations

Amelia Package

## 
## To cite Amelia in publications use:
## 
##   James Honaker, Gary King, Matthew Blackwell (2011). Amelia II: A
##   Program for Missing Data. Journal of Statistical Software, 45(7),
##   1-47. URL http://www.jstatsoft.org/v45/i07/.
## 
## A BibTeX entry for LaTeX users is
## 
##   @Article{,
##     title = {{Amelia II}: A Program for Missing Data},
##     author = {James Honaker and Gary King and Matthew Blackwell},
##     journal = {Journal of Statistical Software},
##     year = {2011},
##     volume = {45},
##     number = {7},
##     pages = {1--47},
##     url = {http://www.jstatsoft.org/v45/i07/},
##   }

car Package

## 
## To cite the car package in publications use:
## 
##   John Fox and Sanford Weisberg (2019). An {R} Companion to Applied
##   Regression, Third Edition. Thousand Oaks CA: Sage. URL:
##   https://socialsciences.mcmaster.ca/jfox/Books/Companion/
## 
## A BibTeX entry for LaTeX users is
## 
##   @Book{,
##     title = {An {R} Companion to Applied Regression},
##     edition = {Third},
##     author = {John Fox and Sanford Weisberg},
##     year = {2019},
##     publisher = {Sage},
##     address = {Thousand Oaks {CA}},
##     url = {https://socialsciences.mcmaster.ca/jfox/Books/Companion/},
##   }

corrplot Package

## 
## To cite corrplot in publications use:
## 
##   Taiyun Wei and Viliam Simko (2017). R package "corrplot":
##   Visualization of a Correlation Matrix (Version 0.84). Available from
##   https://github.com/taiyun/corrplot
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{corrplot2017,
##     title = {R package "corrplot": Visualization of a Correlation Matrix},
##     author = {Taiyun Wei and Viliam Simko},
##     year = {2017},
##     note = {(Version 0.84)},
##     url = {https://github.com/taiyun/corrplot},
##   }

ggcorrplot Package

## 
## To cite package 'ggcorrplot' in publications use:
## 
##   Alboukadel Kassambara (2019). ggcorrplot: Visualization of a
##   Correlation Matrix using 'ggplot2'. R package version 0.1.3.
##   https://CRAN.R-project.org/package=ggcorrplot
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {ggcorrplot: Visualization of a Correlation Matrix using 'ggplot2'},
##     author = {Alboukadel Kassambara},
##     year = {2019},
##     note = {R package version 0.1.3},
##     url = {https://CRAN.R-project.org/package=ggcorrplot},
##   }

ggplot2 Package

## 
## To cite ggplot2 in publications, please use:
## 
##   H. Wickham. ggplot2: Elegant Graphics for Data Analysis.
##   Springer-Verlag New York, 2016.
## 
## A BibTeX entry for LaTeX users is
## 
##   @Book{,
##     author = {Hadley Wickham},
##     title = {ggplot2: Elegant Graphics for Data Analysis},
##     publisher = {Springer-Verlag New York},
##     year = {2016},
##     isbn = {978-3-319-24277-4},
##     url = {https://ggplot2.tidyverse.org},
##   }

kableExtra Package

## 
## To cite package 'kableExtra' in publications use:
## 
##   Hao Zhu (2020). kableExtra: Construct Complex Table with 'kable' and
##   Pipe Syntax. R package version 1.2.1.
##   https://CRAN.R-project.org/package=kableExtra
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {kableExtra: Construct Complex Table with 'kable' and Pipe Syntax},
##     author = {Hao Zhu},
##     year = {2020},
##     note = {R package version 1.2.1},
##     url = {https://CRAN.R-project.org/package=kableExtra},
##   }

knitr Package

## 
## To cite the 'knitr' package in publications use:
## 
##   Yihui Xie (2020). knitr: A General-Purpose Package for Dynamic Report
##   Generation in R. R package version 1.29.
## 
##   Yihui Xie (2015) Dynamic Documents with R and knitr. 2nd edition.
##   Chapman and Hall/CRC. ISBN 978-1498716963
## 
##   Yihui Xie (2014) knitr: A Comprehensive Tool for Reproducible
##   Research in R. In Victoria Stodden, Friedrich Leisch and Roger D.
##   Peng, editors, Implementing Reproducible Computational Research.
##   Chapman and Hall/CRC. ISBN 978-1466561595
## 
## To see these entries in BibTeX format, use 'print(<citation>,
## bibtex=TRUE)', 'toBibtex(.)', or set
## 'options(citation.bibtex.max=999)'.

leaflet and leaflet.extras Packages

## 
## To cite package 'leaflet' in publications use:
## 
##   Joe Cheng, Bhaskar Karambelkar and Yihui Xie (2019). leaflet: Create
##   Interactive Web Maps with the JavaScript 'Leaflet' Library. R package
##   version 2.0.3. https://CRAN.R-project.org/package=leaflet
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {leaflet: Create Interactive Web Maps with the JavaScript 'Leaflet'
## Library},
##     author = {Joe Cheng and Bhaskar Karambelkar and Yihui Xie},
##     year = {2019},
##     note = {R package version 2.0.3},
##     url = {https://CRAN.R-project.org/package=leaflet},
##   }
## 
## To cite package 'leaflet.extras' in publications use:
## 
##   Bhaskar Karambelkar and Barret Schloerke (2018). leaflet.extras:
##   Extra Functionality for 'leaflet' Package. R package version 1.0.0.
##   https://CRAN.R-project.org/package=leaflet.extras
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {leaflet.extras: Extra Functionality for 'leaflet' Package},
##     author = {Bhaskar Karambelkar and Barret Schloerke},
##     year = {2018},
##     note = {R package version 1.0.0},
##     url = {https://CRAN.R-project.org/package=leaflet.extras},
##   }

maptools Package

## 
## To cite package 'maptools' in publications use:
## 
##   Roger Bivand and Nicholas Lewin-Koh (2020). maptools: Tools for
##   Handling Spatial Objects. R package version 1.0-2.
##   https://CRAN.R-project.org/package=maptools
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {maptools: Tools for Handling Spatial Objects},
##     author = {Roger Bivand and Nicholas Lewin-Koh},
##     year = {2020},
##     note = {R package version 1.0-2},
##     url = {https://CRAN.R-project.org/package=maptools},
##   }

MASS Package

## 
## To cite the MASS package in publications use:
## 
##   Venables, W. N. & Ripley, B. D. (2002) Modern Applied Statistics with
##   S. Fourth Edition. Springer, New York. ISBN 0-387-95457-0
## 
## A BibTeX entry for LaTeX users is
## 
##   @Book{,
##     title = {Modern Applied Statistics with S},
##     author = {W. N. Venables and B. D. Ripley},
##     publisher = {Springer},
##     edition = {Fourth},
##     address = {New York},
##     year = {2002},
##     note = {ISBN 0-387-95457-0},
##     url = {http://www.stats.ox.ac.uk/pub/MASS4/},
##   }

psych and QuantPsyc Packages

## 
## To cite the psych package in publications use:
## 
##   Revelle, W. (2020) psych: Procedures for Personality and
##   Psychological Research, Northwestern University, Evanston, Illinois,
##   USA, https://CRAN.R-project.org/package=psych Version = 2.0.8,.
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {psych: Procedures for Psychological, Psychometric, and Personality Research},
##     author = {William Revelle},
##     organization = { Northwestern University},
##     address = { Evanston, Illinois},
##     year = {2020},
##     note = {R package version 2.0.8},
##     url = {https://CRAN.R-project.org/package=psych},
##   }
## 
## To cite package 'QuantPsyc' in publications use:
## 
##   Thomas D. Fletcher (2012). QuantPsyc: Quantitative Psychology Tools.
##   R package version 1.5. https://CRAN.R-project.org/package=QuantPsyc
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {QuantPsyc: Quantitative Psychology Tools},
##     author = {Thomas D. Fletcher},
##     year = {2012},
##     note = {R package version 1.5},
##     url = {https://CRAN.R-project.org/package=QuantPsyc},
##   }
## 
## ATTENTION: This citation information has been auto-generated from the
## package DESCRIPTION file and may need manual editing, see
## 'help("citation")'.

raster Package

## 
## To cite package 'raster' in publications use:
## 
##   Robert J. Hijmans (2020). raster: Geographic Data Analysis and
##   Modeling. R package version 3.3-13.
##   https://CRAN.R-project.org/package=raster
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {raster: Geographic Data Analysis and Modeling},
##     author = {Robert J. Hijmans},
##     year = {2020},
##     note = {R package version 3.3-13},
##     url = {https://CRAN.R-project.org/package=raster},
##   }

sf Package

## 
## To cite package sf in publications, please use:
## 
##   Pebesma, E., 2018. Simple Features for R: Standardized Support for
##   Spatial Vector Data. The R Journal 10 (1), 439-446,
##   https://doi.org/10.32614/RJ-2018-009
## 
## A BibTeX entry for LaTeX users is
## 
##   @Article{,
##     author = {Edzer Pebesma},
##     title = {{Simple Features for R: Standardized Support for Spatial Vector Data}},
##     year = {2018},
##     journal = {{The R Journal}},
##     doi = {10.32614/RJ-2018-009},
##     url = {https://doi.org/10.32614/RJ-2018-009},
##     pages = {439--446},
##     volume = {10},
##     number = {1},
##   }

shiny Package

## 
## To cite package 'shiny' in publications use:
## 
##   Winston Chang, Joe Cheng, JJ Allaire, Yihui Xie and Jonathan
##   McPherson (2020). shiny: Web Application Framework for R. R package
##   version 1.5.0. https://CRAN.R-project.org/package=shiny
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {shiny: Web Application Framework for R},
##     author = {Winston Chang and Joe Cheng and JJ Allaire and Yihui Xie and Jonathan McPherson},
##     year = {2020},
##     note = {R package version 1.5.0},
##     url = {https://CRAN.R-project.org/package=shiny},
##   }

sp Package

## 
## To cite package sp in publications use:
## 
##   Pebesma, E.J., R.S. Bivand, 2005. Classes and methods for spatial
##   data in R. R News 5 (2), https://cran.r-project.org/doc/Rnews/.
## 
##   Roger S. Bivand, Edzer Pebesma, Virgilio Gomez-Rubio, 2013. Applied
##   spatial data analysis with R, Second edition. Springer, NY.
##   https://asdar-book.org/
## 
## To see these entries in BibTeX format, use 'print(<citation>,
## bibtex=TRUE)', 'toBibtex(.)', or set
## 'options(citation.bibtex.max=999)'.

spatialEco and spatialreg Packages

## 
## To cite spatialEco in publications use:
## 
## Evans JS (2020). _spatialEco_. R package version 1.3-1, <URL:
## https://github.com/jeffreyevans/spatialEco>.
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{spatialEco-package,
##     title = {spatialEco},
##     author = {Jeffrey S. Evans},
##     year = {2020},
##     note = {R package version 1.3-1},
##     url = {https://github.com/jeffreyevans/spatialEco},
##   }
## 
## To cite spatialreg in publications use one or more of the following as
## appropriate:
## 
##   Roger Bivand, Gianfranco Piras (2015). Comparing Implementations of
##   Estimation Methods for Spatial Econometrics. Journal of Statistical
##   Software, 63(18), 1-36. URL http://www.jstatsoft.org/v63/i18/.
## 
##   Bivand, R. S., Hauke, J., and Kossowski, T. (2013). Computing the
##   Jacobian in Gaussian spatial autoregressive models: An illustrated
##   comparison of available methods. Geographical Analysis, 45(2),
##   150-179. URL https://doi.org/10.1111/gean.12008
## 
##   Roger S. Bivand, Edzer Pebesma, Virgilio Gomez-Rubio, 2013. Applied
##   spatial data analysis with R, Second edition. Springer, NY.
##   http://www.asdar-book.org/
## 
## To see these entries in BibTeX format, use 'print(<citation>,
## bibtex=TRUE)', 'toBibtex(.)', or set
## 'options(citation.bibtex.max=999)'.

spData and spdep Packages

## 
## To cite package 'spData' in publications use:
## 
##   Roger Bivand, Jakub Nowosad and Robin Lovelace (2020). spData:
##   Datasets for Spatial Analysis. R package version 0.3.8.
##   https://CRAN.R-project.org/package=spData
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {spData: Datasets for Spatial Analysis},
##     author = {Roger Bivand and Jakub Nowosad and Robin Lovelace},
##     year = {2020},
##     note = {R package version 0.3.8},
##     url = {https://CRAN.R-project.org/package=spData},
##   }
## 
## To cite spdep in publications use one or more of the following as
## appropriate:
## 
##   Bivand, Roger S. and Wong, David W. S. (2018) Comparing
##   implementations of global and local indicators of spatial association
##   TEST, 27(3), 716-748. URL https://doi.org/10.1007/s11749-018-0599-x
## 
##   Roger S. Bivand, Edzer Pebesma, Virgilio Gomez-Rubio, 2013. Applied
##   spatial data analysis with R, Second edition. Springer, NY.
##   http://www.asdar-book.org/
## 
## To see these entries in BibTeX format, use 'print(<citation>,
## bibtex=TRUE)', 'toBibtex(.)', or set
## 'options(citation.bibtex.max=999)'.

tmap, tmaptools, and rmapshaper Packages

## 
## To cite tmap/tmaptools in publications use:
## 
## Tennekes M (2018). "tmap: Thematic Maps in R." _Journal of Statistical
## Software_, *84*(6), 1-39. doi: 10.18637/jss.v084.i06 (URL:
## https://doi.org/10.18637/jss.v084.i06).
## 
## A BibTeX entry for LaTeX users is
## 
##   @Article{,
##     title = {{tmap}: Thematic Maps in {R}},
##     author = {Martijn Tennekes},
##     journal = {Journal of Statistical Software},
##     year = {2018},
##     volume = {84},
##     number = {6},
##     pages = {1--39},
##     doi = {10.18637/jss.v084.i06},
##   }
## 
## To cite package 'tmaptools' in publications use:
## 
##   Martijn Tennekes (2020). tmaptools: Thematic Map Tools. R package
##   version 3.1. https://CRAN.R-project.org/package=tmaptools
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {tmaptools: Thematic Map Tools},
##     author = {Martijn Tennekes},
##     year = {2020},
##     note = {R package version 3.1},
##     url = {https://CRAN.R-project.org/package=tmaptools},
##   }
## 
## To cite package 'rmapshaper' in publications use:
## 
##   Andy Teucher and Kenton Russell (2020). rmapshaper: Client for
##   'mapshaper' for 'Geospatial' Operations. R package version 0.4.4.
##   https://CRAN.R-project.org/package=rmapshaper
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {rmapshaper: Client for 'mapshaper' for 'Geospatial' Operations},
##     author = {Andy Teucher and Kenton Russell},
##     year = {2020},
##     note = {R package version 0.4.4},
##     url = {https://CRAN.R-project.org/package=rmapshaper},
##   }