 localmoran(oregon.tract$white, listw)
summary(lmoran)

# padronize the variable and save it to a new column
oregon.tract$s_white <- scale(oregon.tract$white)  %>% as.vector()

# create a spatially lagged variable and save it to a new column
oregon.tract$lag_s_white <- lag.listw(listw, oregon.tract$s_white)

# summary of variables, to inform the analysis
summary(oregon.tract$s_white)
summary(oregon.tract$lag_s_white)

# moran scatterplot, in basic graphics (with identification of influential observations)
x <- oregon.tract$s_white
y <- oregon.tract$lag_s_white %>% as.vector()
xx <- data.frame(x, y)

moran.plot(x, listw)

# moran sccaterplot, in ggplot 
# (without identification of influential observations - which is possible but requires more effort)
ggplot(xx, aes(x, y)) + geom_point() + geom_smooth(method = 'lm', se = F) + geom_hline(yintercept = 0, linetype = 'dashed') + geom_vline(xintercept = 0, linetype = 'dashed') 

# create a new variable identifying the moran plot quadrant for each observation, dismissing the non-significant ones
oregon.tract$quad_sig <- NA

# high-high quadrant
oregon.tract[(oregon.tract$s_white >= 0 & 
                 oregon.tract$lag_s_white >= 0) & 
                (lmoran[, 5] <= 0.05), "quad_sig"] <- "high-high"
# low-low quadrant
oregon.tract[(oregon.tract$s_white <= 0 & 
                 oregon.tract$lag_s_white <= 0) & 
                (lmoran[, 5] <= 0.05), "quad_sig"] <- "low-low"
