楼主: 树袋熊2
4307 4

[书籍介绍] (Michael D,W & Kristian S, G. 2008)Spatial Regression models 和数据集Rcode [推广有奖]

  • 4关注
  • 4粉丝

已卖:464份资源

博士生

3%

还不是VIP/贵宾

-

威望
0
论坛币
336 个
通用积分
3.8492
学术水平
11 点
热心指数
19 点
信用等级
8 点
经验
4585 点
帖子
135
精华
0
在线时间
243 小时
注册时间
2011-3-9
最后登录
2023-9-20

楼主
树袋熊2 发表于 2014-11-11 14:50:17 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
格致方法-定量研究系列丛书之一:空间回归模型(spatial regression models)

Spatial Regression Models
Michael D. Ward Duke University
Kristian Skrede Gleditsch University of Essex, UK
© 2008   112 pages   SAGE Publications, Inc   

Series: Quantitative Applications in the Social Sciences
Volume 155

NOTE: Updated R code for use with this volume, along with other resources, is available at: http://privatewww.essex.ac.uk/~ksg/srm_book.html

Spatial Regression Models
illustrates the use of spatial analysis in the social sciences. The text includes sections that cover different modeling-related topics: mapping and making projections; doing exploratory spatial data analysis; working with models which have lagged endogenous right-handed side variables; using spatial error correction models; employing conditionally autoregressive models; and dealing with over-time panels exhibiting spatial structures. Each of the modeling-based discussions includes separate delineations of how to proceed when dealing with main variables that are quantitative as well as qualitative. In each section, the authors employ prominent and diverse examples, introducing readers to key literature in the field. The examples are presented along with relevant data and programs written in the R, which illustrate exactly how to undertake the analyses described. The book ends with a chapter that covers techniques for presenting spatial information.

Key Features
  • Geared toward social science readers, unlike other volumes on this topic.
  • Illustrates concepts using well-known international, comparative, and national examples of spatial regression analysis.
  • Presents each example alongside relevant data and code, which is also available on a Web site maintained by the authors.

下载(注意是扫描版pdf但通过了文字识别处理):
spatial regression models(Volume 155).rar (35.02 MB, 需要: 3 个论坛币)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:regression regressio Spatial regress Michael Michael 空间 模型

回帖推荐

已有 1 人评分经验 学术水平 热心指数 信用等级 收起 理由
Nicolle + 100 + 5 + 5 + 5 精彩帖子

总评分: 经验 + 100  学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

本帖被以下文库推荐

沙发
lww1993(未真实交易用户) 发表于 2014-11-11 20:47:23
谢谢分享!

藤椅
lonestone(真实交易用户) 在职认证  发表于 2014-11-12 01:38:33 来自手机
树袋熊2 发表于 2014-11-11 14:50
格致方法-定量研究系列丛书之一:空间回归模型(spatial regression models)

Spatial Regression Model ...
good

