Question: Use RStudio to answer the questions below. Load the New Haven dataset which contains US Census - derived demographic characteristics of each census block. Here,
Use RStudio to answer the questions below.
Load the New Haven dataset which contains US Censusderived demographic characteristics of each census block. Here, we are interested in measuring spatial autocorrelation in the proportion of residents of each census block who selfidentify as white ie the variable blocks$PWHITE For this variable, you should:
Create a lagged means plot for queens case adjacency rules, and fit a linear regression between PWHITE independent variable and the lagged means dependent variable What does this regression indicate about spatial autocorrelation in the variable PWHITE?
Calculate Morans I using a k nearest neighbors rule for determining adjacency, for each of k Create a plot of k x axis vs Morans I y axis What does your plot suggest about how the spatial autocorrelation of PWHITE changes with how neighboring census blocks are defined?
I started the script for Rstudio and at the end for answering Question is where I am having trouble.
Please see my script for both questions I cannot upload the Rstudio dataset called newhaven
#Load libraries
librarymaptools
libraryspdep
libraryGISTools
librarypgirmess
# Load data
datanewhaven
coords coordinatesblocks # get the centroids of blocks
# Question : Lagged Means Plot and Linear Regression
coords coordinatesblocks # get the centroids of blocks
#Choropleth
parmfrowc
choroplethblocks blocks$PCTOWNHOME
#Introducing the nb objects and queen's case adjacency rule
polynb
nbqueen polynbblocks
plotblocks
plotnbqueen, coords, addT pch col"red"
#rook's case adjacency rule
nbrook polynbblocks queenF
plotblocks
plotnbrook, coords, addT pch col"blue"
#Plotting queen and rook side by side
parmfrowc
plotblocks
plotnbqueen, coords, addT pch col"red"
plotblocks
plotnbrook, coords, addT pch col"blue"
#Creating a nb object from finding the k nearest polygons centroids as neighbors
IDs row.namesasblocks "data.frame"
nbk knnnbknearneighcoords k row.namesIDs
plotblocks
plotnbk coords, addT pch col"red"
#k nearest neighbors
nbk knnnbknearneighcoords k row.namesIDs
nbk knnnbknearneighcoords k row.namesIDs
nbk knnnbknearneighcoords k row.namesIDs
parmfrowc
plotblocks
plotnbk coords, addT pch col"red"
plotblocks
plotnbk coords, addT pch col"purple"
plotblocks
plotnbk coords, addT pch col"green"
plotblocks
plotnbk coords, addT pch col"gold"
#To determine neighbors based on distance itself, use the function dnearneigh to find neighbors between distance d and d
nbd dnearneighcoords d d row.namesIDs
nbd dnearneighcoords d d row.namesIDs
nbd dnearneighcoords d d row.namesIDs
nbd dnearneighcoords d d row.namesIDs
plotblocks
plotnbd coords, addT pch col"red"
plotblocks
plotnbd coords, addT pch col"blue"
plotblocks
plotnbd coords, addT pch col"green"
plotblocks
plotnbd coords, addT pch col"gold"
#Spatial autocorrelation
parmfrowc
choroplethblocks blocks$PCTOWNHOME
#Lagged plot
# Calculate lagged means
lwqueen nblistwnbqueen, style W
lagged.means lag.listwlwqueen, blocks$PWHITE
plotlaggedmeans, blocks$PWHITE, xlab "Lagged Means", ylab PWHITE"
ablinelmblocks$PWHITE ~ lagged.means col "red"
#Question
# Calculate Moran's I using k nearest neighbors rule
k c:
estimates repNA
for i in :
lwk knnnbknearneighcoords k i row.names row.namesblocks # create spatial weights with k nearest neighbors rule
estimatesi asnumericmorantestblocks$PWHITE, lwk$estimate # extract Moran's I
# Develop a plot of k vs Moran's I
plotk estimates, type b main "Moran's I vs k xlab k ylab "Moran's I"
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