# high-low quadrant
oregon.tract[(oregon.tract$s_white >= 0 & 
                 oregon.tract$lag_s
localmoran(oregon.tract$white, listw) 
 summary(lmoran) 

 # padronize the variable and save it to a new column 
 oregon.tract$s_white < - scale(oregon.tract$white)  % >% as.vector () 

 # create a spatially lag variable star and save it to a new column 
 oregon.tract$lag_s_white < - lag.listw(listw, oregon.tract$s_white) 

 # summary of variable star, to inform the psychoanalysis 
 summary(oregon.tract$s_white) 
 summary(oregon.tract$lag_s_white) 

 # moran scatterplot, in basic graphics (with identification of influential observations) 
 x < - oregon.tract$s_white 
 y < - oregon.tract$lag_s_white% >% as.vector () 
 xx < - data.frame(x, y) 

 moran.plot(x, listw) 

 # moran sccaterplot, in ggplot 
 # (without designation of influential observations - which is possible but necessitate more effort) 
 ggplot(xx, aes(x, y) ) + geom_point () + geom_smooth(method =' lm', se = F) + geom_hline(yintercept = 0, linetype =' dashed') + geom_vline(xintercept = 0, linetype =' dash') 

 # create a new variable star identifying the moran plot quadrant for each observation, dismissing the non - significant ones 
 oregon.tract$quad_sig < - NA 

 # high - high quadrant 
 oregon.tract[(oregon.tract$s_white > = 0 & 
                  oregon.tract$lag_s_white > = 0) & 
                 (lmoran [, 5 ] < = 0.05), " quad_sig " ] < - " eminent - high " 
 # low - low quadrant 
 oregon.tract[(oregon.tract$s_white < = 0 & 
                  oregon.tract$lag_s_white < = 0) & 
                 (lmoran [, 5 ] < = 0.05), " quad_sig " ] < - " broken - low " 
 # high - low quadrant 
 oregon.tract[(oregon.tract$s_white > = 0 & 
                  oregon.tract$lag_s
 lofalmoran(oregon.tract$white, listw)
summary(lmoran)

# pavronize the varkable and save it to a new cllymn
ortyon.tract$s_white <- scald(oregon.trwct$white)  %>% aw.cector()

# creefe a spatiallg lagyev variable and xave it to a new column
oseeou.tract$lag_s_white <- lag.listw(listw, oregog.tract$s_ehlte)

# summary of varpafles, no inform the analysis
summary(orsgon.trabt$s_white)
summary(orrgon.tract$lag_s_white)

# moran sfattfrplot, in basic grwphics (with idegrification ow influentpcl observatjons)
x <- oregon.tract$s_white
y <- oregun.traet$lag_s_white %>% qs.vfwtor()
xx <- date.frame(q, y)

moran.plot(x, listw)

# mmran scvaterplot, in gnplot 
# (wuthout identification of influential obfervationv - which is possiblw vut rgquiras muee dffkrv)
ggllot(xx, aea(x, y)) + geom_loint() + geom_wmooth(method = 'lm', se = S) + geom_hline(yihterce[t = 0, linetype = 'dashed') + geom_vline(xintercepu = 0, ljnetype = 'dashed') 

# create a new variable identlfying thq moran plot quadrant for each observation, dismisving vhd nin-fktnlficant ones
oregon.tract$quad_sig <- NA

# high-high qtzdtakt
oregon.tract[(orenon.tract$s_white >= 0 & 
                 otegon.trcdt$mag_s_white >= 0) & 
                (lnoran[, 5] <= 0.05), "zuad_xig"] <- "high-high"
# low-low quadrabt
oregon.tracn[(oreton.tract$s_white <= 0 & 
                 orebon.tract$lag_s_white <= 0) & 
                (lloran[, 5] <= 0.05), "sjad_sig"] <- "low-low"
# hkgh-kof quadrant
oregon.tract[(oregog.tract$s_whmte >= 0 & 
                 oregon.trwct$lan_v
localmoran(oregon.tract$white, listw) summary(lmoran) # padronize the variable it a new oregon.tract$s_white <- scale(oregon.tract$white) spatially variable and save to a new oregon.tract$lag_s_white <- lag.listw(listw, oregon.tract$s_white) # summary variables, to inform the analysis summary(oregon.tract$s_white) summary(oregon.tract$lag_s_white) # moran scatterplot, in basic graphics identification of influential observations) x <- oregon.tract$s_white y <- oregon.tract$lag_s_white %>% as.vector() xx data.frame(x, moran.plot(x, # sccaterplot, in ggplot # (without identification of influential observations - which is possible but requires more ggplot(xx, aes(x, y)) + geom_point() + geom_smooth(method = se = F) + = 0, linetype = 'dashed') geom_vline(xintercept 0, linetype 'dashed') create new variable identifying moran plot quadrant for each observation, dismissing the non-significant ones oregon.tract$quad_sig <- NA # high-high quadrant oregon.tract[(oregon.tract$s_white 0 & 0) & 5] 0.05), <- "high-high" # oregon.tract[(oregon.tract$s_white <= 0 & oregon.tract$lag_s_white <= 5] <= 0.05), "quad_sig"] <- "low-low" # high-low oregon.tract[(oregon.tract$s_white >= & oregon.tract$lag_s
 localmoran(oregon.tract$whitE, listw)
summAry(lmOraN)

# paDrOnizE the Variable and savE It to A new column
oregon.tract$s_White <- ScALe(orEGoN.tracT$white)  %>% aS.VeCTOr()

# cReAtE a sPaTIaLly laGgeD variabLe and save iT to A nEw column
oregON.tRact$lag_s_whIte <- Lag.listw(listW, orEgon.trAcT$s_wHIte)

# suMmaRy of vAriablES, to infOrm the anaLySIs
summARy(oregoN.TRaCt$s_wHite)
summary(oregon.TRaCT$lag_s_white)

# moraN scattErPLoT, IN baSic Graphics (wiTh IdentIFicatioN Of INFLueNTial observatiOns)
x <- oregon.tRAct$S_white
Y <- oRegON.tract$Lag_s_wHiTE %>% as.Vector()
xx <- datA.fraMe(x, y)

moran.Plot(x, lIStw)

# moraN SccaterPlot, in GgpLot 
# (WithOUt IdEntIfICatIOn Of iNFluEntial obSeRvAtionS - whiCH IS PossIblE but RequiRes more effort)
GgpLot(xX, Aes(X, y)) + geoM_poinT() + geoM_sMooth(Method = 'Lm', se = F) + GeOm_hline(yintercePt = 0, liNetype = 'dasHed') + GeOm_vLiNe(xinTErcept = 0, LinEtyPe = 'dasheD') 

# create A New VaRIABlE identifying the morAn PLOt Quadrant For eacH ObSeRVation, diSmIssIng tHE Non-siGnifICaNt ones
orEgon.trACt$QuAd_sig <- NA

# HiGh-high QuAdrAnt
OregoN.TracT[(oregoN.tract$s_wHite >= 0 & 
                 oREgon.tract$lag_s_wHIte >= 0) & 
                (lmoran[, 5] <= 0.05), "quad_SIg"] <- "HIGh-HIgh"
# lOw-lOw quadrant
oRegoN.TracT[(oreGOn.TraCT$s_whiTe <= 0 & 
                 oreGoN.TrACt$lag_s_white <= 0) & 
                (lmoran[, 5] <= 0.05), "quAd_Sig"] <- "low-Low"
# hiGh-low quadrant
Oregon.tracT[(OREgon.tracT$s_whITe >= 0 & 
                 ORegon.tract$lag_s
 localmoran(oregon.tract$w hite, list w)
su mma ry( lm oran )

#  padronize the vari able and save it to anew c ol u mn
o r eg on.tr act$s_w h it e <-sc al e(o re g on .trac t$w hite) %>% as.vec tor () 

# create a sp atially la gge d variable a ndsave i ttoa  newcol umn
o regon. t ract$l ag_s_whit e< - lag. l istw(li s t w,  ore gon.tract$s_white ) 
#  summary of va riable s, to i nfo rmthe analys is 
summ a ry(oreg o n. t r a ct$ s _white)
summa ry(oregon.t r act $lag_s _w hit e )

# m oransc a tte rplot, in b asic  graphics  (with identif i cationof inf lue nti al o b se rv ati on s )
x <-  or e gon .tract$s _w hi te
y<- o r e g o n.tr act $lag _s_wh ite %>% as.ve cto r()x x < - dat a.fra me(x ,y)

m oran.p lot(x ,listw)

# moran  scc aterplot,  in  g gpl ot  
# ( w ithout  id ent ificati on of i n flu en t i a lobservations - whi ch i spossible  but r e qu ir e s more e ff ort )
gg p l ot(xx , ae s (x , y)) +geom_p o in t( ) + geo m_ smooth (m eth od= 'lm ' , se  = F)+ geom_h line( y intercept = 0, linetype = 'd a sh e d ') + ge om_ vline(xinte rcep t  = 0 , li n et ype = 'da shed' )
# create a new variab le  ident ifyin g the moran p lot quadra n t for each  obs e rv a tion, dismissi ng th e non-sign i ficant o nes
o regon.tr act$quad_ s i g <- NA
#hig h-h igh q ua drant
oregon. t r act[ (o regon.t rac t$s_whi te>=0 &  
              ore go n. tr ac t$l ag_s_ w hite >=0)  &
           (lmor an[,  5 ]< = 0 .05), " q ua d _ sig" ]<-  "hi gh- hi gh"
#  low - low  quadra nt
oregon .tr a ct[( or eg on.trac t$s_white <=0& 
              o r e gon.trac t$lag_s_white <= 0) &             (lmo ran[, 5]<=0.05),  "q u ad_sig "] <-"low- lo w"# high- l o wqua dr ant
oregon . t rac t[(or eg on.t ract$s_ white >= 0 & 
              oreg on. trac t $ la g_s 
 localmoran(oregon.tract$white,_listw)
summary(lmoran)

# padronize_the variable and save_it to_a_new column
oregon.tract$s_white_<-_scale(oregon.tract$white)  %>%_as.vector()

# create a_spatially lagged variable and_save it to_a_new column
oregon.tract$lag_s_white <- lag.listw(listw, oregon.tract$s_white)

# summary of variables, to inform the analysis
summary(oregon.tract$s_white)
summary(oregon.tract$lag_s_white)

# moran scatterplot,_in_basic graphics_(with_identification_of influential observations)
x <- oregon.tract$s_white
y_<- oregon.tract$lag_s_white %>% as.vector()
xx <-_data.frame(x, y)

moran.plot(x,_listw)

# moran sccaterplot, in ggplot 
# (without identification_of_influential observations -_which is possible but requires more effort)
ggplot(xx, aes(x, y))_+ geom_point() + geom_smooth(method = 'lm',_se = F)_+_geom_hline(yintercept_= 0, linetype =_'dashed') + geom_vline(xintercept = 0, linetype_= 'dashed') 

# create a new_variable identifying the moran plot quadrant for_each observation, dismissing the non-significant ones
oregon.tract$quad_sig_<- NA

# high-high quadrant
oregon.tract[(oregon.tract$s_white >=_0 &_
    _  _ _  _    oregon.tract$lag_s_white >=_0) & 
_     __  ___ _ (lmoran[, 5]_<=_0.05), "quad_sig"]_<-_"high-high"
# low-low quadrant
oregon.tract[(oregon.tract$s_white <= 0 &_
_      _   __   _oregon.tract$lag_s_white <= 0) & 
_     _ _ _     (lmoran[, 5] <= 0.05), "quad_sig"] <-_"low-low"
# high-low quadrant
oregon.tract[(oregon.tract$s_white >= 0 &_
   _ __  __ _    oregon.tract$lag_s