板凳
东西方咨询(未真实交易用户) 发表于 2014-11-12 11:41:16
  1.                      
  2. #   Kristian Skrede Gleditsch
  3. #   Michael D. Ward
  4. #   ksg@essex.ac.uk
  5. #   mw160@duke.edu
  6. #
  7. #
  8. #   This file contains code to replicate all the examples with R code
  9. #   apparing in the book An Introduction to Spatial Regression
  10. #   Models in the Social Sciences by Michael D. Ward
  11. #   and Kristian Skrede Gleditsch
  12. #
  13. #   This code is "enhanced" and does not always match exactly what
  14. #   is given in the book. In particular, some comments that do not
  15. #   appear in the book have been added to provide additional
  16. #   explanations, and some formatting has been changed. Moreover, we
  17. #   have updated the spatial object processing to be compatible with
  18. #   R version 2.13.2.
  19. #
  20. #   The code assumes that the relevant input files are in
  21. #   the working directory.
  22. #
  23. #   Last revised on 6 November 2012

  24. # Set a working directory
  25. # Use Unix-style  / or \\ for directories in R
  26. dd <- c("C:\\work\\spatialbook\\")
  27. setwd(dd)


  28. ### Replicates code reproduced in Chapter 1

  29. # Ex 1: Plotting map with centroids and capitals

  30. # Load required libraries
  31. # These libraries can be downloaded from the packages menu within R, or
  32. # directly from Cran.
  33. #
  34. # Mac rgdal is now available for OS/X directly via XXXXXXXXXXX

  35. library(RColorBrewer)
  36. library(maptools)
  37. library(spdep)
  38. library(sp)
  39. library(rgdal)

  40. # Read a Robinson projection map from an ESRI shapefile
  41. newprojection <- "+proj=robin +lon_0=0 +x_0=0 +y_0=0"
  42. rob.shp <- readShapeSpatial("wg2002worldmap.shp",proj4string =
  43.     CRS(newprojection),
  44.     IDvar = "FIPS_CNTRY",repair=TRUE,force_ring=TRUE, verbose=TRUE)

  45. # Add coordinates
  46. coords <- coordinates(rob.shp)

  47. # Replot the map itself without a bounding box
  48. plot(rob.shp, border="Grey", forcefill=T,
  49.     xaxt="n", yaxt="n", bty="n",
  50.     lwd=.75, las=1, ylab="",
  51.     main="Centroids and Capitals", xlab="")

  52. # Add the centroids
  53. points(coordinates(rob.shp), pch=19,cex=.25, col="red")

  54. # Latitude and Longitude
  55. ll.mat <- cbind(as.numeric(as.character(rob.shp$Long)),
  56.     as.numeric(as.character(rob.shp$Lat)))
  57. row.names(ll.mat) <- 1:nrow(ll.mat)
  58. llCRS <- CRS("+proj=longlat +ellps+WGS84")
  59. longlat <-  SpatialPoints(ll.mat,proj4string = llCRS)                          

  60. longlat.transf <- spTransform(longlat,
  61.     CRS("+proj=robin +ellps+WGS84+lon_0=0 + x_0=0 +y_0=0"))
  62. points(coordinates(longlat.transf),pch=19,cex=.25,col="black")


  63. # Add segments between centroids and capitals
  64. # but delete Kiribati, as it crosses date line
  65. diffs <- cbind(coordinates(rob.shp),coordinates(longlat.transf))
  66. segments(diffs[-91,1],diffs[-91,2],diffs[-91,3],diffs[-91,4],col="slategray4")


  67. # Ex 2. Spatial correlation test for democracy and development example

  68. # Load data
  69. #
  70. # This archive contains four objects:
  71. #
  72. #   sldv contains the data on democracy, gdp per capita, and population
  73. #   mdd2 contains the minimum distance data
  74. #   nblist is a list of connectivities based on a 200 km threshold
  75. #       (see below for code to generate this)
  76. #   wmat is a row normalized connectivty matrix based on a 200 km threshold
  77. #       (see below for code to generate this)
  78. source("chapter1data.R")

  79. # Estimate OLS
  80. ols1.fit <- glm(democracy ~ log(gdp.2002/population), data=sldv)  

  81. # Load spdep library for moran.test()
  82. library(spdep)

  83. # Moran's I test under randomization
  84. moran.test(resid(ols1.fit),nb2listw(nblist))
  85. # Moran's I test for residuals from a regression model
  86. #   based on weighted residuals
  87. lm.morantest(ols1.fit,nb2listw(nblist))


  88. # Ex. 3 Create a plot of standardized democracy against its spatial lag
  89. #   with regression line and rug added

  90. # Print to a PDF file
  91. # pdffilename <- c("file name and path")
  92. # pdf(file=pdffilename, width = 5.0, height = 5.0,family="Times")

  93. # Extract residuals from OLS regresion
  94. dem <- (resid(ols1.fit))

  95. # Create a standardized democracy variable
  96. ds <- (dem-mean(dem))/sqrt(var(dem))

  97. # Create a spatial lag
  98. ds.slag <- as.vector(wmat%*%ds)

  99. # Standardize spatial lag
  100. ds.slag <- (ds.slag-mean(ds.slag))/sqrt(var(ds.slag))

  101. # Plot democracy against its spatial lag
  102. plot(ds, ds.slag, xlim=c(-3,3), ylim=c(-3,3), pch=20, las=1,
  103.           xlab="standardized democracy",
  104.           ylab="spatial lag of standardized democracy", bty="n")


  105. # Regression of spatial lag of democracy on democracy - slope is the Moran's I
  106. reg1 <- lm(ds.slag~ds)


  107. # Establish a grid for a confidence interval
  108. xgrid <- seq(-3,1.5,length.out=158)
  109. x0 <- list(ds=xgrid)
  110. pred.out <- predict(reg1, x0, interval="confidence")


  111. # Put 1 and 2 sd boxes on the plot
  112. lines( c(-2,-2,+2,+2,-2), c(-2,+2,+2,-2,-2) )
  113. lines( c(-1,-1,+1,+1,-1), c(-1,+1,+1,-1,-1) )
  114. lines( c(-2,+2), c(0,0) )
  115. lines( c(0,0), c(-2,+2) )

  116. # Add some text for context
  117. text(-2.5,3,"(low,high)"); text(2.5,3,"(high,high)")
  118. text(-2.5,-3,"(low,low)"); text(2.5,-3,"(high,low)")
  119. polygon(x=c(-1,0,0,-1), y=c(-1,-1,0,0), col = "slategray3")
  120. polygon(x=c(0,1,1,0), y=c(0,0,1,1), col = "slategray3")

  121. # Plot the c.i. region
  122. polygon(x=c(xgrid, rev(xgrid)),
  123.     y=c(pred.out[,3], rev(pred.out[,2])), col="slategray3", border=T)

  124. # Put the data on the plot
  125. points(ds, ds.slag, pch=20)

  126. # Add densities
  127. sldensity <- density(ds.slag)
  128. lines(sldensity$y+2, sldensity$x, lty=2, col="slategray4")
  129. ddensity <- density(ds)
  130. lines(ddensity$x, ddensity$y+2, lty=2, col="slategray4",xlim=c(-2,2))

  131. # Add regression line to the plot
  132. lines(xgrid, pred.out[,1], type="l", lty=2, col="gray80", lwd=2)

  133. # Add rugs for the data densities on the two sides
  134. rug(jitter(ds, factor=2), col="slategray3")
  135. rug(ds.slag, side=2, col="slategray3")

  136. # Label a group of points explicitly
  137. text(-2., -2.3, "Oil Exporters", col="slategray4")

  138. # Turn off the device, i.e., close PDF file
  139. # dev.off()




  140. # P. 33

  141. # sldv is the data.frame
  142. # mdd2 is the minimum distance data.frame

  143. # Create a neighbor minimum distance matrix
  144. # from the dyadic minimum distance data
  145. # (Note that the cshapes library provides a
  146. # convienent way to create a matrix directly)
  147. mddmat <- matrix(9999,ncol=dim(sldv)[1],nrow=dim(sldv)[1])
  148. dimnames(mddmat) <- list(c(sldv$tla),c(sldv$tla))
  149. for(i in 1:dim(mdd2)[1]){
  150.     mddmat[mdd2$ida[i],mdd2$idb[i]] <-  mdd2$mindist[i]
  151. }

  152. # Create a binary matrix with a 200 km threshold
  153. m200mat <- mddmat
  154. m200mat[m200mat<=200] <- 1
  155. m200mat[m200mat>200] <- 0

  156. # Create a row standardized weights matrix
  157. wmat <- m200mat/apply(m200mat,1,sum)
  158.    
  159. # calculate the spatial lag of democracy
  160. democracy.spatial.lag <- as.vector(wmat%*%sldv$democracy)

  161. # Create a weights list object (a list object is required for spdep)
  162. cmat.lw <- mat2listw(m200mat,
  163.      row.names=row.names(m200mat))

  164. # Extract a neighbor list
  165. cmat.nb <- cmat.lw$neighbours





  166. #### Chapter 2
  167. source("chapter2adata.R")

  168. # P. 47
  169. sldv.fit <- lagsarlm(democracy ~ log(gdp.2002/population),
  170.     data=sldv, nb2listw(cmat.nb), method="eigen", quiet=FALSE)
  171. summary(sldv.fit)
  172. moran.test(resid(sldv.fit),nb2listw(cmat.nb))



  173. # P. 50-52


  174. # Code to calculate equilibrium effect of changes in GDP per capita
  175. # Create vector to store the estimate for each states
  176. ee.est <- rep(NA,dim(sldv)[1])
  177. # Assign the country name labels
  178. names(ee.est) <- sldv$tla
  179. # Create a null vector to use in loop
  180. svec <- rep(0,dim(sldv)[1])
  181. # Create a N x N identity matrix
  182. eye <- matrix(0,nrow=dim(sldv)[1],ncol=dim(sldv)[1])
  183. diag(eye) <- 1
  184. # Loop over 1:n states and store effect of change in
  185. # each state i in ee.est[i]
  186. for(i in 1:length(ee.est)){
  187.     cvec <- svec
  188.     cvec[i] <- 1
  189.     res <- solve(eye - 0.56315 * wmat) %*% cvec * 0.99877
  190.     ee.est[i] <- res[i]
  191. }
  192. # Russia example of impact on other states (observation 120)
  193. cvec <- rep(0,dim(sldv)[1])
  194. cvec[120] <- 1
  195. # Store estimates for impact of change in Russia in rus.est
  196. eye <- matrix(0,nrow=dim(sldv)[1],ncol=dim(sldv)[1])
  197. diag(eye) <- 1
  198. rus.est <- solve(eye - 0.56315 * wmat) %*% cvec*0.99877
  199. # Find ten highest values of rus.est vector
  200. rus.est <- round(rus.est,3)
  201. rus.est <- data.frame(sldv$tla,rus.est)
  202. rus.est[rev(order(rus.est$rus.est)),][1:10,]


  203. # P. 53

  204. # Impact of change in $y$ to 10 in China R code
  205. # China is observation 32
  206. cvec <- rep(0,dim(sldv)[1])
  207. cvec[32] <- 10
  208. # Store estimates of change in China in chn.est
  209. chn.est <- c(cbind (0, 0, wmat%*%cvec) %*%
  210.     c(summary(sldv.fit)$Coef[,1],summary(sldv.fit)$rho))

  211. chn.est <- round(chn.est,3)
  212. # Find all states where non-zero impact
  213. chn.est <- data.frame(sldv$tla,chn.est)




  214. # P. 56-7
  215. shin <- read.csv("italyturnout.csv",sep=",",header=T)
  216. tr <- readShapePoly("turnout",
  217.     IDvar="FID_1", proj4string=CRS("+proj=robin +lon 0=0"))
  218. dnn50km <- dnearneigh(coordinates(tr), 0, 50000)
  219. summary(dnn50km)

  220. # wmat is the weights matrix
  221. wmat <- nb2mat(dnn50km,style="W")


  222. sldv.fit <- lagsarlm(turnout ~ log(gdpcap), data=shin,
  223.     nb2listw(dnn50km), method="eigen", quiet=FALSE)
  224. summary(sldv.fit)


  225. # p. 58-9
  226. # Extract estimated rho
  227. rho <- coef(sldv.fit)[3]
  228. # Extract estimated beta
  229. beta <- coef(sldv.fit)[1:2]
  230. # Create a X matrix
  231. X <- cbind(1,log(shin$gdpcap))

  232. # Create an alternative X matrix, changing value for
  233. # Reggio Calabria-Sbarre (obs 432)
  234. Xs <- X
  235. Xs[432]<- log(35)
  236. # Create an identity matrix
  237. I <- diag(length(shin$gdpcap))
  238. # Find equilibrium effect by looking at
  239. # the difference in expected value for the
  240. # the two X matrices
  241. Ey <- solve(I - rho*wmat)%*%(X%*%beta)
  242. EyS <- solve(I - rho*wmat)%*%(Xs%*%beta)
  243. dif <- EyS-Ey




  244. # P. 61

  245. library(foreign)
  246. library(maptools)
  247. library(network)
  248. library(spdep)
  249. library(sp)
  250. library(rgdal)

  251. setwd(dd)


  252. # read in 2004 presidential votes

  253. presvote <- read.table("2004presvote.csv",sep=",",header=T)

  254. # read in shape files for 48 US States plus District of Columbia
  255. # will create a MAP OBJECT
  256. usa.shp <- readShapeSpatial("48_states.shp") # use equal area projection (Robinson)
  257. usaall <- merge(data.frame(usa.shp), presvote,
  258.     by.x = "STATE_NAME", by.y = "State",
  259.     sort = F)
  260. # Create a distance matrix from original polygon shape file
  261. tr <- readShapePoly("48_states.shp",
  262.     IDvar="ObjectID", proj4string=CRS("+proj=robin +lon 0=0"))
  263. centroids <- coordinates(tr)
  264. # Create Polygons in a SPATIAL OBJECT
  265. us48polys <- Map2poly(usa.shp,
  266.     region.id = as.character(usa.shp$att.data$STATE_NAME))
  267. # Create neighbors, list, and matrix objects from polygon centroids
  268. us48.nb <- poly2nb(us48polys,
  269.     row.names = as.character(usa.shp$att.data$STATE_NAME))
  270. us48.listw <- nb2listw(us48.nb, style = "B")
  271. us48.mat <- (nb2mat(us48.nb, style="B"))
  272. # plots the network among the centroids
  273. colnames(us48.mat) <- rownames(us48.mat) <- usa.shp$att.dat$STATE_ABBR
  274. usa <- network(us48.mat,directed=F)
  275. set.seed(123)
  276. # plot network first; then add state boundaries
  277. plot.network(usa, displayisolates=T, displaylabels=F,
  278.     boxed.labels=F, coord=centroids, label.col="gray20",
  279.     usearrows=F, edge.col=rep("gray60",190),
  280.     vertex.col="gray30", edge.lty=1)
  281. plot(us48polys,bty="n", border="slategray3" ,forcefill =TRUE,xaxt="n",yaxt="n",
  282.    lwd=.000000000125,las=1,ylab="",xlab="",add=T)






  283. # P. 62
  284. library(RColorBrewer)
  285. # now plot the Bush:Kerry vote ratio
  286. bk <- usaall$Bush/usaall$Kerry
  287. # set up five categories and assign colors
  288. breaks <-round(quantile((bk), seq(0,1,1/5), na.rm=TRUE),1)
  289. # cols <- brewer.pal(length(breaks), "Greys")
  290. cols <- brewer.pal(length(breaks), "Greys")
  291. # use findInterval to color states by bk variable
  292. ### KSG again, this will need to be filled out
  293. plot(us48polys, bty="n", border="slategray3", forcefill=TRUE, xaxt="n",
  294.    yaxt="n",lwd=.000000000125,las=1,ylab="",xlab="")
  295. plot(us48polys, bty="n",col=cols[findInterval(bk, breaks, all.inside=T)],
  296.    forcefill=T, add=T)

  297. # P. 69
  298. # data and variables as employed in chapter 2.
  299. sem.fit <- errorsarlm(democracy ~ log(gdp.2002/population), data=sldv,
  300.     nb2listw(cmat.nb), method="eigen", quiet=FALSE)
  301. summary(sem.fit)
  302. logLik(sem.fit)



  303. # P. 78
  304. source("chapter3data_v2.R")
  305. tab3.sem <- errorsarlm(logtrade ~ logdem + logapop + logbpop +
  306.     logargdppc + logbrgdppc + logs + logdist + logmid,
  307.     data=logdat98,na.action=na.omit,
  308.     nb2listw(dlist2,style="W"), method="eigen")
  309. summary(tab3.sem)
  310. logLik(tab3.sem)
复制代码


报纸
qidan8931009(真实交易用户) 发表于 2018-3-7 17:02:36
very helpful!!

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-30 12:54