This is a PFD about spatial regression model for R
Just free for pinggu members
Thanks....
Spatial Regression Analysis in R
A Workbook
Luc Anselin
Spatial Analysis Laboratory
Department of Agricultural and Consumer Economics
University of Illinois, Urbana-Champaign
Urbana, IL 61801
http://sal.agecon.uiuc.edu/
Center for Spatially Integrated Social Science
http://www.csiss.org/
Preliminary Version, January 18, 2005
----------------------------------------------------------------------------
Preface v
1 Getting Started in R 1
1.1 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Conventions and General Advice . . . . . . . . . . . . . . . . 1
1.3 Sample Session . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 Getting Your Data and Weights Into R 4
2.1 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2 Getting Data and Weights File Ready . . . . . . . . . . . . . 4
2.2.1 Exporting Data with GeoDa . . . . . . . . . . . . . . 5
2.2.2 Creating the Spatial Weights in GeoDa . . . . . . . . 5
2.3 Creating a Data Frame . . . . . . . . . . . . . . . . . . . . . . 5
2.3.1 Command Line . . . . . . . . . . . . . . . . . . . . . . 5
2.3.2 Writing a Function . . . . . . . . . . . . . . . . . . . . 6
2.4 Creating a Neighbor List from a GAL File . . . . . . . . . . . 7
2.4.1 Using read.gal . . . . . . . . . . . . . . . . . . . . . . 8
2.4.2 Weights Characteristics . . . . . . . . . . . . . . . . . 10
2.5 Creating a Neighbor List from a GWT File . . . . . . . . . . 10
2.5.1 Using read.gwt2nb . . . . . . . . . . . . . . . . . . . . 10
2.5.2 Checking for Symmetry of a Neighbor List . . . . . . 11
2.6 Practice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3 Spatial Autocorrelation Analysis in R 13
3.1 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2 Converting Neighbor Lists to Spatial Weights . . . . . . . . . 13
3.2.1 Example . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.2.2 Practice . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.3 Moran’s I . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.3.1 Normal and Randomization Inference . . . . . . . . . 17
3.3.2 Permutation Inference . . . . . . . . . . . . . . . . . . 20
3.3.3 Plotting the Reference Distribution . . . . . . . . . . . 22
3.3.4 Practice . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.4 Constructing a Spatially Lagged Variable . . . . . . . . . . . 26
3.4.1 Example . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.4.2 Practice . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.5 Moran Scatter Plot . . . . . . . . . . . . . . . . . . . . . . . . 29
3.5.1 Example . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.5.2 Customizing the Moran Scatter Plot . . . . . . . . . . 31
3.5.3 Practice . . . . . . . . . . . . . . . . . . . . . . . . . . 34
4 Monte Carlo Simulation (1)
Assessing the Properties of a Test Statistic 36
4.1 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
4.2 Generating Random Variables . . . . . . . . . . . . . . . . . . 36
4.2.1 Example . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.2.2 Practice . . . . . . . . . . . . . . . . . . . . . . . . . . 38
4.3 Basic Matrix Algebra Operations . . . . . . . . . . . . . . . . 40
4.3.1 Example . . . . . . . . . . . . . . . . . . . . . . . . . . 42
4.3.2 Practice . . . . . . . . . . . . . . . . . . . . . . . . . . 43
4.4 Creating Spatial Weights for a Grid Layout . . . . . . . . . . 44
4.4.1 Example . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.4.2 Practice . . . . . . . . . . . . . . . . . . . . . . . . . . 45
4.5 Converting Spatial Weights to a Matrix . . . . . . . . . . . . 46
4.5.1 Example . . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.5.2 Practice . . . . . . . . . . . . . . . . . . . . . . . . . . 49
4.6 A Simulation Experiment . . . . . . . . . . . . . . . . . . . . 49
4.6.1 Computing Moran’s I Using Matrix Algebra . . . . . . 50
4.6.2 The Theoretical Moments of Moran’s I . . . . . . . . . 51
4.6.3 Inference . . . . . . . . . . . . . . . . . . . . . . . . . 52
4.6.4 Setting up the Experiment . . . . . . . . . . . . . . . 53
4.6.5 The Simulation Loop . . . . . . . . . . . . . . . . . . . 54
4.6.6 Analyzing the Results . . . . . . . . . . . . . . . . . . 55
4.6.7 Practice . . . . . . . . . . . . . . . . . . . . . . . . . . 56
5 Monte Carlo Simulation (2)
Assessing the Properties of an Estimator 60
5.1 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.2 Ordinary Least Squares Regression . . . . . . . . . . . . . . . 60
5.2.1 OLS Using lm . . . . . . . . . . . . . . . . . . . . . . . 61
5.2.2 OLS Matrix Algebra . . . . . . . . . . . . . . . . . . . 62
5.2.3 Example . . . . . . . . . . . . . . . . . . . . . . . . . . 62
5.2.4 Practice . . . . . . . . . . . . . . . . . . . . . . . . . . 66
5.3 Spatial Autoregressive Random Variables . . . . . . . . . . . 67
5.3.1 Example . . . . . . . . . . . . . . . . . . . . . . . . . . 68
5.3.2 Practice . . . . . . . . . . . . . . . . . . . . . . . . . . 68
5.4 Spatial Moving Average Random Variables . . . . . . . . . . 70
5.4.1 Example . . . . . . . . . . . . . . . . . . . . . . . . . . 70
5.4.2 Practice . . . . . . . . . . . . . . . . . . . . . . . . . . 71
5.5 A Simulation Experiment . . . . . . . . . . . . . . . . . . . . 72
5.5.1 Setting up the Experiment . . . . . . . . . . . . . . . 74
5.5.2 Example . . . . . . . . . . . . . . . . . . . . . . . . . . 75
5.5.3 Practice . . . . . . . . . . . . . . . . . . . . . . . . . . 79
6 Spatial Regression in R 80
6.1 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
6.2 Things You Should Know . . . . . . . . . . . . . . . . . . . . 80
6.2.1 Running a Regression . . . . . . . . . . . . . . . . . . 80
6.2.2 Testing OLS Residuals for Spatial Autocorrelation . . 80
6.2.3 ML Estimation of Spatial Lag Model . . . . . . . . . . 81
6.2.4 ML Estimation of Spatial Error Model . . . . . . . . . 81
6.2.5 Testing the Spatial Common Factor Hypothesis . . . . 81
6.3 Practice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Appendix 82
Bibliography 84