R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("spdep-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('spdep') Loading required package: tripack Loading required package: maptools Loading required package: foreign Loading required package: SparseM [1] "SparseM library loaded" > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "EBImoran.mc" > > ### * EBImoran.mc > > flush(stderr()); flush(stdout()) > > ### Encoding: latin1 > > ### Name: EBImoran.mc > ### Title: Permutation test for empirical Bayes index > ### Aliases: EBImoran.mc EBImoran > ### Keywords: spatial > > ### ** Examples > > data(nc.sids) > EBImoran.mc(spNamedVec("SID74", nc.sids), spNamedVec("BIR74", nc.sids), + nb2listw(ncCC89.nb, style="B", zero.policy=TRUE), nsim=999, + zero.policy=TRUE) Monte-Carlo simulation of Empirical Bayes Index data: cases: spNamedVec("SID74", nc.sids), risk population: spNamedVec("BIR74", nc.sids) weights: nb2listw(ncCC89.nb, style = "B", zero.policy = TRUE) number of simulations + 1: 1000 statistic = 0.254, observed rank = 1000, p-value = 0.001 alternative hypothesis: greater > sids.p <- nc.sids$SID74 / nc.sids$BIR74 > names(sids.p) <- rownames(nc.sids) > moran.mc(sids.p, nb2listw(ncCC89.nb, style="B", zero.policy=TRUE), + nsim=999, zero.policy=TRUE) Monte-Carlo simulation of Moran's I data: sids.p weights: nb2listw(ncCC89.nb, style = "B", zero.policy = TRUE) number of simulations + 1: 1000 statistic = 0.2133, observed rank = 999, p-value = 0.001 alternative hypothesis: greater > > > > cleanEx(); ..nameEx <- "EBest" > > ### * EBest > > flush(stderr()); flush(stdout()) > > ### Name: EBest > ### Title: Global Empirical Bayes estimator > ### Aliases: EBest > ### Keywords: spatial > > ### ** Examples > > data(auckland) > res <- EBest(auckland$Deaths.1977.85, 9*auckland$Under.5.1981) > attr(res, "parameters") $a [1] 7.284173e-07 $b [1] 0.002633436 > cols <- grey(6:2/7) > brks <- c(-Inf,2,2.5,3,3.5,Inf) > library(maptools) > plot(auckpolys, col=cols[findInterval(res$estmm*1000, brks)], forcefill=FALSE) > legend(c(70,90), c(70,95), fill=cols, legend=leglabs(brks), bty="n") > title(main="Global moment estimator of infant mortality per 1000 per year") > > > > cleanEx(); ..nameEx <- "EBlocal" > > ### * EBlocal > > flush(stderr()); flush(stdout()) > > ### Name: EBlocal > ### Title: Local Empirical Bayes estimator > ### Aliases: EBlocal > ### Keywords: spatial > > ### ** Examples > > data(auckland) > res <- EBlocal(spNamedVec("Deaths.1977.85", auckland), + 9*spNamedVec("Under.5.1981", auckland), auckland.nb) > brks <- c(-Inf,2,2.5,3,3.5,Inf) > cols <- grey(6:2/7) > library(maptools) > plot(auckpolys, col=cols[findInterval(res$est*1000, brks)], forcefill=FALSE) > legend(c(70,90), c(70,95), fill=cols, legend=leglabs(brks), bty="n") > title(main="Local moment estimator of infant mortality per 1000 per year") > > > > cleanEx(); ..nameEx <- "LR.sarlm" > > ### * LR.sarlm > > flush(stderr()); flush(stdout()) > > ### Name: LR.sarlm > ### Title: Likelihood ratio test > ### Aliases: LR.sarlm LR1.sarlm Wald1.sarlm logLik.sarlm > ### Keywords: spatial > > ### ** Examples > > data(columbus) > mixed <- lagsarlm(CRIME ~ HOVAL + INC, data=columbus, nb2listw(col.gal.nb), + type="mixed") > error <- errorsarlm(CRIME ~ HOVAL + INC, data=columbus, nb2listw(col.gal.nb)) > LR.sarlm(mixed, error) Likelihood ratio for spatial linear models data: Likelihood ratio = 4.2782, df = 2, p-value = 0.1178 sample estimates: Log likelihood of mixed Log likelihood of error -182.0161 -184.1552 > > > > cleanEx(); ..nameEx <- "afcon" > > ### * afcon > > flush(stderr()); flush(stdout()) > > ### Name: afcon > ### Title: Spatial patterns of conflict in Africa 1966-78 > ### Aliases: afcon africa.rook.nb afxy paper.nb > ### Keywords: datasets > > ### ** Examples > > data(afcon) > plot(africa.rook.nb, afxy) > plot(diffnb(paper.nb, africa.rook.nb), afxy, col="red", add=TRUE) Neighbour difference for region id: MO in relation to id: MR Neighbour difference for region id: MR in relation to id: MO Neighbour difference for region id: CG in relation to id: TZ Neighbour difference for region id: TZ in relation to id: CG Neighbour difference for region id: AO in relation to id: SF Neighbour difference for region id: ZA in relation to id: BC SF Neighbour difference for region id: BC in relation to id: ZA Neighbour difference for region id: SF in relation to id: AO ZA > text(afxy, labels=attr(africa.rook.nb, "region.id"), pos=4, offset=0.4) > moran.test(spNamedVec("totcon", afcon), nb2listw(africa.rook.nb)) Moran's I test under randomisation data: spNamedVec("totcon", afcon) weights: nb2listw(africa.rook.nb) Moran I statistic standard deviate = 4.1251, p-value = 1.853e-05 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.40981723 -0.02439024 0.01107950 > moran.test(spNamedVec("totcon", afcon), nb2listw(paper.nb)) Moran's I test under randomisation data: spNamedVec("totcon", afcon) weights: nb2listw(paper.nb) Moran I statistic standard deviate = 4.3485, p-value = 6.854e-06 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.41679563 -0.02439024 0.01029358 > geary.test(spNamedVec("totcon", afcon), nb2listw(paper.nb)) Geary's C test under randomisation data: spNamedVec("totcon", afcon) weights: nb2listw(paper.nb) Geary C statistic standard deviate = -2.8988, p-value = 0.001873 alternative hypothesis: less sample estimates: Geary C statistic Expectation Variance 0.58395772 1.00000000 0.02059931 > > > > cleanEx(); ..nameEx <- "anova.sarlm" > > ### * anova.sarlm > > flush(stderr()); flush(stdout()) > > ### Name: anova.sarlm > ### Title: Comparison of simultaneous autoregressive models > ### Aliases: anova.sarlm > ### Keywords: spatial > > ### ** Examples > > data(columbus) > lm.mod <- lm(CRIME ~ HOVAL + INC, data=columbus) > lag <- lagsarlm(CRIME ~ HOVAL + INC, data=columbus, nb2listw(col.gal.nb)) > mixed <- lagsarlm(CRIME ~ HOVAL + INC, data=columbus, nb2listw(col.gal.nb), + type="mixed") > error <- errorsarlm(CRIME ~ HOVAL + INC, data=columbus, nb2listw(col.gal.nb)) > LR.sarlm(mixed, error) Likelihood ratio for spatial linear models data: Likelihood ratio = 4.2782, df = 2, p-value = 0.1178 sample estimates: Log likelihood of mixed Log likelihood of error -182.0161 -184.1552 > anova(lag, lm.mod) Model df AIC logLik Test L.Ratio p-value lag 1 5 376.3366 -183.1683 NA NA lm.mod 2 4 382.7545 -187.3772 1 vs 2 8.417918 0.003715411 > anova(lag, error, mixed) Model df AIC logLik Test L.Ratio p-value lag 1 5 376.3366 -183.1683 NA NA error 2 5 378.3104 -184.1552 NA NA mixed 3 7 378.0322 -182.0161 2 vs 3 4.278176 0.1177622 > AIC(lag, error, mixed) df AIC lag 5 376.3366 error 5 378.3104 mixed 7 378.0322 > > > > cleanEx(); ..nameEx <- "asMatrixCsrListw" > > ### * asMatrixCsrListw > > flush(stderr()); flush(stdout()) > > ### Name: asMatrixCsrListw > ### Title: Convert spatial weights list to CSR matrix form > ### Aliases: asMatrixCsrListw asListwMatrixCsr asMatrixCsrIrW asMatrixCsrI > ### Keywords: spatial > > ### ** Examples > > data(oldcol) > COL.W <- nb2listw(COL.nb, style="W") > COL.W Characteristics of weights list object: Neighbour list object: Number of regions: 49 Number of nonzero links: 232 Percentage nonzero weights: 9.66264 Average number of links: 4.734694 Weights style: W Weights constants summary: n nn S0 S1 S2 W 49 2401 49 23.29434 204.8729 > image(asMatrixCsrListw(COL.W)) > > > > cleanEx(); ..nameEx <- "baltimore" > > ### * baltimore > > flush(stderr()); flush(stdout()) > > ### Name: baltimore > ### Title: House sales prices, Baltimore, MD 1978 > ### Aliases: baltimore > ### Keywords: datasets > > ### ** Examples > > data(baltimore) > ## maybe str(baltimore) ; plot(baltimore) ... > > > > cleanEx(); ..nameEx <- "boston" > > ### * boston > > flush(stderr()); flush(stdout()) > > ### Name: boston > ### Title: Corrected Boston Housing Data > ### Aliases: boston.c boston boston.soi boston.utm > ### Keywords: datasets > > ### ** Examples > > data(boston) > hr0 <- lm(log(MEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) + + AGE + log(DIS) + log(RAD) + TAX + PTRATIO + B + log(LSTAT), data=boston.c) > summary(hr0) Call: lm(formula = log(MEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) + AGE + log(DIS) + log(RAD) + TAX + PTRATIO + B + log(LSTAT), data = boston.c) Residuals: Min 1Q Median 3Q Max -0.71176 -0.09169 -0.00566 0.09895 0.79780 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 4.558e+00 1.544e-01 29.512 < 2e-16 *** CRIM -1.186e-02 1.245e-03 -9.532 < 2e-16 *** ZN 8.016e-05 5.056e-04 0.159 0.874105 INDUS 2.395e-04 2.364e-03 0.101 0.919318 CHAS1 9.140e-02 3.320e-02 2.753 0.006129 ** I(NOX^2) -6.380e-01 1.131e-01 -5.639 2.88e-08 *** I(RM^2) 6.328e-03 1.312e-03 4.823 1.89e-06 *** AGE 9.074e-05 5.263e-04 0.172 0.863179 log(DIS) -1.913e-01 3.339e-02 -5.727 1.78e-08 *** log(RAD) 9.571e-02 1.913e-02 5.002 7.91e-07 *** TAX -4.203e-04 1.227e-04 -3.426 0.000664 *** PTRATIO -3.112e-02 5.013e-03 -6.208 1.14e-09 *** B 3.637e-04 1.031e-04 3.527 0.000460 *** log(LSTAT) -3.712e-01 2.501e-02 -14.841 < 2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.1825 on 492 degrees of freedom Multiple R-Squared: 0.8059, Adjusted R-squared: 0.8008 F-statistic: 157.1 on 13 and 492 DF, p-value: < 2.2e-16 > logLik(hr0) 'log Lik.' 149.9548 (df=15) > gp0 <- lm(log(CMEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) + + AGE + log(DIS) + log(RAD) + TAX + PTRATIO + B + log(LSTAT), data=boston.c) > summary(gp0) Call: lm(formula = log(CMEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) + AGE + log(DIS) + log(RAD) + TAX + PTRATIO + B + log(LSTAT), data = boston.c) Residuals: Min 1Q Median 3Q Max -0.70893 -0.09295 -0.01049 0.09575 0.79618 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 4.562e+00 1.523e-01 29.955 < 2e-16 *** CRIM -1.177e-02 1.228e-03 -9.590 < 2e-16 *** ZN 9.175e-05 4.987e-04 0.184 0.854085 INDUS 1.789e-04 2.331e-03 0.077 0.938846 CHAS1 9.213e-02 3.274e-02 2.813 0.005097 ** I(NOX^2) -6.372e-01 1.116e-01 -5.711 1.95e-08 *** I(RM^2) 6.255e-03 1.294e-03 4.833 1.80e-06 *** AGE 7.100e-05 5.190e-04 0.137 0.891253 log(DIS) -1.978e-01 3.293e-02 -6.007 3.67e-09 *** log(RAD) 8.957e-02 1.887e-02 4.746 2.72e-06 *** TAX -4.191e-04 1.210e-04 -3.464 0.000579 *** PTRATIO -2.960e-02 4.944e-03 -5.986 4.14e-09 *** B 3.611e-04 1.017e-04 3.551 0.000421 *** log(LSTAT) -3.749e-01 2.466e-02 -15.200 < 2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.1799 on 492 degrees of freedom Multiple R-Squared: 0.8108, Adjusted R-squared: 0.8058 F-statistic: 162.1 on 13 and 492 DF, p-value: < 2.2e-16 > logLik(gp0) 'log Lik.' 156.9788 (df=15) > lm.morantest(hr0, nb2listw(boston.soi)) Global Moran's I for regression residuals data: model: lm(formula = log(MEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) + AGE + log(DIS) + log(RAD) + TAX + PTRATIO + B + log(LSTAT), data = boston.c) weights: nb2listw(boston.soi) Moran I statistic standard deviate = 14.5085, p-value < 2.2e-16 alternative hypothesis: greater sample estimates: Observed Moran's I Expectation Variance 0.4364296993 -0.0168870829 0.0009762383 > gp1 <- errorsarlm(log(CMEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) + + AGE + log(DIS) + log(RAD) + TAX + PTRATIO + B + log(LSTAT), + data=boston.c, nb2listw(boston.soi), method="SparseM", + tol.opt = .Machine$double.eps^(1/4)) > summary(gp1) Call:errorsarlm(formula = log(CMEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) + AGE + log(DIS) + log(RAD) + TAX + PTRATIO + B + log(LSTAT), data = boston.c, listw = nb2listw(boston.soi), method = "SparseM", tol.opt = .Machine$double.eps^(1/4)) Residuals: Min 1Q Median 3Q Max -6.4315e-01 -6.7098e-02 7.1602e-05 7.5522e-02 6.5017e-01 Type: error Coefficients: (asymptotic standard errors) Estimate Std. Error z value Pr(>|z|) (Intercept) 3.8403e+00 1.5701e-01 24.4594 < 2.2e-16 CRIM -5.2921e-03 9.4259e-04 -5.6145 1.972e-08 ZN 4.7295e-04 5.0495e-04 0.9366 0.348955 INDUS -2.5159e-05 2.7607e-03 -0.0091 0.992729 CHAS1 -3.8824e-02 2.7525e-02 -1.4105 0.158386 I(NOX^2) -2.2283e-01 1.5959e-01 -1.3963 0.162630 I(RM^2) 7.9634e-03 1.0319e-03 7.7174 1.177e-14 AGE -1.0508e-03 4.8725e-04 -2.1566 0.031036 log(DIS) -1.1752e-01 4.7439e-02 -2.4772 0.013242 log(RAD) 6.5538e-02 2.0605e-02 3.1806 0.001470 TAX -4.9962e-04 1.1760e-04 -4.2485 2.152e-05 PTRATIO -1.7664e-02 5.5099e-03 -3.2058 0.001347 B 5.9446e-04 1.0818e-04 5.4952 3.903e-08 log(LSTAT) -2.6595e-01 2.2581e-02 -11.7780 < 2.2e-16 Lambda: 0.71548 LR test value: 224.9 p-value: < 2.22e-16 Log likelihood: 269.4266 for error model ML residual variance (sigma squared): 0.017012, (sigma: 0.13043) Number of observations: 506 Number of parameters estimated: 16 AIC: -506.85, (AIC for lm: -283.96) > gp2 <- lagsarlm(log(CMEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) + + AGE + log(DIS) + log(RAD) + TAX + PTRATIO + B + log(LSTAT), + data=boston.c, nb2listw(boston.soi), method="SparseM") > summary(gp2) Call:lagsarlm(formula = log(CMEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) + AGE + log(DIS) + log(RAD) + TAX + PTRATIO + B + log(LSTAT), data = boston.c, listw = nb2listw(boston.soi), method = "SparseM") Residuals: Min 1Q Median 3Q Max -0.5262308 -0.0749699 -0.0044237 0.0713409 0.7122121 Type: lag Coefficients: (log likelihood/likelihood ratio) Estimate Log likelihood LR statistic Pr(>|z|) (Intercept) 2.2796e+00 NA NA NA CRIM -7.1045e-03 2.3884e+02 50.3390 1.294e-12 ZN 3.7985e-04 2.6352e+02 0.9715 0.3243010 INDUS 1.2572e-03 2.6377e+02 0.4877 0.4849681 CHAS1 7.3677e-03 2.6397e+02 0.0819 0.7746851 I(NOX^2) -2.6892e-01 2.5943e+02 9.1619 0.0024710 I(RM^2) 6.7243e-03 2.4236e+02 43.2951 4.707e-11 AGE -2.7682e-04 2.6377e+02 0.4762 0.4901358 log(DIS) -1.5830e-01 2.4538e+02 37.2542 1.037e-09 log(RAD) 7.0689e-02 2.5252e+02 22.9730 1.643e-06 TAX -3.6569e-04 2.5645e+02 15.1129 0.0001013 PTRATIO -1.2011e-02 2.5940e+02 9.2264 0.0023854 B 2.8432e-04 2.5754e+02 12.9406 0.0003215 log(LSTAT) -2.3216e-01 2.0587e+02 116.2822 < 2.2e-16 Rho: 0.48537 LR test value: 214.06 p-value: < 2.22e-16 Log likelihood: 264.0089 for lag model ML residual variance (sigma squared): 0.019276, (sigma: 0.13884) Number of observations: 506 Number of parameters estimated: 16 AIC: -496.02, (AIC for lm: -283.96) > > > > > cleanEx(); ..nameEx <- "bptest.sarlm" > > ### * bptest.sarlm > > flush(stderr()); flush(stdout()) > > ### Encoding: latin1 > > ### Name: bptest.sarlm > ### Title: Breusch-Pagan test for spatial models > ### Aliases: bptest.sarlm > ### Keywords: spatial > > ### ** Examples > > data(columbus) > error.col <- errorsarlm(CRIME ~ HOVAL + INC, data=columbus, + nb2listw(col.gal.nb)) > bptest.sarlm(error.col) studentized Breusch-Pagan test data: BP = 9.3694, df = 2, p-value = 0.009235 > bptest.sarlm(error.col, studentize=FALSE) Breusch-Pagan test data: BP = 16.2854, df = 2, p-value = 0.0002908 > > > > cleanEx(); ..nameEx <- "card" > > ### * card > > flush(stderr()); flush(stdout()) > > ### Name: card > ### Title: Cardinalities for neighbours lists > ### Aliases: card > ### Keywords: spatial > > ### ** Examples > > data(columbus) > table(card(col.gal.nb)) 2 3 4 5 6 7 8 9 10 7 7 13 4 9 6 1 1 1 > > > > cleanEx(); ..nameEx <- "cell2nb" > > ### * cell2nb > > flush(stderr()); flush(stdout()) > > ### Name: cell2nb > ### Title: Generate neighbours list for grid cells > ### Aliases: cell2nb mrc2vi rookcell queencell vi2mrc > ### Keywords: spatial > > ### ** Examples > > nb7rt <- cell2nb(7, 7) > summary(nb7rt) Neighbour list object: Number of regions: 49 Number of nonzero links: 168 Percentage nonzero weights: 6.997085 Average number of links: 3.428571 Link number distribution: 2 3 4 4 20 25 4 least connected regions: 1:1 7:1 1:7 7:7 with 2 links 25 most connected regions: 2:2 3:2 4:2 5:2 6:2 2:3 3:3 4:3 5:3 6:3 2:4 3:4 4:4 5:4 6:4 2:5 3:5 4:5 5:5 6:5 2:6 3:6 4:6 5:6 6:6 with 4 links > xyc <- attr(nb7rt, "region.id") > xy <- matrix(as.integer(unlist(strsplit(xyc, ":"))), ncol=2, byrow=TRUE) > plot(nb7rt, xy) > nb7rt <- cell2nb(7, 7, torus=TRUE) > summary(nb7rt) Neighbour list object: Number of regions: 49 Number of nonzero links: 196 Percentage nonzero weights: 8.163265 Average number of links: 4 Link number distribution: 4 49 49 least connected regions: 1:1 2:1 3:1 4:1 5:1 6:1 7:1 1:2 2:2 3:2 4:2 5:2 6:2 7:2 1:3 2:3 3:3 4:3 5:3 6:3 7:3 1:4 2:4 3:4 4:4 5:4 6:4 7:4 1:5 2:5 3:5 4:5 5:5 6:5 7:5 1:6 2:6 3:6 4:6 5:6 6:6 7:6 1:7 2:7 3:7 4:7 5:7 6:7 7:7 with 4 links 49 most connected regions: 1:1 2:1 3:1 4:1 5:1 6:1 7:1 1:2 2:2 3:2 4:2 5:2 6:2 7:2 1:3 2:3 3:3 4:3 5:3 6:3 7:3 1:4 2:4 3:4 4:4 5:4 6:4 7:4 1:5 2:5 3:5 4:5 5:5 6:5 7:5 1:6 2:6 3:6 4:6 5:6 6:6 7:6 1:7 2:7 3:7 4:7 5:7 6:7 7:7 with 4 links > > > > cleanEx(); ..nameEx <- "choynowski" > > ### * choynowski > > flush(stderr()); flush(stdout()) > > ### Name: choynowski > ### Title: Choynowski probability map values > ### Aliases: choynowski > ### Keywords: spatial > > ### ** Examples > > data(auckland) > res <- choynowski(auckland$Deaths.1977.85, 9*auckland$Under.5.1981) > res1 <- probmap(auckland$Deaths.1977.85, 9*auckland$Under.5.1981) > table(abs(res$pmap - res1$pmap) < 0.00001, res$type) FALSE TRUE FALSE 74 0 TRUE 0 93 > plot(auckpolys, forcefill=FALSE) > lt005 <- (res$pmap < 0.05) & (res$type) > ge005 <- (res$pmap < 0.05) & (!res$type) > plot(subset(auckpolys, lt005), add=TRUE, col=grey(2/7), forcefill=FALSE) > plot(subset(auckpolys, ge005), add=TRUE, col=grey(5/7), forcefill=FALSE) > legend(c(70,90), c(70,95), fill=grey(c(2,5)/7), + legend=c("low", "high"), bty="n") > > > > cleanEx(); ..nameEx <- "columbus" > > ### * columbus > > flush(stderr()); flush(stdout()) > > ### Name: columbus > ### Title: Columbus OH spatial analysis data set > ### Aliases: columbus col.gal.nb coords polys bbs > ### Keywords: datasets > > ### ** Examples > > data(columbus) > summary(columbus) AREA PERIMETER COLUMBUS. COLUMBUS.I POLYID Min. :0.03438 Min. :0.9021 Min. : 2 Min. : 1 Min. : 1 1st Qu.:0.09315 1st Qu.:1.4023 1st Qu.:14 1st Qu.:13 1st Qu.:13 Median :0.17477 Median :1.8410 Median :26 Median :25 Median :25 Mean :0.18649 Mean :1.8887 Mean :26 Mean :25 Mean :25 3rd Qu.:0.24669 3rd Qu.:2.1992 3rd Qu.:38 3rd Qu.:37 3rd Qu.:37 Max. :0.69926 Max. :5.0775 Max. :50 Max. :49 Max. :49 NEIG HOVAL INC CRIME Min. : 1 Min. :17.90 Min. : 4.477 Min. : 0.1783 1st Qu.:13 1st Qu.:25.70 1st Qu.: 9.963 1st Qu.:20.0485 Median :25 Median :33.50 Median :13.380 Median :34.0008 Mean :25 Mean :38.44 Mean :14.375 Mean :35.1288 3rd Qu.:37 3rd Qu.:43.30 3rd Qu.:18.324 3rd Qu.:48.5855 Max. :49 Max. :96.40 Max. :31.070 Max. :68.8920 OPEN PLUMB DISCBD X Min. : 0.0000 Min. : 0.1327 Min. :0.370 Min. :24.25 1st Qu.: 0.2598 1st Qu.: 0.3323 1st Qu.:1.700 1st Qu.:36.15 Median : 1.0061 Median : 1.0239 Median :2.670 Median :39.61 Mean : 2.7709 Mean : 2.3639 Mean :2.852 Mean :39.46 3rd Qu.: 3.9364 3rd Qu.: 2.5343 3rd Qu.:3.890 3rd Qu.:43.44 Max. :24.9981 Max. :18.8111 Max. :5.570 Max. :51.24 Y AREA NSA NSB Min. :24.96 Min. : 1.093 Min. :0.0000 Min. :0.0000 1st Qu.:28.26 1st Qu.: 3.193 1st Qu.:0.0000 1st Qu.:0.0000 Median :31.91 Median : 6.029 Median :0.0000 Median :1.0000 Mean :32.37 Mean : 6.372 Mean :0.4898 Mean :0.5102 3rd Qu.:35.92 3rd Qu.: 7.989 3rd Qu.:1.0000 3rd Qu.:1.0000 Max. :44.07 Max. :21.282 Max. :1.0000 Max. :1.0000 EW CP THOUS NEIGNO Min. :0.0000 Min. :0.0000 Min. :1000 Min. :1001 1st Qu.:0.0000 1st Qu.:0.0000 1st Qu.:1000 1st Qu.:1013 Median :1.0000 Median :0.0000 Median :1000 Median :1025 Mean :0.5918 Mean :0.4898 Mean :1000 Mean :1025 3rd Qu.:1.0000 3rd Qu.:1.0000 3rd Qu.:1000 3rd Qu.:1037 Max. :1.0000 Max. :1.0000 Max. :1000 Max. :1049 PERIM Min. :0.9021 1st Qu.:1.4023 Median :1.8410 Mean :1.8887 3rd Qu.:2.1992 Max. :5.0775 > > > > cleanEx(); ..nameEx <- "compon" > > ### * compon > > flush(stderr()); flush(stdout()) > > ### Name: Graph Components > ### Title: Depth First Search on Neighbor Lists > ### Aliases: n.comp.nb > ### Keywords: spatial > > ### ** Examples > > data(columbus) > plot(col.gal.nb, coords, col="grey") > col2 <- droplinks(col.gal.nb, 21) > plot(col2, coords, add=TRUE) > res <- n.comp.nb(col2) > table(res$comp.id) 1 2 3 42 1 6 > points(coords, col=res$comp.id, pch=16) > > > > cleanEx(); ..nameEx <- "diffnb" > > ### * diffnb > > flush(stderr()); flush(stdout()) > > ### Name: diffnb > ### Title: Differences between neighbours lists > ### Aliases: diffnb > ### Keywords: spatial > > ### ** Examples > > data(columbus) > knn1 <- knearneigh(coords, 1) > knn2 <- knearneigh(coords, 2) > nb1 <- knn2nb(knn1, row.names=rownames(columbus)) > nb2 <- knn2nb(knn2, row.names=rownames(columbus)) > diffs <- diffnb(nb2, nb1) Neighbour difference for region id: 1005 in relation to id: 1001 Neighbour difference for region id: 1001 in relation to id: 1005 Neighbour difference for region id: 1006 in relation to id: 1002 Neighbour difference for region id: 1002 in relation to id: 1001 Neighbour difference for region id: 1007 in relation to id: 1003 Neighbour difference for region id: 1008 in relation to id: 1007 Neighbour difference for region id: 1004 in relation to id: 1003 Neighbour difference for region id: 1003 in relation to id: 1004 Neighbour difference for region id: 1018 in relation to id: 1008 Neighbour difference for region id: 1010 in relation to id: 1018 Neighbour difference for region id: 1038 in relation to id: 1039 Neighbour difference for region id: 1037 in relation to id: 1039 Neighbour difference for region id: 1039 in relation to id: 1037 Neighbour difference for region id: 1040 in relation to id: 1041 Neighbour difference for region id: 1009 in relation to id: 1032 Neighbour difference for region id: 1036 in relation to id: 1009 Neighbour difference for region id: 1011 in relation to id: 1010 Neighbour difference for region id: 1042 in relation to id: 1041 Neighbour difference for region id: 1041 in relation to id: 1042 Neighbour difference for region id: 1017 in relation to id: 1012 Neighbour difference for region id: 1043 in relation to id: 1044 Neighbour difference for region id: 1019 in relation to id: 1020 Neighbour difference for region id: 1012 in relation to id: 1013 Neighbour difference for region id: 1035 in relation to id: 1041 Neighbour difference for region id: 1032 in relation to id: 1009 Neighbour difference for region id: 1020 in relation to id: 1019 Neighbour difference for region id: 1021 in relation to id: 1019 Neighbour difference for region id: 1031 in relation to id: 1024 Neighbour difference for region id: 1033 in relation to id: 1031 Neighbour difference for region id: 1034 in relation to id: 1030 Neighbour difference for region id: 1045 in relation to id: 1044 Neighbour difference for region id: 1013 in relation to id: 1016 Neighbour difference for region id: 1022 in relation to id: 1023 Neighbour difference for region id: 1044 in relation to id: 1045 Neighbour difference for region id: 1023 in relation to id: 1025 Neighbour difference for region id: 1046 in relation to id: 1049 Neighbour difference for region id: 1030 in relation to id: 1029 Neighbour difference for region id: 1024 in relation to id: 1030 Neighbour difference for region id: 1047 in relation to id: 1046 Neighbour difference for region id: 1016 in relation to id: 1014 Neighbour difference for region id: 1014 in relation to id: 1016 Neighbour difference for region id: 1049 in relation to id: 1046 Neighbour difference for region id: 1029 in relation to id: 1027 Neighbour difference for region id: 1025 in relation to id: 1026 Neighbour difference for region id: 1028 in relation to id: 1029 Neighbour difference for region id: 1048 in relation to id: 1046 Neighbour difference for region id: 1015 in relation to id: 1016 Neighbour difference for region id: 1027 in relation to id: 1026 Neighbour difference for region id: 1026 in relation to id: 1025 > library(maptools) > plot(polys, border="grey", forcefill=FALSE) > plot(nb1, coords, add=TRUE) > plot(diffs, coords, add=TRUE, col="red", lty=2) > title(main="Plot of first (black) and second (red)\nnearest neighbours") > > > > cleanEx(); ..nameEx <- "dnearneigh" > > ### * dnearneigh > > flush(stderr()); flush(stdout()) > > ### Name: dnearneigh > ### Title: Neighbourhood contiguity by distance > ### Aliases: dnearneigh > ### Keywords: spatial > > ### ** Examples > > data(columbus) > k1 <- knn2nb(knearneigh(coords)) > all.linked <- max(unlist(nbdists(k1, coords))) > col.nb.0.all <- dnearneigh(coords, 0, all.linked, row.names=rownames(columbus)) > summary(col.nb.0.all, coords) Neighbour list object: Number of regions: 49 Number of nonzero links: 252 Percentage nonzero weights: 10.49563 Average number of links: 5.142857 Link number distribution: 1 2 3 4 5 6 7 8 9 10 11 4 8 6 2 5 8 6 2 6 1 1 4 least connected regions: 1008 1010 1043 1015 with 1 link 1 most connected region: 1031 with 11 links Summary of link distances: Min. 1st Qu. Median Mean 3rd Qu. Max. 0.1276 0.3608 0.4566 0.4331 0.5224 0.6189 The decimal point is 2 digit(s) to the left of the | 12 | 88 14 | 44 16 | 18 | 7788 20 | 0033 22 | 772277 24 | 4488 26 | 8822 28 | 2244 30 | 00334466 32 | 11114444001188 34 | 0033446633 36 | 1133559900335588 38 | 1133668899003355 40 | 44557777222266 42 | 990022333399 44 | 3322777799 46 | 22223344666677001111225588 48 | 00000011222299 50 | 1122888800557799 52 | 22223333446600 54 | 00333377001133556677 56 | 111133446666 58 | 0022337799 60 | 2299111199 > library(maptools) > plot(polys, border="grey", forcefill=FALSE) > plot(col.nb.0.all, coords, add=TRUE) > title(main=paste("Distance based neighbours 0-", format(all.linked), + " distance units", sep="")) > data(state) > us48.fipsno <- read.geoda(system.file("etc/weights/us48.txt", + package="spdep")[1]) > if (as.numeric(paste(version$major, version$minor, sep="")) < 19) { + m50.48 <- match(us48.fipsno$"State.name", state.name) + } else { + m50.48 <- match(us48.fipsno$"State_name", state.name) + } > xy <- as.matrix(as.data.frame(state.center))[m50.48,] > llk1 <- knn2nb(knearneigh(xy, k=1, lonlat=FALSE)) > all.linked <- max(unlist(nbdists(llk1, xy, lonlat=FALSE))) > ll.nb <- dnearneigh(xy, 0, all.linked, lonlat=FALSE) > summary(ll.nb, xy, lonlat=TRUE, scale=0.5) Neighbour list object: Number of regions: 48 Number of nonzero links: 190 Percentage nonzero weights: 8.246528 Average number of links: 3.958333 Link number distribution: 1 2 3 4 5 7 8 9 10 11 9 4 8 4 4 4 3 1 11 least connected regions: 2 4 8 10 24 26 29 32 35 41 45 with 1 link 1 most connected region: 28 with 10 links Summary of link distances: Min. 1st Qu. Median Mean 3rd Qu. Max. 93.59 293.00 360.10 354.00 448.00 542.40 The decimal point is 2 digit(s) to the right of the | 0 | 99 1 | 00112233 1 | 666699 2 | 00112222334444444444 2 | 667788999999 3 | 000000001111111122222222222233333333334444 3 | 555566666677777788888899999999 4 | 0000001111223344 4 | 555555555555666666777788888888889999 5 | 000000111122334444 > gck1 <- knn2nb(knearneigh(xy, k=1, lonlat=TRUE)) > all.linked <- max(unlist(nbdists(gck1, xy, lonlat=TRUE))) > gc.nb <- dnearneigh(xy, 0, all.linked, lonlat=TRUE) > summary(gc.nb, xy, lonlat=TRUE, scale=0.5) Neighbour list object: Number of regions: 48 Number of nonzero links: 219 Percentage nonzero weights: 9.505208 Average number of links: 4.5625 Non-symmetric neighbours list Link number distribution: 1 2 3 4 5 6 7 8 9 10 6 8 6 8 5 2 3 3 5 2 6 least connected regions: 2 4 8 29 41 45 with 1 link 2 most connected regions: 7 28 with 10 links Summary of link distances: Min. 1st Qu. Median Mean 3rd Qu. Max. 93.59 304.10 378.20 371.10 467.20 523.60 The decimal point is 2 digit(s) to the right of the | 0 | 99 1 | 00112233 1 | 666699 2 | 00112222334444444444 2 | 667788999999 3 | 000000001111111122222222222233333333334444 3 | 555566666677777788888899999999 4 | 00000011112233334444 4 | 55555555555566666666667777888888888888999999 5 | 00000000000000111111112222222222222 > plot(ll.nb, xy) > plot(diffnb(ll.nb, gc.nb), xy, add=TRUE, col="red", lty=2) Neighbour difference for region id: 2 in relation to id: 29 42 Neighbour difference for region id: 5 in relation to id: 42 Neighbour difference for region id: 7 in relation to id: 46 Neighbour difference for region id: 10 in relation to id: 24 35 42 Neighbour difference for region id: 11 in relation to id: 15 20 Neighbour difference for region id: 12 in relation to id: 46 Neighbour difference for region id: 13 in relation to id: 25 Neighbour difference for region id: 14 in relation to id: 23 Neighbour difference for region id: 15 in relation to id: 11 Neighbour difference for region id: 18 in relation to id: 33 Neighbour difference for region id: 19 in relation to id: 36 Neighbour difference for region id: 20 in relation to id: 11 47 Neighbour difference for region id: 21 in relation to id: 32 39 Neighbour difference for region id: 23 in relation to id: 14 34 Neighbour difference for region id: 24 in relation to id: 10 Neighbour difference for region id: 25 in relation to id: 13 Neighbour difference for region id: 26 in relation to id: 42 Neighbour difference for region id: 32 in relation to id: 21 Neighbour difference for region id: 33 in relation to id: 18 36 Neighbour difference for region id: 34 in relation to id: 23 Neighbour difference for region id: 35 in relation to id: 10 Neighbour difference for region id: 36 in relation to id: 19 33 Neighbour difference for region id: 38 in relation to id: 46 Neighbour difference for region id: 39 in relation to id: 21 Neighbour difference for region id: 42 in relation to id: 2 5 10 26 Neighbour difference for region id: 46 in relation to id: 7 12 38 Neighbour difference for region id: 47 in relation to id: 20 > title(main="Differences between Euclidean and Great Circle neighbours") > > > > cleanEx(); ..nameEx <- "droplinks" > > ### * droplinks > > flush(stderr()); flush(stdout()) > > ### Name: droplinks > ### Title: Drop links in a neighbours list > ### Aliases: droplinks > ### Keywords: spatial > > ### ** Examples > > rho <- c(0.2, 0.5, 0.95, 0.999, 1.0) > ns <- c(5, 7, 9, 11, 13, 15, 17, 19) > mns <- matrix(0, nrow=length(ns), ncol=length(rho)) > rownames(mns) <- ns > colnames(mns) <- rho > mxs <- matrix(0, nrow=length(ns), ncol=length(rho)) > rownames(mxs) <- ns > colnames(mxs) <- rho > for (i in 1:length(ns)) { + nblist <- cell2nb(ns[i], ns[i]) + nbdropped <- droplinks(nblist, ((ns[i]*ns[i])+1)/2, sym=FALSE) + listw <- nb2listw(nbdropped, style="W", zero.policy=TRUE) + wmat <- listw2mat(listw) + for (j in 1:length(rho)) { + mat <- diag(ns[i]*ns[i]) - rho[j] * wmat + res <- diag(solve(t(mat) %*% mat)) + mns[i,j] <- mean(res) + mxs[i,j] <- max(res) + } + } > print(mns) 0.2 0.5 0.95 0.999 1 5 1.038271 1.312627 9.486051 30.81487 32.04915 7 1.036443 1.295621 10.899580 83.25437 92.09812 9 1.035356 1.285145 10.798611 160.90951 195.02166 11 1.034639 1.278279 10.383083 254.83998 347.71145 13 1.034132 1.273442 9.968389 353.66366 555.88699 15 1.033753 1.269852 9.619387 447.19245 824.46560 17 1.033460 1.267082 9.337167 528.49015 1157.77630 19 1.033227 1.264879 9.109487 594.23907 1559.69614 > print(mxs) 0.2 0.5 0.95 0.999 1 5 1.048834 1.401934 12.00215 39.22742 40.79967 7 1.048834 1.402174 14.66823 106.90031 118.01556 9 1.048834 1.402176 15.49606 207.28928 249.74893 11 1.048834 1.402176 15.75744 329.22973 443.97194 13 1.048834 1.402176 15.83957 458.75739 707.14827 15 1.048834 1.402176 15.86474 583.50722 1044.75562 17 1.048834 1.402176 15.87225 695.10288 1461.57017 19 1.048834 1.402176 15.87445 789.50575 1961.84025 > > > > > cleanEx(); ..nameEx <- "eigenw" > > ### * eigenw > > flush(stderr()); flush(stdout()) > > ### Name: eigenw > ### Title: Spatial weights matrix eigenvalues > ### Aliases: eigenw > ### Keywords: spatial > > ### ** Examples > > data(oldcol) > W.eig <- eigenw(nb2listw(COL.nb, style="W")) > 1/range(W.eig) [1] -1.536177 1.000000 > S.eig <- eigenw(nb2listw(COL.nb, style="S")) > 1/range(S.eig) [1] -1.7364189 0.8918997 > B.eig <- eigenw(nb2listw(COL.nb, style="B")) > 1/range(B.eig) [1] -0.3229290 0.1692726 > > > > cleanEx(); ..nameEx <- "eire" > > ### * eire > > flush(stderr()); flush(stdout()) > > ### Encoding: latin1 > > ### Name: eire > ### Title: Eire data sets > ### Aliases: eire eire.df eire.polys.utm eire.coords.utm eire.nb > ### Keywords: datasets > > ### ** Examples > > data(eire) > summary(eire.df$A) Min. 1st Qu. Median Mean 3rd Qu. Max. 23.92 27.92 29.26 29.53 30.94 35.86 > brks <- round(fivenum(eire.df$A), digits=2) > cols <- rev(heat.colors(4)) > library(maptools) > plot(eire.polys.utm, + col=cols[findInterval(eire.df$A, brks)], forcefill=FALSE) > title(main="Percentage with blood group A in Eire") > legend(x=c(-50, 70), y=c(6120, 6050), leglabs(brks), fill=cols, bty="n") > plot(eire.polys.utm, forcefill=FALSE) > plot(eire.nb, eire.coords.utm, add=TRUE) > lA <- lag.listw(nb2listw(eire.nb), eire.df$A) > summary(lA) Min. 1st Qu. Median Mean 3rd Qu. Max. 26.08 28.33 29.21 29.64 31.12 33.39 > moran.test(spNamedVec("A", eire.df), nb2listw(eire.nb)) Moran's I test under randomisation data: spNamedVec("A", eire.df) weights: nb2listw(eire.nb) Moran I statistic standard deviate = 4.6851, p-value = 1.399e-06 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.55412382 -0.04000000 0.01608138 > geary.test(spNamedVec("A", eire.df), nb2listw(eire.nb)) Geary's C test under randomisation data: spNamedVec("A", eire.df) weights: nb2listw(eire.nb) Geary C statistic standard deviate = -4.5146, p-value = 3.172e-06 alternative hypothesis: less sample estimates: Geary C statistic Expectation Variance 0.38011971 1.00000000 0.01885309 > cor(lA, eire.df$A) [1] 0.8144345 > moran.plot(spNamedVec("A", eire.df), nb2listw(eire.nb), + labels=rownames(eire.df)) Potentially influential observations of lm(formula = wx ~ x) : dfb.1_ dfb.x dffit cov.r cook.d hat Carlow -0.04 0.04 0.05 1.27_* 0.00 0.14 Cork 0.97 -0.93 1.04_* 0.92 0.47 0.19 Limerick -0.26 0.21 -0.52 0.74_* 0.11 0.05 Wexford 0.05 -0.06 -0.06 1.41_* 0.00 0.23 Wicklow -0.19 0.19 0.22 1.35_* 0.02 0.21 > A.lm <- lm(A ~ towns + pale, data=eire.df) > summary(A.lm) Call: lm(formula = A ~ towns + pale, data = eire.df) Residuals: Min 1Q Median 3Q Max -3.6420 -1.0340 -0.3428 1.0263 4.0460 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 27.5728 0.5448 50.614 < 2e-16 *** towns -0.3595 2.9672 -0.121 0.904610 pale 4.3419 1.0851 4.001 0.000561 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 2.018 on 23 degrees of freedom Multiple R-Squared: 0.5551, Adjusted R-squared: 0.5164 F-statistic: 14.35 on 2 and 23 DF, p-value: 9.014e-05 > res <- residuals(A.lm) > brks <- c(min(res),-2,-1,0,1,2,max(res)) > cols <- rev(cm.colors(6)) > plot(eire.polys.utm, col=cols[findInterval(res, brks)], forcefill=FALSE) > title(main="Regression residuals") > legend(x=c(-50, 70), y=c(6120, 6050), legend=leglabs(brks), fill=cols, + bty="n") > lm.morantest(A.lm, nb2listw(eire.nb)) Global Moran's I for regression residuals data: model: lm(formula = A ~ towns + pale, data = eire.df) weights: nb2listw(eire.nb) Moran I statistic standard deviate = 1.8003, p-value = 0.03591 alternative hypothesis: greater sample estimates: Observed Moran's I Expectation Variance 0.15085317 -0.06845969 0.01484007 > lm.morantest.sad(A.lm, nb2listw(eire.nb)) Saddlepoint approximation for global Moran's I (Barndorff-Nielsen formula) data: model:lm(formula = A ~ towns + pale, data = eire.df) weights: nb2listw(eire.nb) Saddlepoint approximation = 1.7284, p-value = 0.04196 alternative hypothesis: greater sample estimates: Observed Moran's I 0.1508532 > lm.LMtests(A.lm, nb2listw(eire.nb), test="LMerr") Lagrange multiplier diagnostics for spatial dependence data: model: lm(formula = A ~ towns + pale, data = eire.df) weights: nb2listw(eire.nb) LMerr = 1.1634, df = 1, p-value = 0.2808 > brks <- round(fivenum(eire.df$OWNCONS), digits=2) > cols <- grey(4:1/5) > plot(eire.polys.utm, + col=cols[findInterval(eire.df$OWNCONS, brks)], forcefill=FALSE) > title(main="Percentage own consumption of agricultural produce") > legend(x=c(-50, 70), y=c(6120, 6050), legend=leglabs(brks), + fill=cols, bty="n") > moran.plot(spNamedVec("OWNCONS", eire.df), nb2listw(eire.nb)) Potentially influential observations of lm(formula = wx ~ x) : dfb.1_ dfb.x dffit cov.r cook.d hat Donegal -0.02 0.03 0.04 1.33_* 0.00 0.18 Kerry -0.04 -0.21 -0.62 0.62_* 0.15 0.04 Mayo 0.59 -0.79 -0.85 1.23 0.35 0.26_* Sligo -0.43 0.77 1.02_* 0.56_* 0.37 0.09 > moran.test(spNamedVec("OWNCONS", eire.df), nb2listw(eire.nb)) Moran's I test under randomisation data: spNamedVec("OWNCONS", eire.df) weights: nb2listw(eire.nb) Moran I statistic standard deviate = 5.8637, p-value = 2.263e-09 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.71281837 -0.04000000 0.01648309 > e.lm <- lm(OWNCONS ~ ROADACC, data=eire.df) > res <- residuals(e.lm) > brks <- c(min(res),-2,-1,0,1,2,max(res)) > cols <- rev(cm.colors(6)) > plot(eire.polys.utm, col=cols[findInterval(res, brks)], forcefill=FALSE) > title(main="Regression residuals") > legend(x=c(-50, 70), y=c(6120, 6050), legend=leglabs(brks), fill=cm.colors(6), + bty="n") > lm.morantest(e.lm, nb2listw(eire.nb)) Global Moran's I for regression residuals data: model: lm(formula = OWNCONS ~ ROADACC, data = eire.df) weights: nb2listw(eire.nb) Moran I statistic standard deviate = 3.2575, p-value = 0.0005619 alternative hypothesis: greater sample estimates: Observed Moran's I Expectation Variance 0.33660565 -0.05877741 0.01473183 > lm.morantest.sad(e.lm, nb2listw(eire.nb)) Saddlepoint approximation for global Moran's I (Barndorff-Nielsen formula) data: model:lm(formula = OWNCONS ~ ROADACC, data = eire.df) weights: nb2listw(eire.nb) Saddlepoint approximation = 2.9395, p-value = 0.001644 alternative hypothesis: greater sample estimates: Observed Moran's I 0.3366057 > lm.LMtests(e.lm, nb2listw(eire.nb), test="LMerr") Lagrange multiplier diagnostics for spatial dependence data: model: lm(formula = OWNCONS ~ ROADACC, data = eire.df) weights: nb2listw(eire.nb) LMerr = 5.7925, df = 1, p-value = 0.01609 > print(localmoran.sad(e.lm, eire.nb, select=1:nrow(eire.df))) Local Morans I Saddlepoint Pr. (Sad) 1 Carlow 0.216996683 0.95074844 1.708660e-01 2 Cavan -0.372573613 -1.00603119 8.427997e-01 3 Clare 0.231975105 0.67166518 2.508984e-01 4 Cork 0.781935479 1.74761575 4.026529e-02 5 Donegal -1.690640590 -1.72031078 9.573120e-01 6 Dublin -0.160696921 -0.35212627 6.376282e-01 7 Galway 1.313714727 2.66849536 3.809592e-03 8 Kerry 0.365348659 0.78073279 2.174798e-01 9 Kildare -0.025575445 0.04167665 4.833782e-01 10 Kilkenny 0.576843308 1.70897697 4.372761e-02 11 Laoghis -0.059517978 -0.12155465 5.483741e-01 12 Leitrim 0.384845866 1.47227033 7.047395e-02 13 Limerick 0.118179867 0.45727712 3.237359e-01 14 Longford 1.416432004 2.51113769 6.017137e-03 15 Louth 0.562429203 1.07441571 1.413182e-01 16 Mayo 0.875727038 2.05251226 2.005995e-02 17 Meath 0.003678560 0.12813539 4.490209e-01 18 Monaghan 0.550983111 1.23999193 1.074892e-01 19 Offaly 0.151555560 0.80786519 2.095841e-01 20 Roscommon 2.043688390 4.53187292 2.923151e-06 21 Sligo -0.475798710 -0.94578114 8.278699e-01 22 Tipperary -0.034541063 -0.06919691 5.275836e-01 23 Waterford 0.857234228 1.91385108 2.781959e-02 24 Westmeath 0.451385718 1.36017204 8.688774e-02 25 Wexford 0.643718339 1.63188492 5.135187e-02 26 Wicklow 0.024419502 0.21197000 4.160652e-01 > > > > cleanEx(); ..nameEx <- "errorsarlm" > > ### * errorsarlm > > flush(stderr()); flush(stdout()) > > ### Name: errorsarlm > ### Title: Spatial simultaneous autoregressive error model estimation > ### Aliases: errorsarlm > ### Keywords: spatial > > ### ** Examples > > data(oldcol) > COL.errW.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, + nb2listw(COL.nb, style="W"), method="eigen", quiet=FALSE) Spatial autoregressive error model Jacobian calculated using neighbourhood matrix eigenvalues Computing eigenvalues ... (eigen) lambda: -0.5674437 function value: -195.8051 (eigen) lambda: 0.03126655 function value: -187.0219 (eigen) lambda: 0.4012898 function value: -183.8422 (eigen) lambda: 0.6299767 function value: -183.4895 (eigen) lambda: 0.5811116 function value: -183.3887 (eigen) lambda: 0.554104 function value: -183.3817 (eigen) lambda: 0.5621834 function value: -183.3805 (eigen) lambda: 0.5617028 function value: -183.3805 (eigen) lambda: 0.5617888 function value: -183.3805 (eigen) lambda: 0.5617902 function value: -183.3805 (eigen) lambda: 0.5617903 function value: -183.3805 (eigen) lambda: 0.5617903 function value: -183.3805 > COL.errW.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, + nb2listw(COL.nb, style="W"), method="eigen", quiet=FALSE) Spatial autoregressive error model Jacobian calculated using neighbourhood matrix eigenvalues Computing eigenvalues ... (eigen) lambda: -0.5674437 function value: -195.8051 (eigen) lambda: 0.03126655 function value: -187.0219 (eigen) lambda: 0.4012898 function value: -183.8422 (eigen) lambda: 0.6299767 function value: -183.4895 (eigen) lambda: 0.5811116 function value: -183.3887 (eigen) lambda: 0.554104 function value: -183.3817 (eigen) lambda: 0.5621834 function value: -183.3805 (eigen) lambda: 0.5617028 function value: -183.3805 (eigen) lambda: 0.5617888 function value: -183.3805 (eigen) lambda: 0.5617902 function value: -183.3805 (eigen) lambda: 0.5617903 function value: -183.3805 (eigen) lambda: 0.5617903 function value: -183.3805 > COL.errB.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, + nb2listw(COL.nb, style="B"), method="eigen", quiet=FALSE) Spatial autoregressive error model Jacobian calculated using neighbourhood matrix eigenvalues Computing eigenvalues ... (eigen) lambda: -0.1349247 function value: -196.5231 (eigen) lambda: -0.01873166 function value: -188.4544 (eigen) lambda: 0.0530796 function value: -184.5803 (eigen) lambda: 0.0974614 function value: -182.6524 (eigen) lambda: 0.1248908 function value: -182.0539 (eigen) lambda: 0.1474059 function value: -182.6008 (eigen) lambda: 0.1229929 function value: -182.0642 (eigen) lambda: 0.1261661 function value: -182.0507 (eigen) lambda: 0.1269409 function value: -182.0502 (eigen) lambda: 0.126872 function value: -182.0502 (eigen) lambda: 0.1268641 function value: -182.0502 (eigen) lambda: 0.1268645 function value: -182.0502 (eigen) lambda: 0.1268645 function value: -182.0502 (eigen) lambda: 0.1268645 function value: -182.0502 (eigen) lambda: 0.1268645 function value: -182.0502 > COL.errW.SM <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, + nb2listw(COL.nb, style="W"), method="SparseM", quiet=FALSE) Spatial autoregressive error model Jacobian calculated using sparse matrix techniques using SparseM (SparseM) lambda: -0.2364499 function value: -190.4287 (SparseM) lambda: 0.2354499 function value: -185.0024 (SparseM) lambda: 0.5271001 function value: -183.4053 (SparseM) lambda: 0.728364 function value: -184.1244 (SparseM) lambda: 0.5304163 function value: -183.4009 (SparseM) lambda: 0.5557478 function value: -183.3812 (SparseM) lambda: 0.6216813 function value: -183.4637 (SparseM) lambda: 0.562713 function value: -183.3805 (SparseM) lambda: 0.5618852 function value: -183.3805 (SparseM) lambda: 0.5617866 function value: -183.3805 (SparseM) lambda: 0.5617903 function value: -183.3805 (SparseM) lambda: 0.5617903 function value: -183.3805 (SparseM) lambda: 0.5617903 function value: -183.3805 (SparseM) lambda: 0.5617903 function value: -183.3805 > summary(COL.errW.eig, correlation=TRUE) Call: errorsarlm(formula = CRIME ~ INC + HOVAL, data = COL.OLD, listw = nb2listw(COL.nb, style = "W"), method = "eigen", quiet = FALSE) Residuals: Min 1Q Median 3Q Max -34.81174 -6.44031 -0.72142 7.61476 23.33626 Type: error Coefficients: (asymptotic standard errors) Estimate Std. Error z value Pr(>|z|) (Intercept) 59.893219 5.366163 11.1613 < 2.2e-16 INC -0.941312 0.330569 -2.8476 0.0044057 HOVAL -0.302250 0.090476 -3.3407 0.0008358 Lambda: 0.56179 LR test value: 7.9935 p-value: 0.0046945 Asymptotic standard error: 0.13387 z-value: 4.1966 p-value: 2.7098e-05 Wald statistic: 17.611 p-value: 2.7098e-05 Log likelihood: -183.3805 for error model ML residual variance (sigma squared): 95.575, (sigma: 9.7762) Number of observations: 49 Number of parameters estimated: 5 AIC: 376.76, (AIC for lm: 382.75) Correlation of Coefficients: sigma lambda (Intercept) INC lambda -0.24 (Intercept) 0.00 0.00 INC 0.00 0.00 -0.56 HOVAL 0.00 0.00 -0.26 -0.45 > summary(COL.errB.eig, correlation=TRUE) Call: errorsarlm(formula = CRIME ~ INC + HOVAL, data = COL.OLD, listw = nb2listw(COL.nb, style = "B"), method = "eigen", quiet = FALSE) Residuals: Min 1Q Median 3Q Max -32.19010 -5.22646 -0.69952 7.92588 24.23511 Type: error Coefficients: (asymptotic standard errors) Estimate Std. Error z value Pr(>|z|) (Intercept) 55.383118 5.449775 10.1625 < 2.2e-16 INC -0.936595 0.319355 -2.9328 0.0033596 HOVAL -0.299857 0.088678 -3.3814 0.0007212 Lambda: 0.12686 LR test value: 10.654 p-value: 0.0010983 Asymptotic standard error: 0.021745 z-value: 5.8342 p-value: 5.4044e-09 Wald statistic: 34.038 p-value: 5.4044e-09 Log likelihood: -182.0502 for error model ML residual variance (sigma squared): 88.744, (sigma: 9.4204) Number of observations: 49 Number of parameters estimated: 5 AIC: 374.1, (AIC for lm: 382.75) Correlation of Coefficients: sigma lambda (Intercept) INC lambda -0.24 (Intercept) 0.00 0.00 INC 0.00 0.00 -0.60 HOVAL 0.00 0.00 -0.30 -0.42 > summary(COL.errW.SM, correlation=TRUE) Call: errorsarlm(formula = CRIME ~ INC + HOVAL, data = COL.OLD, listw = nb2listw(COL.nb, style = "W"), method = "SparseM", quiet = FALSE) Residuals: Min 1Q Median 3Q Max -34.81174 -6.44031 -0.72142 7.61476 23.33626 Type: error Coefficients: (asymptotic standard errors) Estimate Std. Error z value Pr(>|z|) (Intercept) 59.893219 5.366162 11.1613 < 2.2e-16 INC -0.941312 0.330569 -2.8476 0.0044057 HOVAL -0.302250 0.090476 -3.3407 0.0008358 Lambda: 0.56179 LR test value: 7.9935 p-value: 0.0046945 Log likelihood: -183.3805 for error model ML residual variance (sigma squared): 95.575, (sigma: 9.7762) Number of observations: 49 Number of parameters estimated: 5 AIC: 376.76, (AIC for lm: 382.75) > NA.COL.OLD <- COL.OLD > NA.COL.OLD$CRIME[20:25] <- NA > COL.err.NA <- errorsarlm(CRIME ~ INC + HOVAL, data=NA.COL.OLD, + nb2listw(COL.nb), na.action=na.exclude) > COL.err.NA$na.action 1020 1021 1022 1023 1024 1025 20 21 22 23 24 25 attr(,"class") [1] "exclude" > COL.err.NA Call: errorsarlm(formula = CRIME ~ INC + HOVAL, data = NA.COL.OLD, listw = nb2listw(COL.nb), na.action = na.exclude) Type: error Coefficients: (Intercept) INC HOVAL lambda 58.2460530 -0.8473028 -0.3024909 0.5748430 Log likelihood: -161.8763 > resid(COL.err.NA) 1001 1002 1003 1004 1005 1006 -4.18270828 -11.44133862 0.31874929 -34.47163066 2.42244752 -4.32095075 1007 1008 1009 1010 1011 1012 8.66744162 -13.38669925 -1.92276576 17.85753941 -1.11484610 -2.30434795 1013 1014 1015 1016 1017 1018 -8.16935127 -5.80500232 0.14973712 5.93191452 -7.03028248 2.39112833 1019 1020 1021 1022 1023 1024 -8.95099917 NA NA NA NA NA 1025 1026 1027 1028 1029 1030 NA -2.52940719 -9.60025400 -6.95635593 -0.43630587 5.98493684 1031 1032 1033 1034 1035 1036 6.25882674 7.75527043 10.83413248 23.23927265 -0.05594936 1.43808582 1037 1038 1039 1040 1041 1042 9.51995270 12.18295374 8.31031721 17.06834506 7.04418408 7.50088942 1043 1044 1045 1046 1047 1048 -7.78485972 -6.79207465 -7.94977553 -11.25362129 -5.68994642 5.04837380 1049 2.22497376 > > > > cleanEx(); ..nameEx <- "geary" > > ### * geary > > flush(stderr()); flush(stdout()) > > ### Name: geary > ### Title: Compute Geary's C > ### Aliases: geary > ### Keywords: spatial > > ### ** Examples > > data(oldcol) > col.W <- nb2listw(COL.nb, style="W") > str(geary(COL.OLD$CRIME, col.W, length(COL.nb), length(COL.nb)-1, + Szero(col.W))) List of 2 $ C: num 0.53 $ K: num 2.23 > > > > cleanEx(); ..nameEx <- "geary.mc" > > ### * geary.mc > > flush(stderr()); flush(stdout()) > > ### Name: geary.mc > ### Title: Permutation test for Geary's C statistic > ### Aliases: geary.mc > ### Keywords: spatial > > ### ** Examples > > data(oldcol) > sim1 <- geary.mc(spNamedVec("CRIME", COL.OLD), nb2listw(COL.nb, style="W"), + nsim=99, alternative="less") > sim1 Monte-Carlo simulation of Geary's C data: spNamedVec("CRIME", COL.OLD) weights: nb2listw(COL.nb, style = "W") number of simulations + 1: 100 statistic = 0.5299, observed rank = 1, p-value = 0.01 alternative hypothesis: less > mean(sim1$res) [1] 0.9899218 > var(sim1$res) [1] 0.008075363 > summary(sim1$res) Min. 1st Qu. Median Mean 3rd Qu. Max. 0.5299 0.9419 0.9904 0.9899 1.0450 1.1740 > colold.lags <- nblag(COL.nb, 3) > sim2 <- geary.mc(spNamedVec("CRIME", COL.OLD), nb2listw(colold.lags[[2]], + style="W"), nsim=99) > sim2 Monte-Carlo simulation of Geary's C data: spNamedVec("CRIME", COL.OLD) weights: nb2listw(colold.lags[[2]], style = "W") number of simulations + 1: 100 statistic = 0.8113, observed rank = 1, p-value = 0.01 alternative hypothesis: less > summary(sim2$res) Min. 1st Qu. Median Mean 3rd Qu. Max. 0.8113 0.9398 1.0010 0.9954 1.0400 1.1530 > sim3 <- geary.mc(spNamedVec("CRIME", COL.OLD), nb2listw(colold.lags[[3]], + style="W"), nsim=99) > sim3 Monte-Carlo simulation of Geary's C data: spNamedVec("CRIME", COL.OLD) weights: nb2listw(colold.lags[[3]], style = "W") number of simulations + 1: 100 statistic = 1.1303, observed rank = 96, p-value = 0.96 alternative hypothesis: less > summary(sim3$res) Min. 1st Qu. Median Mean 3rd Qu. Max. 0.7883 0.9357 0.9938 0.9900 1.0340 1.1900 > > > > cleanEx(); ..nameEx <- "geary.test" > > ### * geary.test > > flush(stderr()); flush(stdout()) > > ### Name: geary.test > ### Title: Geary's C test for spatial autocorrelation > ### Aliases: geary.test > ### Keywords: spatial > > ### ** Examples > > data(oldcol) > geary.test(spNamedVec("CRIME", COL.OLD), nb2listw(COL.nb, style="W")) Geary's C test under randomisation data: spNamedVec("CRIME", COL.OLD) weights: nb2listw(COL.nb, style = "W") Geary C statistic standard deviate = -4.7605, p-value = 9.655e-07 alternative hypothesis: less sample estimates: Geary C statistic Expectation Variance 0.52986993 1.00000000 0.00975278 > geary.test(spNamedVec("CRIME", COL.OLD), nb2listw(COL.nb, style="W"), + randomisation=FALSE) Geary's C test under normality data: spNamedVec("CRIME", COL.OLD) weights: nb2listw(COL.nb, style = "W") Geary C statistic standard deviate = -4.6388, p-value = 1.752e-06 alternative hypothesis: less sample estimates: Geary C statistic Expectation Variance 0.52986993 1.00000000 0.01027137 > colold.lags <- nblag(COL.nb, 3) > geary.test(spNamedVec("CRIME", COL.OLD), nb2listw(colold.lags[[2]], + style="W")) Geary's C test under randomisation data: spNamedVec("CRIME", COL.OLD) weights: nb2listw(colold.lags[[2]], style = "W") Geary C statistic standard deviate = -2.2896, p-value = 0.01102 alternative hypothesis: less sample estimates: Geary C statistic Expectation Variance 0.811285136 1.000000000 0.006793327 > geary.test(spNamedVec("CRIME", COL.OLD), nb2listw(colold.lags[[3]], + style="W"), alternative="greater") Geary's C test under randomisation data: spNamedVec("CRIME", COL.OLD) weights: nb2listw(colold.lags[[3]], style = "W") Geary C statistic standard deviate = 1.5667, p-value = 0.05859 alternative hypothesis: greater sample estimates: Geary C statistic Expectation Variance 1.130277918 1.000000000 0.006914551 > print(is.symmetric.nb(COL.nb)) [1] TRUE > COL.k4.nb <- knn2nb(knearneigh(coords.OLD, 4)) > print(is.symmetric.nb(COL.k4.nb)) Non-symmetric neighbours list [1] FALSE > geary.test(spNamedVec("CRIME", COL.OLD), nb2listw(COL.k4.nb, style="W")) Geary's C test under randomisation data: spNamedVec("CRIME", COL.OLD) weights: nb2listw(COL.k4.nb, style = "W") Geary C statistic standard deviate = -12.3013, p-value < 2.2e-16 alternative hypothesis: less sample estimates: Geary C statistic Expectation Variance 0.424057549 1.000000000 0.002192075 > geary.test(spNamedVec("CRIME", COL.OLD), nb2listw(COL.k4.nb, style="W"), + randomisation=FALSE) Warning in sqrt(VC) : NaNs produced Geary's C test under normality data: spNamedVec("CRIME", COL.OLD) weights: nb2listw(COL.k4.nb, style = "W") Geary C statistic standard deviate = NaN, p-value = NA alternative hypothesis: less sample estimates: Geary C statistic Expectation Variance 0.4240575491 1.0000000000 -0.0008663057 > cat("Note non-symmetric weights matrix - use listw2U()\n") Note non-symmetric weights matrix - use listw2U() > geary.test(spNamedVec("CRIME", COL.OLD), listw2U(nb2listw(COL.k4.nb, + style="W"))) Geary's C test under randomisation data: spNamedVec("CRIME", COL.OLD) weights: listw2U(nb2listw(COL.k4.nb, style = "W")) Geary C statistic standard deviate = -6.1267, p-value = 4.486e-10 alternative hypothesis: less sample estimates: Geary C statistic Expectation Variance 0.42405755 1.00000000 0.00883705 > geary.test(spNamedVec("CRIME", COL.OLD), listw2U(nb2listw(COL.k4.nb, + style="W")), randomisation=FALSE) Geary's C test under normality data: spNamedVec("CRIME", COL.OLD) weights: listw2U(nb2listw(COL.k4.nb, style = "W")) Geary C statistic standard deviate = -5.995, p-value = 1.017e-09 alternative hypothesis: less sample estimates: Geary C statistic Expectation Variance 0.424057549 1.000000000 0.009229488 > > > > cleanEx(); ..nameEx <- "getisord" > > ### * getisord > > flush(stderr()); flush(stdout()) > > ### Name: getisord > ### Title: Getis-Ord remote sensing example data > ### Aliases: getisord x y xyz > ### Keywords: datasets > > ### ** Examples > > data(getisord) > image(x, y, t(matrix(xyz$val, nrow=16, ncol=16, byrow=TRUE)), asp=1) > text(xyz$x, xyz$y, xyz$val, cex=0.7) > polygon(c(195,225,225,195), c(195,195,225,225), lwd=2) > title(main="Getis-Ord 1996 remote sensing data") > > > > cleanEx(); ..nameEx <- "globalG.test" > > ### * globalG.test > > flush(stderr()); flush(stdout()) > > ### Name: globalG.test > ### Title: test for spatial autocorrelation > ### Aliases: globalG.test > ### Keywords: spatial > > ### ** Examples > > data(nc.sids) > sidsrate79 <- (1000*nc.sids$SID79)/nc.sids$BIR79 > names(sidsrate79) <- rownames(nc.sids) > dists <- c(10, 20, 30, 33, 40, 50, 60, 70, 80, 90, 100) > ndists <- length(dists) > ZG <- numeric(length=ndists) > milesxy <- cbind(nc.sids$east, nc.sids$north) > for (i in 1:ndists) { + thisnb <- dnearneigh(milesxy, 0, dists[i], row.names=rownames(nc.sids)) + thislw <- nb2listw(thisnb, style="B", zero.policy=TRUE) + ZG[i] <- globalG.test(sidsrate79, thislw, zero.policy=TRUE)$statistic + } > cbind(dists, ZG) dists ZG [1,] 10 0.81651489 [2,] 20 0.27046614 [3,] 30 -0.11849772 [4,] 33 0.40157023 [5,] 40 -0.04345713 [6,] 50 0.58686472 [7,] 60 -0.35823892 [8,] 70 -0.27864299 [9,] 80 -0.18791364 [10,] 90 0.11457610 [11,] 100 0.31591356 > > > > cleanEx(); ..nameEx <- "graphneigh" > > ### * graphneigh > > flush(stderr()); flush(stdout()) > > ### Name: graphneigh > ### Title: Graph based spatial weights > ### Aliases: gabrielneigh relativeneigh soi.graph plot.Gabriel > ### plot.relative graph2nb > ### Keywords: spatial > > ### ** Examples > > data(columbus) > par(mfrow=c(2,2)) > col.tri.nb<-tri2nb(coords) > col.gab.nb<-graph2nb(gabrielneigh(coords), sym=TRUE) > col.rel.nb<- graph2nb(relativeneigh(coords), sym=TRUE) > col.soi.nb<- graph2nb(soi.graph(col.tri.nb,coords), sym=TRUE) > library(maptools) > plot(polys, border="grey", forcefill=FALSE) > plot(col.tri.nb,coords,add=TRUE) > title(main="Delaunay Triangulation") > plot(polys, border="grey", forcefill=FALSE) > plot(col.gab.nb, coords, add=TRUE) > title(main="Gabriel Graph") > plot(polys, border="grey", forcefill=FALSE) > plot(col.rel.nb, coords, add=TRUE) > title(main="Relative Neighbor Graph") > plot(polys, border="grey", forcefill=FALSE) > plot(col.soi.nb, coords, add=TRUE) > title(main="Sphere of Influence Graph") > par(mfrow=c(1,1)) > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "hopkins" > > ### * hopkins > > flush(stderr()); flush(stdout()) > > ### Name: hopkins > ### Title: Hopkins burnt savanna herb remains > ### Aliases: hopkins > ### Keywords: datasets > > ### ** Examples > > data(hopkins) > image(1:32, 1:32, hopkins[5:36,36:5], breaks=c(-0.5, 3.5, 20), + col=c("white", "black")) > box() > > > > cleanEx(); ..nameEx <- "include.self" > > ### * include.self > > flush(stderr()); flush(stdout()) > > ### Name: include.self > ### Title: Include self in neighbours list > ### Aliases: include.self > ### Keywords: spatial > > ### ** Examples > > data(columbus) > summary(col.gal.nb, coords) Neighbour list object: Number of regions: 49 Number of nonzero links: 230 Percentage nonzero weights: 9.579342 Average number of links: 4.693878 Link number distribution: 2 3 4 5 6 7 8 9 10 7 7 13 4 9 6 1 1 1 7 least connected regions: 1005 1008 1045 1047 1049 1048 1015 with 2 links 1 most connected region: 1017 with 10 links Summary of link distances: Min. 1st Qu. Median Mean 3rd Qu. Max. 0.1276 0.3613 0.4566 0.4694 0.5536 0.8924 The decimal point is 1 digit(s) to the left of the | 1 | 3344 1 | 99 2 | 000011333344 2 | 556677779999 3 | 000011222222223344444444 3 | 556666777777888888889999999999 4 | 00001111112233333333334444 4 | 55666666666666777777777788888899 5 | 0011112222222222222233334444 5 | 556666667788 6 | 000000112244 6 | 5577889999 7 | 11112244 7 | 557777 8 | 1144 8 | 55999999 > summary(include.self(col.gal.nb), coords) Neighbour list object: Number of regions: 49 Number of nonzero links: 279 Percentage nonzero weights: 11.62016 Average number of links: 5.693878 Link number distribution: 3 4 5 6 7 8 9 10 11 7 7 13 4 9 6 1 1 1 7 least connected regions: 1005 1008 1045 1047 1049 1048 1015 with 3 links 1 most connected region: 1017 with 11 links Summary of link distances: Min. 1st Qu. Median Mean 3rd Qu. Max. 0.0000 0.2576 0.4073 0.3870 0.5232 0.8924 The decimal point is 1 digit(s) to the left of the | 0 | 0000000000000000000000000000000000000000000000000 0 | 1 | 3344 1 | 99 2 | 000011333344 2 | 556677779999 3 | 000011222222223344444444 3 | 556666777777888888889999999999 4 | 00001111112233333333334444 4 | 55666666666666777777777788888899 5 | 0011112222222222222233334444 5 | 556666667788 6 | 000000112244 6 | 5577889999 7 | 11112244 7 | 557777 8 | 1144 8 | 55999999 > > > > cleanEx(); ..nameEx <- "invIrM" > > ### * invIrM > > flush(stderr()); flush(stdout()) > > ### Name: invIrM > ### Title: Compute SAR generating operator > ### Aliases: invIrM invIrW > ### Keywords: spatial > > ### ** Examples > > > nb7rt <- cell2nb(7, 7, torus=TRUE) > x <- matrix(rnorm(500*length(nb7rt)), nrow=length(nb7rt)) > res0 <- apply(invIrM(nb7rt, rho=0.0) %*% x, 2, function(x) var(x)/length(x)) > res2 <- apply(invIrM(nb7rt, rho=0.2) %*% x, 2, function(x) var(x)/length(x)) > res4 <- apply(invIrM(nb7rt, rho=0.4) %*% x, 2, function(x) var(x)/length(x)) > res6 <- apply(invIrM(nb7rt, rho=0.6) %*% x, 2, function(x) var(x)/length(x)) > res8 <- apply(invIrM(nb7rt, rho=0.8) %*% x, 2, function(x) var(x)/length(x)) > res9 <- apply(invIrM(nb7rt, rho=0.9) %*% x, 2, function(x) var(x)/length(x)) > plot(density(res9), col="red", xlim=c(-0.01, max(density(res9)$x)), + ylim=range(density(res0)$y), + xlab="estimated variance of the mean", + main=expression(paste("Effects of spatial autocorrelation for different ", + rho, " values"))) > lines(density(res0), col="black") > lines(density(res2), col="brown") > lines(density(res4), col="green") > lines(density(res6), col="orange") > lines(density(res8), col="pink") > legend(c(-0.02, 0.01), c(7, 25), legend=c("0.0", "0.2", "0.4", "0.6", "0.8", "0.9"), col=c("black", "brown", "green", "orange", "pink", "red"), lty=1, bty="n") > > > > > cleanEx(); ..nameEx <- "joincount.mc" > > ### * joincount.mc > > flush(stderr()); flush(stdout()) > > ### Name: joincount.mc > ### Title: Permutation test for same colour join count statistics > ### Aliases: joincount.mc > ### Keywords: spatial > > ### ** Examples > > data(oldcol) > HICRIME <- cut(COL.OLD$CRIME, breaks=c(0,35,80), labels=c("low","high")) > names(HICRIME) <- rownames(COL.OLD) > joincount.mc(HICRIME, nb2listw(COL.nb, style="B"), nsim=99) Monte-Carlo simulation of join-count statistic data: HICRIME weights: nb2listw(COL.nb, style = "B") number of simulations + 1: 100 Join-count statistic for low = 34, rank of observed statistic = 86, p-value = 0.14 alternative hypothesis: greater sample estimates: mean of simulation variance of simulation 29.01010 19.29582 Monte-Carlo simulation of join-count statistic data: HICRIME weights: nb2listw(COL.nb, style = "B") number of simulations + 1: 100 Join-count statistic for high = 54, rank of observed statistic = 100, p-value = 0.01 alternative hypothesis: greater sample estimates: mean of simulation variance of simulation 27.82828 18.06205 > joincount.test(HICRIME, nb2listw(COL.nb, style="B")) Join count test under nonfree sampling data: HICRIME weights: nb2listw(COL.nb, style = "B") Std. deviate for low = 1.0141, p-value = 0.1553 alternative hypothesis: greater sample estimates: Same colour statistic Expectation Variance 34.00000 29.59184 18.89550 Join count test under nonfree sampling data: HICRIME weights: nb2listw(COL.nb, style = "B") Std. deviate for high = 6.3307, p-value = 1.220e-10 alternative hypothesis: greater sample estimates: Same colour statistic Expectation Variance 54.00000 27.22449 17.88838 > > > > cleanEx(); ..nameEx <- "joincount.multi" > > ### * joincount.multi > > flush(stderr()); flush(stdout()) > > ### Name: joincount.multi > ### Title: BB, BW and Jtot join count statistic for k-coloured factors > ### Aliases: joincount.multi print.jcmulti > ### Keywords: spatial > > ### ** Examples > > data(oldcol) > HICRIME <- cut(COL.OLD$CRIME, breaks=c(0,35,80), labels=c("low","high")) > names(HICRIME) <- rownames(COL.OLD) > joincount.multi(HICRIME, nb2listw(COL.nb, style="B")) Joincount Expected Variance z-value low:low 34.000 29.592 18.895 1.0141 high:high 54.000 27.224 17.888 6.3307 high:low 28.000 59.184 26.233 -6.0884 Jtot 28.000 59.184 26.233 -6.0884 > data(hopkins) > image(1:32, 1:32, hopkins[5:36,36:5], breaks=c(-0.5, 3.5, 20), + col=c("white", "black")) > box() > hopkins.rook.nb <- cell2nb(32, 32, type="rook") > unlist(spweights.constants(nb2listw(hopkins.rook.nb, style="B"))) n n1 n2 n3 nn S0 S1 S2 1024 1023 1022 1021 1048576 3968 7936 61984 > hopkins.queen.nb <- cell2nb(32, 32, type="queen") > hopkins.bishop.nb <- diffnb(hopkins.rook.nb, hopkins.queen.nb, verbose=FALSE) > hopkins4 <- hopkins[5:36,36:5] > hopkins4[which(hopkins4 > 3, arr.ind=TRUE)] <- 4 > hopkins4.f <- factor(hopkins4) > table(hopkins4.f) hopkins4.f 0 1 2 3 4 657 215 98 30 24 > joincount.multi(hopkins4.f, nb2listw(hopkins.rook.nb, style="B")) Joincount Expected Variance z-value 0:0 864.00000 816.27273 116.05233 4.4304 1:1 94.00000 87.14015 55.25216 0.9229 2:2 18.00000 18.00379 14.81562 -0.0010 3:3 2.00000 1.64773 1.55539 0.2825 4:4 5.00000 1.04545 0.99845 3.9576 1:0 503.00000 535.05682 227.76750 -2.1241 2:0 213.00000 243.88636 97.21769 -3.1325 2:1 99.00000 79.81061 59.01930 2.4978 3:0 61.00000 74.65909 28.58592 -2.5547 3:1 28.00000 24.43182 18.99976 0.8186 3:2 15.00000 11.13636 9.82411 1.2327 4:0 40.00000 59.72727 22.78583 -4.1327 4:1 23.00000 19.54545 15.26564 0.8842 4:2 14.00000 8.90909 7.90051 1.8112 4:3 5.00000 2.72727 2.58616 1.4133 Jtot 1001.00000 1059.89015 273.78610 -3.5591 > cat("replicates Upton & Fingleton table 3.4 (p. 166)\n") replicates Upton & Fingleton table 3.4 (p. 166) > joincount.multi(hopkins4.f, nb2listw(hopkins.bishop.nb, style="B")) Joincount Expected Variance z-value 0:0 823.00000 790.76420 144.44877 2.6821 1:1 101.00000 84.41702 55.98143 2.2164 2:2 19.00000 17.44117 14.61542 0.4077 3:3 3.00000 1.59624 1.51444 1.1407 4:4 3.00000 1.01278 0.97111 2.0166 1:0 497.00000 518.33629 234.93545 -1.3920 2:0 216.00000 236.26491 104.42142 -1.9831 2:1 81.00000 77.31652 58.70829 0.4807 3:0 58.00000 72.32599 31.49151 -2.5529 3:1 21.00000 23.66832 18.85316 -0.6145 3:2 17.00000 10.78835 9.62487 2.0022 4:0 48.00000 57.86080 25.15973 -1.9659 4:1 21.00000 18.93466 15.14473 0.5307 4:2 10.00000 8.63068 7.73708 0.4923 4:3 4.00000 2.64205 2.51686 0.8560 Jtot 973.00000 1026.76858 284.51030 -3.1877 > cat("replicates Upton & Fingleton table 3.6 (p. 168)\n") replicates Upton & Fingleton table 3.6 (p. 168) > joincount.multi(hopkins4.f, nb2listw(hopkins.queen.nb, style="B")) Joincount Expected Variance z-value 0:0 1687.0000 1607.0369 303.8034 4.5877 1:1 195.0000 171.5572 114.2057 2.1936 2:2 37.0000 35.4450 29.6821 0.2854 3:3 5.0000 3.2440 3.0687 1.0024 4:4 8.0000 2.0582 1.9674 4.2361 1:0 1000.0000 1053.3931 480.6959 -2.4353 2:0 429.0000 480.1513 215.0360 -3.4882 2:1 180.0000 157.1271 119.3987 2.0932 3:0 119.0000 146.9851 65.1029 -3.4684 3:1 49.0000 48.1001 38.3268 0.1454 3:2 32.0000 21.9247 19.5237 2.2802 4:0 88.0000 117.5881 52.0312 -4.1019 4:1 44.0000 38.4801 30.7868 0.9948 4:2 24.0000 17.5398 15.6933 1.6308 4:3 9.0000 5.3693 5.0994 1.6078 Jtot 1974.0000 2086.6587 582.8326 -4.6665 > cat("replicates Upton & Fingleton table 3.7 (p. 169)\n") replicates Upton & Fingleton table 3.7 (p. 169) > > > > cleanEx(); ..nameEx <- "joincount.test" > > ### * joincount.test > > flush(stderr()); flush(stdout()) > > ### Name: joincount.test > ### Title: BB join count statistic for k-coloured factors > ### Aliases: joincount.test print.jclist > ### Keywords: spatial > > ### ** Examples > > data(oldcol) > HICRIME <- cut(COL.OLD$CRIME, breaks=c(0,35,80), labels=c("low","high")) > names(HICRIME) <- rownames(COL.OLD) > joincount.test(HICRIME, nb2listw(COL.nb, style="B")) Join count test under nonfree sampling data: HICRIME weights: nb2listw(COL.nb, style = "B") Std. deviate for low = 1.0141, p-value = 0.1553 alternative hypothesis: greater sample estimates: Same colour statistic Expectation Variance 34.00000 29.59184 18.89550 Join count test under nonfree sampling data: HICRIME weights: nb2listw(COL.nb, style = "B") Std. deviate for high = 6.3307, p-value = 1.220e-10 alternative hypothesis: greater sample estimates: Same colour statistic Expectation Variance 54.00000 27.22449 17.88838 > joincount.test(HICRIME, nb2listw(COL.nb, style="C")) Join count test under nonfree sampling data: HICRIME weights: nb2listw(COL.nb, style = "C") Std. deviate for low = 1.0141, p-value = 0.1553 alternative hypothesis: greater sample estimates: Same colour statistic Expectation Variance 7.181034 6.250000 0.842897 Join count test under nonfree sampling data: HICRIME weights: nb2listw(COL.nb, style = "C") Std. deviate for high = 6.3307, p-value = 1.220e-10 alternative hypothesis: greater sample estimates: Same colour statistic Expectation Variance 11.4051724 5.7500000 0.7979712 > joincount.test(HICRIME, nb2listw(COL.nb, style="S")) Join count test under nonfree sampling data: HICRIME weights: nb2listw(COL.nb, style = "S") Std. deviate for low = 2.5786, p-value = 0.00496 alternative hypothesis: greater sample estimates: Same colour statistic Expectation Variance 8.2425673 6.2500000 0.5971141 Join count test under nonfree sampling data: HICRIME weights: nb2listw(COL.nb, style = "S") Std. deviate for high = 6.1736, p-value = 3.337e-10 alternative hypothesis: greater sample estimates: Same colour statistic Expectation Variance 10.4249914 5.7500000 0.5734265 > joincount.test(HICRIME, nb2listw(COL.nb, style="W")) Join count test under nonfree sampling data: HICRIME weights: nb2listw(COL.nb, style = "W") Std. deviate for low = 4.6675, p-value = 1.524e-06 alternative hypothesis: greater sample estimates: Same colour statistic Expectation Variance 9.5190476 6.2500000 0.4905378 Join count test under nonfree sampling data: HICRIME weights: nb2listw(COL.nb, style = "W") Std. deviate for high = 5.1205, p-value = 1.523e-07 alternative hypothesis: greater sample estimates: Same colour statistic Expectation Variance 9.2920635 5.7500000 0.4784979 > by(card(COL.nb), HICRIME, summary) INDICES: low Min. 1st Qu. Median Mean 3rd Qu. Max. 2.00 2.00 4.00 3.84 4.00 10.00 ------------------------------------------------------------ INDICES: high Min. 1st Qu. Median Mean 3rd Qu. Max. 3.000 4.750 6.000 5.667 7.000 9.000 > print(is.symmetric.nb(COL.nb)) [1] TRUE > COL.k4.nb <- knn2nb(knearneigh(coords.OLD, 4)) > print(is.symmetric.nb(COL.k4.nb)) Non-symmetric neighbours list [1] FALSE > joincount.test(HICRIME, nb2listw(COL.k4.nb, style="B")) Warning in sqrt(Vjc[i]) : NaNs produced Warning in sqrt(Vjc[i]) : NaNs produced Join count test under nonfree sampling data: HICRIME weights: nb2listw(COL.k4.nb, style = "B") Std. deviate for low = NaN, p-value = NA alternative hypothesis: greater sample estimates: Same colour statistic Expectation Variance 36.500000 25.000000 -5.856492 Join count test under nonfree sampling data: HICRIME weights: nb2listw(COL.k4.nb, style = "B") Std. deviate for high = NaN, p-value = NA alternative hypothesis: greater sample estimates: Same colour statistic Expectation Variance 40.50000 23.00000 -4.97449 > cat("Note non-symmetric weights matrix - use listw2U()\n") Note non-symmetric weights matrix - use listw2U() > joincount.test(HICRIME, listw2U(nb2listw(COL.k4.nb, style="B"))) Join count test under nonfree sampling data: HICRIME weights: listw2U(nb2listw(COL.k4.nb, style = "B")) Std. deviate for low = 4.3698, p-value = 6.217e-06 alternative hypothesis: greater sample estimates: Same colour statistic Expectation Variance 36.500000 25.000000 6.925749 Join count test under nonfree sampling data: HICRIME weights: listw2U(nb2listw(COL.k4.nb, style = "B")) Std. deviate for high = 6.7239, p-value = 8.845e-12 alternative hypothesis: greater sample estimates: Same colour statistic Expectation Variance 40.500000 23.000000 6.773773 > > > > cleanEx(); ..nameEx <- "knearneigh" > > ### * knearneigh > > flush(stderr()); flush(stdout()) > > ### Name: knearneigh > ### Title: K nearest neighbours for spatial weights > ### Aliases: knearneigh > ### Keywords: spatial > > ### ** Examples > > data(columbus) > col.knn <- knearneigh(coords, k=4) > library(maptools) > plot(polys, border="grey", forcefill=FALSE) > plot(knn2nb(col.knn), coords, add=TRUE) > title(main="K nearest neighbours, k = 4") > data(state) > us48.fipsno <- read.geoda(system.file("etc/weights/us48.txt", + package="spdep")[1]) > if (as.numeric(paste(version$major, version$minor, sep="")) < 19) { + m50.48 <- match(us48.fipsno$"State.name", state.name) + } else { + m50.48 <- match(us48.fipsno$"State_name", state.name) + } > xy <- as.matrix(as.data.frame(state.center))[m50.48,] > llk4.nb <- knn2nb(knearneigh(xy, k=4, lonlat=FALSE)) > gck4.nb <- knn2nb(knearneigh(xy, k=4, lonlat=TRUE)) > plot(llk4.nb, xy) > plot(diffnb(llk4.nb, gck4.nb), xy, add=TRUE, col="red", lty=2) Neighbour difference for region id: 10 in relation to id: 26 48 Neighbour difference for region id: 11 in relation to id: 15 47 Neighbour difference for region id: 23 in relation to id: 14 34 Neighbour difference for region id: 24 in relation to id: 5 32 42 45 Neighbour difference for region id: 25 in relation to id: 5 32 Neighbour difference for region id: 28 in relation to id: 30 36 Neighbour difference for region id: 30 in relation to id: 19 27 28 36 Neighbour difference for region id: 32 in relation to id: 24 48 Neighbour difference for region id: 39 in relation to id: 13 14 Neighbour difference for region id: 40 in relation to id: 9 12 Neighbour difference for region id: 41 in relation to id: 14 29 Neighbour difference for region id: 42 in relation to id: 5 48 Neighbour difference for region id: 46 in relation to id: 15 18 31 36 > title(main="Differences between Euclidean and Great Circle k=4 neighbours") > summary(llk4.nb, xy, lonlat=TRUE) Neighbour list object: Number of regions: 48 Number of nonzero links: 192 Percentage nonzero weights: 8.333333 Average number of links: 4 Non-symmetric neighbours list Link number distribution: 4 48 48 least connected regions: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 with 4 links 48 most connected regions: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 with 4 links Summary of link distances: Min. 1st Qu. Median Mean 3rd Qu. Max. 93.59 297.60 393.50 414.50 513.00 955.90 The decimal point is 2 digit(s) to the right of the | 0 | 99 1 | 00112233 1 | 666699 2 | 00112222334444444444 2 | 6677889999 3 | 00000111112222222233333333334444 3 | 556666777788899999 4 | 0000001111233 4 | 555555666666677788888899 5 | 0000111111122222222344444 5 | 55666679 6 | 00233 6 | 5667 7 | 011234 7 | 5889 8 | 022 8 | 79 9 | 9 | 56 > summary(gck4.nb, xy, lonlat=TRUE) Neighbour list object: Number of regions: 48 Number of nonzero links: 192 Percentage nonzero weights: 8.333333 Average number of links: 4 Non-symmetric neighbours list Link number distribution: 4 48 48 least connected regions: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 with 4 links 48 most connected regions: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 with 4 links Summary of link distances: Min. 1st Qu. Median Mean 3rd Qu. Max. 93.59 297.00 393.50 410.20 508.10 952.40 The decimal point is 2 digit(s) to the right of the | 0 | 99 1 | 00112233 1 | 666699 2 | 00112222334444444444 2 | 66778899999 3 | 000000111112222222233333333334444 3 | 5566677778888999 4 | 0000001111233 4 | 5555556666666777788888899 5 | 00000111111122222223444444 5 | 56667899 6 | 00233 6 | 56 7 | 0001124 7 | 55899 8 | 022 8 | 9 9 | 9 | 5 > > > > cleanEx(); ..nameEx <- "knn2nb" > > ### * knn2nb > > flush(stderr()); flush(stdout()) > > ### Name: knn2nb > ### Title: Neighbours list from knn object > ### Aliases: knn2nb > ### Keywords: spatial > > ### ** Examples > > data(columbus) > col.knn <- knearneigh(coords, k=4) > library(maptools) > plot(polys, border="grey", forcefill=FALSE) > plot(knn2nb(col.knn), coords, add=TRUE) > title(main="K nearest neighbours, k = 4") > > > > cleanEx(); ..nameEx <- "lag.listw" > > ### * lag.listw > > flush(stderr()); flush(stdout()) > > ### Name: lag.listw > ### Title: Spatial lag of a numeric vector > ### Aliases: lag.listw > ### Keywords: spatial > > ### ** Examples > > data(oldcol) > Vx <- lag.listw(nb2listw(COL.nb, style="W"), COL.OLD$CRIME) > plot(Vx, COL.OLD$CRIME) > plot(ecdf(COL.OLD$CRIME)) > plot(ecdf(Vx), add=TRUE, col.points="red", col.hor="red") > > > > cleanEx(); ..nameEx <- "lagsarlm" > > ### * lagsarlm > > flush(stderr()); flush(stdout()) > > ### Name: lagsarlm > ### Title: Spatial simultaneous autoregressive lag model estimation > ### Aliases: lagsarlm > ### Keywords: spatial > > ### ** Examples > > data(oldcol) > COL.lag.eig <- lagsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, + nb2listw(COL.nb), method="eigen", quiet=FALSE) Spatial lag model Jacobian calculated using neighbourhood matrix eigenvalues Computing eigenvalues ... (eigen) rho: -0.5674437 function value: -202.2909 (eigen) rho: 0.03126655 function value: -186.749 (eigen) rho: 0.4012898 function value: -182.419 (eigen) rho: 0.6138418 function value: -183.5636 (eigen) rho: 0.4157662 function value: -182.398 (eigen) rho: 0.4295565 function value: -182.3905 (eigen) rho: 0.4311288 function value: -182.3904 (eigen) rho: 0.4310273 function value: -182.3904 (eigen) rho: 0.4310232 function value: -182.3904 (eigen) rho: 0.4310232 function value: -182.3904 (eigen) rho: 0.4310232 function value: -182.3904 (eigen) rho: 0.4310232 function value: -182.3904 (eigen) rho: 0.4310232 function value: -182.3904 > COL.lag.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, + nb2listw(COL.nb, style="W"), method="eigen", quiet=FALSE) Spatial autoregressive error model Jacobian calculated using neighbourhood matrix eigenvalues Computing eigenvalues ... (eigen) lambda: -0.5674437 function value: -195.8051 (eigen) lambda: 0.03126655 function value: -187.0219 (eigen) lambda: 0.4012898 function value: -183.8422 (eigen) lambda: 0.6299767 function value: -183.4895 (eigen) lambda: 0.5811116 function value: -183.3887 (eigen) lambda: 0.554104 function value: -183.3817 (eigen) lambda: 0.5621834 function value: -183.3805 (eigen) lambda: 0.5617028 function value: -183.3805 (eigen) lambda: 0.5617888 function value: -183.3805 (eigen) lambda: 0.5617902 function value: -183.3805 (eigen) lambda: 0.5617903 function value: -183.3805 (eigen) lambda: 0.5617903 function value: -183.3805 > COL.lag.SM <- lagsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, + nb2listw(COL.nb), method="SparseM", quiet=FALSE) Spatial lag model Jacobian calculated using sparse matrix techniques using SparseM (SparseM) rho: -0.2364499 function value: -204.0209 (SparseM) rho: 0.2354499 function value: -191.4847 (SparseM) rho: 0.5271001 function value: -187.3391 (SparseM) rho: 0.8206424 function value: -189.798 (SparseM) rho: 0.5653776 function value: -187.1909 (SparseM) rho: 0.5865778 function value: -187.1595 (SparseM) rho: 0.5944322 function value: -187.1575 (SparseM) rho: 0.5936095 function value: -187.1574 (SparseM) rho: 0.593551 function value: -187.1574 (SparseM) rho: 0.5935532 function value: -187.1574 (SparseM) rho: 0.5935532 function value: -187.1574 (SparseM) rho: 0.5935532 function value: -187.1574 (SparseM) rho: -0.2364499 function value: -195.8910 (SparseM) rho: 0.2354499 function value: -187.5084 (SparseM) rho: 0.5271001 function value: -186.8787 (SparseM) rho: 0.4340997 function value: -186.5621 (SparseM) rho: 0.4198224 function value: -186.5597 (SparseM) rho: 0.4241877 function value: -186.5592 (SparseM) rho: 0.4240698 function value: -186.5592 (SparseM) rho: 0.4240783 function value: -186.5592 (SparseM) rho: 0.4240783 function value: -186.5592 (SparseM) rho: 0.4240784 function value: -186.5592 (SparseM) rho: 0.4240784 function value: -186.5592 (SparseM) rho: -0.2364499 function value: -192.9523 (SparseM) rho: 0.2354499 function value: -183.542 (SparseM) rho: 0.5271001 function value: -182.7039 (SparseM) rho: 0.4455543 function value: -182.3974 (SparseM) rho: 0.4267907 function value: -182.391 (SparseM) rho: 0.4311986 function value: -182.3904 (SparseM) rho: 0.4310114 function value: -182.3904 (SparseM) rho: 0.4310231 function value: -182.3904 (SparseM) rho: 0.4310232 function value: -182.3904 (SparseM) rho: 0.4310232 function value: -182.3904 (SparseM) rho: 0.4310232 function value: -182.3904 (SparseM) rho: 0.4310232 function value: -182.3904 > summary(COL.lag.eig, correlation=TRUE) Call: errorsarlm(formula = CRIME ~ INC + HOVAL, data = COL.OLD, listw = nb2listw(COL.nb, style = "W"), method = "eigen", quiet = FALSE) Residuals: Min 1Q Median 3Q Max -34.81174 -6.44031 -0.72142 7.61476 23.33626 Type: error Coefficients: (asymptotic standard errors) Estimate Std. Error z value Pr(>|z|) (Intercept) 59.893219 5.366163 11.1613 < 2.2e-16 INC -0.941312 0.330569 -2.8476 0.0044057 HOVAL -0.302250 0.090476 -3.3407 0.0008358 Lambda: 0.56179 LR test value: 7.9935 p-value: 0.0046945 Asymptotic standard error: 0.13387 z-value: 4.1966 p-value: 2.7098e-05 Wald statistic: 17.611 p-value: 2.7098e-05 Log likelihood: -183.3805 for error model ML residual variance (sigma squared): 95.575, (sigma: 9.7762) Number of observations: 49 Number of parameters estimated: 5 AIC: 376.76, (AIC for lm: 382.75) Correlation of Coefficients: sigma lambda (Intercept) INC lambda -0.24 (Intercept) 0.00 0.00 INC 0.00 0.00 -0.56 HOVAL 0.00 0.00 -0.26 -0.45 > summary(COL.lag.SM, correlation=TRUE) Call: lagsarlm(formula = CRIME ~ INC + HOVAL, data = COL.OLD, listw = nb2listw(COL.nb), method = "SparseM", quiet = FALSE) Residuals: Min 1Q Median 3Q Max -37.68585 -5.35636 0.05421 6.02013 23.20555 Type: lag Coefficients: (log likelihood/likelihood ratio) Estimate Log likelihood LR statistic Pr(>|z|) (Intercept) 45.07925 NA NA NA INC -1.03162 -187.15742 9.5340 0.002017 HOVAL -0.26593 -186.55917 8.3375 0.003884 Rho: 0.43102 LR test value: 9.9736 p-value: 0.001588 Log likelihood: -182.3904 for lag model ML residual variance (sigma squared): 95.494, (sigma: 9.7721) Number of observations: 49 Number of parameters estimated: 5 AIC: 374.78, (AIC for lm: 382.75) > COL.lag.B <- lagsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, + nb2listw(COL.nb, style="B")) > summary(COL.lag.B, correlation=TRUE) Call: lagsarlm(formula = CRIME ~ INC + HOVAL, data = COL.OLD, listw = nb2listw(COL.nb, style = "B")) Residuals: Min 1Q Median 3Q Max -33.6975 -4.7996 -1.4808 5.3648 25.8922 Type: lag Coefficients: (asymptotic standard errors) Estimate Std. Error z value Pr(>|z|) (Intercept) 52.403878 5.961310 8.7907 < 2.2e-16 INC -1.175261 0.300473 -3.9114 9.178e-05 HOVAL -0.252680 0.087613 -2.8840 0.003926 Rho: 0.051981 LR test value: 12.764 p-value: 0.00035336 Asymptotic standard error: 0.014428 z-value: 3.6028 p-value: 0.00031482 Wald statistic: 12.98 p-value: 0.00031482 Log likelihood: -180.9953 for lag model ML residual variance (sigma squared): 93.29, (sigma: 9.6587) Number of observations: 49 Number of parameters estimated: 5 AIC: 371.99, (AIC for lm: 382.75) LM test for residual autocorrelation test value: 0.0028047 p-value: 0.95776 Correlation of Coefficients: sigma rho (Intercept) INC rho -0.04 (Intercept) 0.03 -0.74 INC -0.01 0.34 -0.63 HOVAL 0.00 0.10 -0.30 -0.43 > COL.mixed.B <- lagsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, + nb2listw(COL.nb, style="B"), type="mixed", tol.solve=1e-9) > summary(COL.mixed.B, correlation=TRUE) Call: lagsarlm(formula = CRIME ~ INC + HOVAL, data = COL.OLD, listw = nb2listw(COL.nb, style = "B"), type = "mixed", tol.solve = 1e-09) Residuals: Min 1Q Median 3Q Max -34.45813 -5.25361 -0.14753 5.20581 23.81568 Type: mixed Coefficients: (asymptotic standard errors) Estimate Std. Error z value Pr(>|z|) (Intercept) 54.179690 5.817611 9.3130 < 2.2e-16 INC -0.942199 0.327149 -2.8800 0.003976 HOVAL -0.287421 0.087377 -3.2894 0.001004 lag.(Intercept) -2.124907 2.756294 -0.7709 0.440749 lag.INC -0.124606 0.135599 -0.9189 0.358134 lag.HOVAL 0.052373 0.040246 1.3013 0.193150 Rho: 0.08115 LR test value: 3.993 p-value: 0.04569 Asymptotic standard error: 0.033436 z-value: 2.427 p-value: 0.015224 Wald statistic: 5.8904 p-value: 0.015224 Log likelihood: -179.4932 for mixed model ML residual variance (sigma squared): 85.779, (sigma: 9.2617) Number of observations: 49 Number of parameters estimated: 8 AIC: 374.99, (AIC for lm: 376.98) LM test for residual autocorrelation test value: 0.84013 p-value: 0.35936 Correlation of Coefficients: sigma rho (Intercept) INC HOVAL lag.(Intercept) lag.INC rho -0.16 (Intercept) 0.02 -0.14 INC -0.03 0.17 -0.52 HOVAL 0.01 -0.05 -0.28 -0.41 lag.(Intercept) 0.14 -0.86 -0.15 0.07 0.12 lag.INC -0.08 0.48 0.00 -0.33 0.10 -0.60 lag.HOVAL -0.03 0.16 0.09 0.11 -0.28 -0.35 -0.39 > COL.mixed.W <- lagsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, + nb2listw(COL.nb, style="W"), type="mixed") > summary(COL.mixed.W, correlation=TRUE) Call: lagsarlm(formula = CRIME ~ INC + HOVAL, data = COL.OLD, listw = nb2listw(COL.nb, style = "W"), type = "mixed") Residuals: Min 1Q Median 3Q Max -37.47829 -6.46731 -0.33835 6.05200 22.62969 Type: mixed Coefficients: (asymptotic standard errors) Estimate Std. Error z value Pr(>|z|) (Intercept) 42.822415 12.667205 3.3806 0.0007233 INC -0.914223 0.331094 -2.7612 0.0057586 HOVAL -0.293738 0.089212 -3.2926 0.0009927 lag.INC -0.520284 0.565129 -0.9206 0.3572355 lag.HOVAL 0.245640 0.178917 1.3729 0.1697756 Rho: 0.42634 LR test value: 5.3693 p-value: 0.020494 Asymptotic standard error: 0.15623 z-value: 2.7288 p-value: 0.0063561 Wald statistic: 7.4465 p-value: 0.0063561 Log likelihood: -181.3935 for mixed model ML residual variance (sigma squared): 91.791, (sigma: 9.5808) Number of observations: 49 Number of parameters estimated: 7 AIC: 376.79, (AIC for lm: 380.16) LM test for residual autocorrelation test value: 0.28919 p-value: 0.59074 Correlation of Coefficients: sigma rho (Intercept) INC HOVAL lag.INC rho -0.18 (Intercept) 0.16 -0.89 INC -0.03 0.14 -0.19 HOVAL 0.02 -0.09 0.03 -0.45 lag.INC -0.09 0.49 -0.53 -0.36 0.05 lag.HOVAL -0.04 0.19 -0.36 0.19 -0.24 -0.41 > NA.COL.OLD <- COL.OLD > NA.COL.OLD$CRIME[20:25] <- NA > COL.lag.NA <- lagsarlm(CRIME ~ INC + HOVAL, data=NA.COL.OLD, + nb2listw(COL.nb), na.action=na.exclude, tol.opt=.Machine$double.eps^0.4) > COL.lag.NA$na.action 1020 1021 1022 1023 1024 1025 20 21 22 23 24 25 attr(,"class") [1] "exclude" > COL.lag.NA Call: lagsarlm(formula = CRIME ~ INC + HOVAL, data = NA.COL.OLD, listw = nb2listw(COL.nb), na.action = na.exclude, tol.opt = .Machine$double.eps^0.4) Type: lag Coefficients: (Intercept) INC HOVAL rho 43.1054975 -0.9267352 -0.2715541 0.4537820 Log likelihood: -160.8867 > resid(COL.lag.NA) 1001 1002 1003 1004 1005 1006 -4.4352945 -13.2750948 -2.9233555 -37.3067542 1.3568011 -3.8828027 1007 1008 1009 1010 1011 1012 5.9980436 -12.8113318 -4.0482558 18.1813323 5.9714203 1.0035599 1013 1014 1015 1016 1017 1018 -1.7490666 -1.7490651 5.8456327 10.1074158 -4.3706895 3.3713771 1019 1020 1021 1022 1023 1024 -4.0823022 NA NA NA NA NA 1025 1026 1027 1028 1029 1030 NA -6.0553296 -11.5813311 -8.0011389 -1.9047478 3.9744243 1031 1032 1033 1034 1035 1036 4.8148614 6.0673483 10.2059847 22.7419913 -2.0830998 0.1422777 1037 1038 1039 1040 1041 1042 8.6436388 8.8150864 6.4974685 15.4121789 9.4182148 5.6427603 1043 1044 1045 1046 1047 1048 -7.5727123 -7.5983733 -9.7792620 -10.0870764 -3.1242393 3.4921796 1049 0.7173251 > > > > cleanEx(); ..nameEx <- "listw2sn" > > ### * listw2sn > > flush(stderr()); flush(stdout()) > > ### Name: listw2sn > ### Title: Spatial neighbour sparse representation > ### Aliases: listw2sn sn2listw > ### Keywords: spatial > > ### ** Examples > > data(columbus) > col.listw <- nb2listw(col.gal.nb) > col.listw$neighbours[[1]] [1] 2 3 > col.listw$weights[[1]] [1] 0.5 0.5 > col.sn <- listw2sn(col.listw) > str(col.sn) Classes spatial.neighbour and `data.frame': 230 obs. of 3 variables: $ from : int 1 1 2 2 2 3 3 3 3 4 ... $ to : int 2 3 1 3 4 1 2 4 5 2 ... $ weights: num 0.500 0.500 0.333 0.333 0.333 ... - attr(*, "n")= int 49 - attr(*, "region.id")= num 1005 1001 1006 1002 1007 ... - attr(*, "neighbours.attrs")= chr "class" "region.id" "gal" "call" ... - attr(*, "weights.attrs")= chr "mode" "W" "comp" - attr(*, "listw.call")= language nb2listw(neighbours = col.gal.nb) > W <- asMatrixCsrListw(similar.listw(col.listw)) > str(W) Formal class 'matrix.csr' [package "SparseM"] with 4 slots ..@ ra : num [1:230] 0.408 0.354 0.408 0.289 0.289 ... ..@ ja : int [1:230] 2 3 1 3 4 1 2 4 5 2 ... ..@ ia : int [1:50] 1 3 6 10 14 21 23 27 33 41 ... ..@ dimension: int [1:2] 49 49 > rho <- seq(-0.8, 0.9, 0.1) > for (i in rho) print(paste("rho:", i, "log(det(I - rho*W))", + log(det(asMatrixCsrIrW(W, i)))), quote=TRUE) [1] "rho: -0.8 log(det(I - rho*W)) -3.32243407978180" [1] "rho: -0.7 log(det(I - rho*W)) -2.52453311812212" [1] "rho: -0.6 log(det(I - rho*W)) -1.84841461424027" [1] "rho: -0.5 log(det(I - rho*W)) -1.28423182869652" [1] "rho: -0.4 log(det(I - rho*W)) -0.825408693950342" [1] "rho: -0.3 log(det(I - rho*W)) -0.468020827352672" [1] "rho: -0.2 log(det(I - rho*W)) -0.210481644636056" [1] "rho: -0.1 log(det(I - rho*W)) -0.0534583888635971" [1] "rho: 0 log(det(I - rho*W)) 0" [1] "rho: 0.1 log(det(I - rho*W)) -0.0559069320516246" [1] "rho: 0.2 log(det(I - rho*W)) -0.230433425962048" [1] "rho: 0.3 log(det(I - rho*W)) -0.537514700112025" [1] "rho: 0.4 log(det(I - rho*W)) -0.99791717000465" [1] "rho: 0.5 log(det(I - rho*W)) -1.64318107245676" [1] "rho: 0.6 log(det(I - rho*W)) -2.52345398161187" [1] "rho: 0.7 log(det(I - rho*W)) -3.72509399156610" [1] "rho: 0.8 log(det(I - rho*W)) -5.41872816510602" [1] "rho: 0.9 log(det(I - rho*W)) -8.04718926152849" > > > > cleanEx(); ..nameEx <- "lm.LMtests" > > ### * lm.LMtests > > flush(stderr()); flush(stdout()) > > ### Name: lm.LMtests > ### Title: Lagrange Multiplier diagnostics for spatial dependence in linear > ### models > ### Aliases: lm.LMtests print.LMtestlist > ### Keywords: spatial > > ### ** Examples > > data(oldcol) > oldcrime.lm <- lm(CRIME ~ HOVAL + INC, data = COL.OLD) > summary(oldcrime.lm) Call: lm(formula = CRIME ~ HOVAL + INC, data = COL.OLD) Residuals: Min 1Q Median 3Q Max -34.418 -6.388 -1.580 9.052 28.649 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 68.6190 4.7355 14.490 < 2e-16 *** HOVAL -0.2739 0.1032 -2.654 0.0109 * INC -1.5973 0.3341 -4.780 1.83e-05 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 11.43 on 46 degrees of freedom Multiple R-Squared: 0.5524, Adjusted R-squared: 0.5329 F-statistic: 28.39 on 2 and 46 DF, p-value: 9.34e-09 > lm.LMtests(oldcrime.lm, nb2listw(COL.nb), test=c("LMerr", "LMlag", "RLMerr", + "RLMlag", "SARMA")) Lagrange multiplier diagnostics for spatial dependence data: model: lm(formula = CRIME ~ HOVAL + INC, data = COL.OLD) weights: nb2listw(COL.nb) LMerr = 5.7231, df = 1, p-value = 0.01674 Lagrange multiplier diagnostics for spatial dependence data: model: lm(formula = CRIME ~ HOVAL + INC, data = COL.OLD) weights: nb2listw(COL.nb) LMlag = 9.3637, df = 1, p-value = 0.002213 Lagrange multiplier diagnostics for spatial dependence data: model: lm(formula = CRIME ~ HOVAL + INC, data = COL.OLD) weights: nb2listw(COL.nb) RLMerr = 0.0795, df = 1, p-value = 0.778 Lagrange multiplier diagnostics for spatial dependence data: model: lm(formula = CRIME ~ HOVAL + INC, data = COL.OLD) weights: nb2listw(COL.nb) RLMlag = 3.72, df = 1, p-value = 0.05376 Lagrange multiplier diagnostics for spatial dependence data: model: lm(formula = CRIME ~ HOVAL + INC, data = COL.OLD) weights: nb2listw(COL.nb) SARMA = 9.4432, df = 2, p-value = 0.008901 > > > > cleanEx(); ..nameEx <- "lm.morantest" > > ### * lm.morantest > > flush(stderr()); flush(stdout()) > > ### Name: lm.morantest > ### Title: Moran's I test for residual spatial autocorrelation > ### Aliases: lm.morantest listw2U > ### Keywords: spatial > > ### ** Examples > > data(oldcol) > oldcrime1.lm <- lm(CRIME ~ 1, data = COL.OLD) > oldcrime.lm <- lm(CRIME ~ HOVAL + INC, data = COL.OLD) > lm.morantest(oldcrime.lm, nb2listw(COL.nb, style="W")) Global Moran's I for regression residuals data: model: lm(formula = CRIME ~ HOVAL + INC, data = COL.OLD) weights: nb2listw(COL.nb, style = "W") Moran I statistic standard deviate = 2.9539, p-value = 0.001569 alternative hypothesis: greater sample estimates: Observed Moran's I Expectation Variance 0.235638354 -0.033302866 0.008289408 > lm.LMtests(oldcrime.lm, nb2listw(COL.nb, style="W")) Lagrange multiplier diagnostics for spatial dependence data: model: lm(formula = CRIME ~ HOVAL + INC, data = COL.OLD) weights: nb2listw(COL.nb, style = "W") LMerr = 5.7231, df = 1, p-value = 0.01674 > lm.morantest(oldcrime.lm, nb2listw(COL.nb, style="S")) Global Moran's I for regression residuals data: model: lm(formula = CRIME ~ HOVAL + INC, data = COL.OLD) weights: nb2listw(COL.nb, style = "S") Moran I statistic standard deviate = 3.1745, p-value = 0.0007504 alternative hypothesis: greater sample estimates: Observed Moran's I Expectation Variance 0.239317561 -0.033431740 0.007381982 > lm.morantest(oldcrime1.lm, nb2listw(COL.nb, style="W")) Global Moran's I for regression residuals data: model: lm(formula = CRIME ~ 1, data = COL.OLD) weights: nb2listw(COL.nb, style = "W") Moran I statistic standard deviate = 5.6754, p-value = 6.92e-09 alternative hypothesis: greater sample estimates: Observed Moran's I Expectation Variance 0.510951264 -0.020833333 0.008779831 > moran.test(spNamedVec("CRIME", COL.OLD), nb2listw(COL.nb, style="W"), + randomisation=FALSE) Moran's I test under normality data: spNamedVec("CRIME", COL.OLD) weights: nb2listw(COL.nb, style = "W") Moran I statistic standard deviate = 5.6754, p-value = 6.92e-09 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.510951264 -0.020833333 0.008779831 > oldcrime.wlm <- lm(CRIME ~ HOVAL + INC, data = COL.OLD, weights = I(1/AREA)) > lm.morantest(oldcrime.wlm, nb2listw(COL.nb, style="W"), resfun=weighted.residuals) Global Moran's I for regression residuals data: model: lm(formula = CRIME ~ HOVAL + INC, data = COL.OLD, weights = I(1/AREA)) weights: nb2listw(COL.nb, style = "W") Moran I statistic standard deviate = 3.0141, p-value = 0.001289 alternative hypothesis: greater sample estimates: Observed Moran's I Expectation Variance 0.241298974 -0.032224366 0.008235091 > lm.morantest(oldcrime.wlm, nb2listw(COL.nb, style="W"), resfun=rstudent) Global Moran's I for regression residuals data: model: lm(formula = CRIME ~ HOVAL + INC, data = COL.OLD, weights = I(1/AREA)) weights: nb2listw(COL.nb, style = "W") Moran I statistic standard deviate = 2.822, p-value = 0.002387 alternative hypothesis: greater sample estimates: Observed Moran's I Expectation Variance 0.223860298 -0.032224366 0.008235091 > > > > cleanEx(); ..nameEx <- "lm.morantest.sad" > > ### * lm.morantest.sad > > flush(stderr()); flush(stdout()) > > ### Name: lm.morantest.sad > ### Title: Saddlepoint approximation of global Moran's I test > ### Aliases: lm.morantest.sad print.moransad summary.moransad > ### print.summary.moransad > ### Keywords: spatial > > ### ** Examples > > data(eire) > e.lm <- lm(OWNCONS ~ ROADACC, data=eire.df) > lm.morantest(e.lm, nb2listw(eire.nb)) Global Moran's I for regression residuals data: model: lm(formula = OWNCONS ~ ROADACC, data = eire.df) weights: nb2listw(eire.nb) Moran I statistic standard deviate = 3.2575, p-value = 0.0005619 alternative hypothesis: greater sample estimates: Observed Moran's I Expectation Variance 0.33660565 -0.05877741 0.01473183 > lm.morantest.sad(e.lm, nb2listw(eire.nb)) Saddlepoint approximation for global Moran's I (Barndorff-Nielsen formula) data: model:lm(formula = OWNCONS ~ ROADACC, data = eire.df) weights: nb2listw(eire.nb) Saddlepoint approximation = 2.9395, p-value = 0.001644 alternative hypothesis: greater sample estimates: Observed Moran's I 0.3366057 > summary(lm.morantest.sad(e.lm, nb2listw(eire.nb))) Saddlepoint approximation for global Moran's I (Barndorff-Nielsen formula) data: model:lm(formula = OWNCONS ~ ROADACC, data = eire.df) weights: nb2listw(eire.nb) Saddlepoint approximation = 2.9395, p-value = 0.001644 alternative hypothesis: greater sample estimates: Observed Moran's I 0.3366057 Expectation Variance Std. deviate Skewness Kurtosis Minimum -0.05877741 0.01473183 3.25753938 0.31336881 3.05047361 -0.67545810 Maximum omega sad.r sad.u 0.89091555 0.76549075 2.77616585 4.36854629 f.root iter estim.prec 6.916689e-14 1.100000e+01 7.450581e-09 > e.wlm <- lm(OWNCONS ~ ROADACC, data=eire.df, weights=RETSALE) > lm.morantest(e.wlm, nb2listw(eire.nb), resfun=rstudent) Global Moran's I for regression residuals data: model: lm(formula = OWNCONS ~ ROADACC, data = eire.df, weights = RETSALE) weights: nb2listw(eire.nb) Moran I statistic standard deviate = 3.1385, p-value = 0.0008491 alternative hypothesis: greater sample estimates: Observed Moran's I Expectation Variance 0.34500329 -0.04049313 0.01508687 > lm.morantest.sad(e.wlm, nb2listw(eire.nb), resfun=rstudent) Saddlepoint approximation for global Moran's I (Barndorff-Nielsen formula) data: model:lm(formula = OWNCONS ~ ROADACC, data = eire.df, weights = RETSALE) weights: nb2listw(eire.nb) Saddlepoint approximation = 2.8708, p-value = 0.002047 alternative hypothesis: greater sample estimates: Observed Moran's I 0.3450033 > > > > cleanEx(); ..nameEx <- "localG" > > ### * localG > > flush(stderr()); flush(stdout()) > > ### Name: localG > ### Title: G and Gstar local spatial statistics > ### Aliases: localG > ### Keywords: spatial > > ### ** Examples > > data(getisord) > xycoords <- cbind(xyz$x, xyz$y) > nb30 <- dnearneigh(xycoords, 0, 30) > G30 <- localG(spNamedVec("val", xyz), nb2listw(nb30, style="B")) > G30[length(xyz$val)-136] 120 1.221979 > nb60 <- dnearneigh(xycoords, 0, 60) > G60 <- localG(spNamedVec("val", xyz), nb2listw(nb60, style="B")) > G60[length(xyz$val)-136] 120 1.748098 > nb90 <- dnearneigh(xycoords, 0, 90) > G90 <- localG(spNamedVec("val", xyz), nb2listw(nb90, style="B")) > G90[length(xyz$val)-136] 120 1.986135 > nb120 <- dnearneigh(xycoords, 0, 120) > G120 <- localG(spNamedVec("val", xyz), nb2listw(nb120, style="B")) > G120[length(xyz$val)-136] 120 1.893374 > nb150 <- dnearneigh(xycoords, 0, 150) > G150 <- localG(spNamedVec("val", xyz), nb2listw(nb150, style="B")) > G150[length(xyz$val)-136] 120 1.237454 > brks <- seq(-5,5,1) > cm.col <- cm.colors(length(brks)-1) > image(x, y, t(matrix(G30, nrow=16, ncol=16, byrow=TRUE)), + breaks=brks, col=cm.col, asp=1) > text(xyz$x, xyz$y, round(G30, digits=1), cex=0.7) > polygon(c(195,225,225,195), c(195,195,225,225), lwd=2) > title(main=expression(paste("Values of the ", G[i], " statistic"))) > G30s <- localG(spNamedVec("val", xyz), nb2listw(include.self(nb30), + style="B")) > cat("value according to Getis and Ord's eq. 14.2, p. 263 (1996)\n") value according to Getis and Ord's eq. 14.2, p. 263 (1996) > G30s[length(xyz$val)-136] [1] 1.450780 > cat(paste("value given by Getis and Ord (1996), p. 267", + "(division by n-1 rather than n \n in variance)\n")) value given by Getis and Ord (1996), p. 267 (division by n-1 rather than n in variance) > G30s[length(xyz$val)-136] * + (sqrt(sum(scale(xyz$val, scale=FALSE)^2)/length(xyz$val)) / + sqrt(var(xyz$val))) [1] 1.447943 > image(x, y, t(matrix(G30s, nrow=16, ncol=16, byrow=TRUE)), + breaks=brks, col=cm.col, asp=1) > text(xyz$x, xyz$y, round(G30s, digits=1), cex=0.7) > polygon(c(195,225,225,195), c(195,195,225,225), lwd=2) > title(main=expression(paste("Values of the ", G[i]^"*", " statistic"))) > > > > cleanEx(); ..nameEx <- "localmoran" > > ### * localmoran > > flush(stderr()); flush(stdout()) > > ### Name: localmoran > ### Title: Local Moran's I statistic > ### Aliases: localmoran > ### Keywords: spatial > > ### ** Examples > > data(afcon) > oid <- order(afcon$id) > resI <- localmoran(spNamedVec("totcon", afcon), nb2listw(paper.nb)) > printCoefmat(data.frame(resI[oid,], row.names=afcon$name[oid]), check.names=FALSE) Ii E.Ii Var.Ii Z.Ii Pr.z...0. THE GAMBIA 0.3752254 -0.0243902 0.8707799 0.4282410 0.3342 MALI 0.4636340 -0.0243902 0.1084938 1.4816272 0.0692 SENEGAL 0.2567014 -0.0243902 0.2037796 0.6226838 0.2667 BENIN 0.1941194 -0.0243902 0.2037796 0.4840501 0.3142 MAURITANIA 0.0970535 -0.0243902 0.2037796 0.2690263 0.3940 NIGER 0.2307143 -0.0243902 0.1084938 0.7744898 0.2193 IVORY COAST 0.2900359 -0.0243902 0.1593129 0.7877586 0.2154 GUINEA 0.1826275 -0.0243902 0.1593129 0.5186592 0.3020 BURKINA FASO 0.5082778 -0.0243902 0.1296684 1.4792430 0.0695 LIBERIA 0.1856475 -0.0243902 0.2778907 0.3984375 0.3452 SIERRA LEONE 0.2652337 -0.0243902 0.4261130 0.4436823 0.3286 GHANA 0.1476406 -0.0243902 0.2778907 0.3263392 0.3721 TOGO 0.2193448 -0.0243902 0.2778907 0.4623607 0.3219 CAMEROON 0.2592454 -0.0243902 0.1593129 0.7106167 0.2387 NIGERIA 0.1137709 -0.0243902 0.2037796 0.3060593 0.3798 GABON 0.2036649 -0.0243902 0.4261130 0.3493635 0.3634 CENTRAL AFRICAN REPUBLIC -0.4420567 -0.0243902 0.1593129 -1.0464153 0.8523 CHAD -0.1052846 -0.0243902 0.1296684 -0.2246472 0.5889 CONGO 0.0113803 -0.0243902 0.2037796 0.0792401 0.4684 ZAIRE 0.7097807 -0.0243902 0.0802610 2.5914625 0.0048 ANGOLA 0.1179749 -0.0243902 0.2778907 0.2700640 0.3936 UGANDA 1.9425080 -0.0243902 0.1593129 4.9278382 4.157e-07 KENYA 1.1969287 -0.0243902 0.1593129 3.0598747 0.0011 TANZANIA 0.2718545 -0.0243902 0.0926129 0.9734529 0.1652 BURUNDI -0.4842787 -0.0243902 0.2778907 -0.8723997 0.8085 RWANDA -0.7523578 -0.0243902 0.2037796 -1.6126187 0.9466 SOMALIA 0.4527658 -0.0243902 0.4261130 0.7309674 0.2324 ETHIOPIA 0.7251240 -0.0243902 0.2778907 1.4218143 0.0775 ZAMBIA 0.0421598 -0.0243902 0.0926129 0.2186818 0.4134 ZIMBABWE -0.0095068 -0.0243902 0.2037796 0.0329703 0.4868 MALAWI -0.2288840 -0.0243902 0.2778907 -0.3879207 0.6510 MOZAMBIQUE 0.0167900 -0.0243902 0.1296684 0.1143594 0.4545 SOUTH AFRICA -0.1825396 -0.0243902 0.1084938 -0.4801368 0.6844 LESOTHO -0.4193478 -0.0243902 0.8707799 -0.4232493 0.6639 BOTSWANA -0.0039316 -0.0243902 0.2778907 0.0388096 0.4845 SWAZILAND 0.0166842 -0.0243902 0.4261130 0.0629231 0.4749 MOROCCO -0.0969607 -0.0243902 0.4261130 -0.1111725 0.5443 ALGERIA -0.0100369 -0.0243902 0.1296684 0.0398599 0.4841 TUNISIA 0.0053873 -0.0243902 0.4261130 0.0456170 0.4818 LIBYA 0.8038237 -0.0243902 0.1296684 2.2999872 0.0107 SUDAN 2.9877738 -0.0243902 0.0926129 9.8978982 2.126e-23 EGYPT 6.9467291 -0.0243902 0.4261130 10.6792343 6.366e-27 > hist(resI[,5]) > resI <- localmoran(spNamedVec("totcon", afcon), nb2listw(paper.nb), p.adjust.method="bonferroni") > printCoefmat(data.frame(resI[oid,], row.names=afcon$name[oid]), check.names=FALSE) Ii E.Ii Var.Ii Z.Ii Pr.z...0. THE GAMBIA 0.3752254 -0.0243902 0.8707799 0.4282410 0.6685 MALI 0.4636340 -0.0243902 0.1084938 1.4816272 0.5538 SENEGAL 0.2567014 -0.0243902 0.2037796 0.6226838 1.0000 BENIN 0.1941194 -0.0243902 0.2037796 0.4840501 1.0000 MAURITANIA 0.0970535 -0.0243902 0.2037796 0.2690263 1.0000 NIGER 0.2307143 -0.0243902 0.1084938 0.7744898 1.0000 IVORY COAST 0.2900359 -0.0243902 0.1593129 0.7877586 1.0000 GUINEA 0.1826275 -0.0243902 0.1593129 0.5186592 1.0000 BURKINA FASO 0.5082778 -0.0243902 0.1296684 1.4792430 0.4868 LIBERIA 0.1856475 -0.0243902 0.2778907 0.3984375 1.0000 SIERRA LEONE 0.2652337 -0.0243902 0.4261130 0.4436823 0.9859 GHANA 0.1476406 -0.0243902 0.2778907 0.3263392 1.0000 TOGO 0.2193448 -0.0243902 0.2778907 0.4623607 1.0000 CAMEROON 0.2592454 -0.0243902 0.1593129 0.7106167 1.0000 NIGERIA 0.1137709 -0.0243902 0.2037796 0.3060593 1.0000 GABON 0.2036649 -0.0243902 0.4261130 0.3493635 1.0000 CENTRAL AFRICAN REPUBLIC -0.4420567 -0.0243902 0.1593129 -1.0464153 1.0000 CHAD -0.1052846 -0.0243902 0.1296684 -0.2246472 1.0000 CONGO 0.0113803 -0.0243902 0.2037796 0.0792401 1.0000 ZAIRE 0.7097807 -0.0243902 0.0802610 2.5914625 0.0478 ANGOLA 0.1179749 -0.0243902 0.2778907 0.2700640 1.0000 UGANDA 1.9425080 -0.0243902 0.1593129 4.9278382 2.494e-06 KENYA 1.1969287 -0.0243902 0.1593129 3.0598747 0.0066 TANZANIA 0.2718545 -0.0243902 0.0926129 0.9734529 1.0000 BURUNDI -0.4842787 -0.0243902 0.2778907 -0.8723997 1.0000 RWANDA -0.7523578 -0.0243902 0.2037796 -1.6126187 1.0000 SOMALIA 0.4527658 -0.0243902 0.4261130 0.7309674 0.6972 ETHIOPIA 0.7251240 -0.0243902 0.2778907 1.4218143 0.3102 ZAMBIA 0.0421598 -0.0243902 0.0926129 0.2186818 1.0000 ZIMBABWE -0.0095068 -0.0243902 0.2037796 0.0329703 1.0000 MALAWI -0.2288840 -0.0243902 0.2778907 -0.3879207 1.0000 MOZAMBIQUE 0.0167900 -0.0243902 0.1296684 0.1143594 1.0000 SOUTH AFRICA -0.1825396 -0.0243902 0.1084938 -0.4801368 1.0000 LESOTHO -0.4193478 -0.0243902 0.8707799 -0.4232493 1.0000 BOTSWANA -0.0039316 -0.0243902 0.2778907 0.0388096 1.0000 SWAZILAND 0.0166842 -0.0243902 0.4261130 0.0629231 1.0000 MOROCCO -0.0969607 -0.0243902 0.4261130 -0.1111725 1.0000 ALGERIA -0.0100369 -0.0243902 0.1296684 0.0398599 1.0000 TUNISIA 0.0053873 -0.0243902 0.4261130 0.0456170 1.0000 LIBYA 0.8038237 -0.0243902 0.1296684 2.2999872 0.0751 SUDAN 2.9877738 -0.0243902 0.0926129 9.8978982 1.913e-22 EGYPT 6.9467291 -0.0243902 0.4261130 10.6792343 1.910e-26 > hist(resI[,5]) > totcon <- spNamedVec("totcon", afcon) > is.na(totcon) <- sample(1:length(totcon), 5) > totcon TS AG MO LY EG MR ML NG CD SU ET SG UV NI GA CM 1363 1421 1861 2355 5246 811 299 NA 895 4751 1878 NA 347 1130 241 NA GV BN SO GH TO CT IV SL LI CG KE UG CF GB TZ RW 1015 998 2122 1090 848 618 NA 423 980 3087 2273 3134 1142 824 2881 487 BY AO ZA MI MZ ZI BC SF WZ LT 604 1528 1554 NA 792 795 1266 1875 147 363 > resI.na <- localmoran(totcon, nb2listw(paper.nb), na.action=na.exclude, + zero.policy=TRUE) > if (class(attr(resI.na, "na.action")) == "exclude") { + print(data.frame(resI.na[oid,], row.names=afcon$name[oid]), digits=2) + } else print(resI.na, digits=2) Ii E.Ii Var.Ii Z.Ii Pr.z...0. THE GAMBIA 0.0000 0.000 0.000 NaN NaN MALI 0.4726 -0.028 0.202 1.11364 1.3e-01 SENEGAL NA NA NA NA NA BENIN 0.2259 -0.028 0.276 0.48257 3.1e-01 MAURITANIA 0.1201 -0.028 0.276 0.28125 3.9e-01 NIGER NA NA NA NA NA IVORY COAST NA NA NA NA NA GUINEA 0.2847 -0.028 0.276 0.59444 2.8e-01 BURKINA FASO 0.5273 -0.028 0.202 1.23523 1.1e-01 LIBERIA 0.2546 -0.028 0.425 0.43318 3.3e-01 SIERRA LEONE 0.3450 -0.028 0.425 0.57183 2.8e-01 GHANA 0.2269 -0.028 0.425 0.39060 3.5e-01 TOGO 0.2852 -0.028 0.276 0.59551 2.8e-01 CAMEROON NA NA NA NA NA NIGERIA 0.1183 -0.028 0.425 0.22411 4.1e-01 GABON 0.1418 -0.028 0.871 0.18168 4.3e-01 CENTRAL AFRICAN REPUBLIC -0.6398 -0.028 0.202 -1.36207 9.1e-01 CHAD -0.3194 -0.028 0.202 -0.64892 7.4e-01 CONGO -0.0149 -0.028 0.276 0.02448 4.9e-01 ZAIRE 0.5103 -0.028 0.078 1.92726 2.7e-02 ANGOLA 0.0460 -0.028 0.276 0.14027 4.4e-01 UGANDA 1.5980 -0.028 0.157 4.09940 2.1e-05 KENYA 0.9448 -0.028 0.157 2.45251 7.1e-03 TANZANIA 0.2823 -0.028 0.106 0.95116 1.7e-01 BURUNDI -0.4492 -0.028 0.276 -0.80181 7.9e-01 RWANDA -0.7107 -0.028 0.202 -1.51973 9.4e-01 SOMALIA 0.3232 -0.028 0.425 0.53830 3.0e-01 ETHIOPIA 0.5257 -0.028 0.276 1.05296 1.5e-01 ZAMBIA 0.0250 -0.028 0.106 0.16189 4.4e-01 ZIMBABWE 0.0357 -0.028 0.202 0.14121 4.4e-01 MALAWI NA NA NA NA NA MOZAMBIQUE -0.0029 -0.028 0.157 0.06262 4.8e-01 SOUTH AFRICA -0.1704 -0.028 0.106 -0.43759 6.7e-01 LESOTHO -0.3519 -0.028 0.871 -0.34725 6.4e-01 BOTSWANA 0.0049 -0.028 0.276 0.06219 4.8e-01 SWAZILAND 0.1088 -0.028 0.425 0.20946 4.2e-01 MOROCCO -0.1034 -0.028 0.425 -0.11600 5.5e-01 ALGERIA 0.0019 -0.028 0.157 0.07481 4.7e-01 TUNISIA -0.0273 -0.028 0.425 0.00073 5.0e-01 LIBYA 0.8883 -0.028 0.157 2.30998 1.0e-02 SUDAN 2.4774 -0.028 0.090 8.33526 3.9e-17 EGYPT 6.0584 -0.028 0.425 9.33517 5.0e-21 > resG <- localG(spNamedVec("totcon", afcon), nb2listw(include.self(paper.nb))) > print(data.frame(resG[oid], row.names=afcon$name[oid]), digits=2) resG.oid. THE GAMBIA -0.984 MALI -1.699 SENEGAL -1.463 BENIN -1.301 MAURITANIA -0.605 NIGER -1.049 IVORY COAST -1.417 GUINEA -1.449 BURKINA FASO -1.751 LIBERIA -1.041 SIERRA LEONE -0.870 GHANA -1.103 TOGO -0.991 CAMEROON -1.133 NIGERIA -1.173 GABON -0.789 CENTRAL AFRICAN REPUBLIC 1.173 CHAD 0.463 CONGO -0.203 ZAIRE 2.023 ANGOLA 1.235 UGANDA 3.336 KENYA 3.503 TANZANIA 1.098 BURUNDI 0.774 RWANDA 1.457 SOMALIA 1.183 ETHIOPIA 2.627 ZAMBIA 0.753 ZIMBABWE -0.200 MALAWI 0.212 MOZAMBIQUE -0.288 SOUTH AFRICA -0.868 LESOTHO -0.298 BOTSWANA 0.041 SWAZILAND -0.659 MOROCCO 0.022 ALGERIA -0.363 TUNISIA 0.579 LIBYA 2.553 SUDAN 4.039 EGYPT 4.421 > > > > > cleanEx(); ..nameEx <- "localmoran.sad" > > ### * localmoran.sad > > flush(stderr()); flush(stdout()) > > ### Name: localmoran.sad > ### Title: Saddlepoint approximation of local Moran's Ii tests > ### Aliases: localmoran.sad listw2star print.summary.localmoransad > ### summary.localmoransad print.localmoransad as.data.frame.localmoransad > ### Keywords: spatial > > ### ** Examples > > data(eire) > e.lm <- lm(OWNCONS ~ ROADACC, data=eire.df) > e.locmor <- summary(localmoran.sad(e.lm, eire.nb, select=1:nrow(eire.df))) > e.locmor Local Morans I Stand. dev. (N) Pr. (N) Saddlepoint 1 Carlow 0.216996683 0.74177148 2.291129e-01 0.95074844 2 Cavan -0.372573613 -0.81297374 7.918834e-01 -1.00603119 3 Clare 0.231975105 0.49502499 3.102912e-01 0.67166518 4 Cork 0.781935479 1.75999915 3.920398e-02 1.74761575 5 Donegal -1.690640590 -1.98244914 9.762855e-01 -1.72031078 6 Dublin -0.160696921 -0.15041940 5.597831e-01 -0.35212627 7 Galway 1.313714727 3.34305297 4.143104e-04 2.66849536 8 Kerry 0.365348659 0.58147812 2.804591e-01 0.78073279 9 Kildare -0.025575445 0.15146558 4.398042e-01 0.04167665 10 Kilkenny 0.576843308 1.62868431 5.168993e-02 1.70897697 11 Laoghis -0.059517978 0.01724651 4.931200e-01 -0.12155465 12 Leitrim 0.384845866 1.27548777 1.010683e-01 1.47227033 13 Limerick 0.118179867 0.34038037 3.667850e-01 0.45727712 14 Longford 1.416432004 3.10732224 9.439524e-04 2.51113769 15 Louth 0.562429203 0.87665682 1.903365e-01 1.07441571 16 Mayo 0.875727038 2.02375701 2.149758e-02 2.05251226 17 Meath 0.003678560 0.16081712 4.361187e-01 0.12813539 18 Monaghan 0.550983111 1.06684464 1.430210e-01 1.23999193 19 Offaly 0.151555560 0.61933942 2.678464e-01 0.80786519 20 Roscommon 2.043688390 6.66107106 1.359196e-11 4.53187292 21 Sligo -0.475798710 -0.73430274 7.686179e-01 -0.94578114 22 Tipperary -0.034541063 0.04843351 4.806854e-01 -0.06919691 23 Waterford 0.857234228 1.98516133 2.356326e-02 1.91385108 24 Westmeath 0.451385718 1.20305006 1.144785e-01 1.36017204 25 Wexford 0.643718339 1.55468550 6.001049e-02 1.63188492 26 Wicklow 0.024419502 0.21823347 4.136236e-01 0.21197000 Pr. (Sad) Expectation Variance Skewness Kurtosis Minimum 1 Carlow 1.708660e-01 -0.06471134 0.14423085 -0.7895263 7.059116 -5.461326 2 Cavan 8.427997e-01 -0.04030838 0.16703857 -0.4622793 6.813004 -5.567356 3 Clare 2.508984e-01 -0.04219377 0.30674823 -0.3579185 6.761932 -7.406885 4 Cork 4.026529e-02 -0.04363826 0.22003250 -0.4363325 6.799081 -6.360927 5 Donegal 9.573120e-01 -0.11935726 0.62821008 -0.7004303 6.979051 -11.236382 6 Dublin 6.376282e-01 -0.08240217 0.27093033 -0.7352902 7.009201 -7.420687 7 Galway 3.809592e-03 -0.04389010 0.16491503 -0.5059997 6.838308 -5.573707 8 Kerry 2.174798e-01 -0.03212369 0.46724761 -0.2212594 6.714810 -8.915104 9 Kildare 4.833782e-01 -0.07623733 0.11187546 -1.0416026 7.339962 -4.999621 10 Kilkenny 4.372761e-02 -0.05911601 0.15247016 -0.7040737 6.982131 -5.538889 11 Laoghis 5.483741e-01 -0.06620117 0.15016408 -0.7915137 7.061015 -5.574277 12 Leitrim 7.047395e-02 -0.06828680 0.12621127 -0.8864130 7.157471 -5.186756 13 Limerick 3.237359e-01 -0.04172917 0.22070746 -0.4167943 6.789132 -6.348870 14 Longford 6.017137e-03 -0.04055162 0.21985521 -0.4059156 6.783792 -6.324457 15 Louth 1.413182e-01 -0.04386717 0.47831137 -0.2983105 6.738631 -9.149779 16 Mayo 2.005995e-02 -0.10340651 0.23408152 -0.9804377 7.264328 -7.165847 17 Meath 4.490209e-01 -0.04799533 0.10324707 -0.6949022 6.974408 -4.551176 18 Monaghan 1.074892e-01 -0.04136950 0.30828917 -0.3501006 6.758633 -7.415047 19 Offaly 2.095841e-01 -0.04662212 0.10238870 -0.6782821 6.960676 -4.519986 20 Roscommon 2.923151e-06 -0.04435301 0.09826301 -0.6591526 6.945294 -4.414164 21 Sligo 8.278699e-01 -0.11041170 0.24760301 -1.0156782 7.307311 -7.409091 22 Tipperary 5.275836e-01 -0.04872132 0.08571886 -0.7716947 7.042300 -4.198353 23 Waterford 2.781959e-02 -0.05435079 0.21086415 -0.5533724 6.868342 -6.353514 24 Westmeath 8.688774e-02 -0.04181671 0.16806722 -0.4779156 6.821788 -5.599610 25 Wexford 5.135187e-02 -0.05432673 0.20159596 -0.5654870 6.876461 -6.225016 26 Wicklow 4.160652e-01 -0.07022471 0.18808122 -0.7515626 7.023792 -6.198974 Maximum omega sad.r sad.u 1 Carlow 3.908254 0.071122863 0.71853146 0.84900467 2 Cavan 4.599954 -0.051532330 -0.69003582 -0.85816092 3 Clare 6.394234 0.031939551 0.46982957 0.51656357 4 Cork 5.313609 0.083281515 1.43928884 2.24323856 5 Donegal 8.371808 -0.039371561 -1.39288713 -2.19776923 6 Dublin 5.443035 -0.010354512 -0.14127218 -0.14554367 7 Galway 4.520344 0.134873939 2.39189491 4.63522665 8 Kerry 8.144135 0.028431952 0.54051534 0.61545648 9 Kildare 3.169925 0.018723213 0.14926096 0.14688325 10 Kilkenny 4.120105 0.105365819 1.40668493 2.15214600 11 Laoghis 3.985449 0.001724096 0.01660985 0.01657177 12 Leitrim 3.547872 0.109608339 1.18229964 1.66578026 13 Limerick 5.347370 0.027585567 0.32820959 0.34241163 14 Longford 5.351218 0.108368224 2.22687206 4.19385821 15 Louth 8.096967 0.037745731 0.78968254 0.98878788 16 Mayo 4.684091 0.105317102 1.75922892 2.94711915 17 Meath 3.399289 0.020074178 0.15693992 0.15623206 18 Monaghan 6.422179 0.053418031 0.94193428 1.24723730 19 Offaly 3.401055 0.071432961 0.59871278 0.67858124 20 Roscommon 3.349691 0.357114199 4.33885200 10.02517077 21 Sligo 4.759210 -0.036185300 -0.60775394 -0.74635955 22 Tipperary 3.029041 0.006482570 0.04683010 0.04657633 23 Waterford 5.049095 0.093409563 1.61022194 2.62552879 24 Westmeath 4.596009 0.080097979 1.05978192 1.45704611 25 Wexford 4.921174 0.085478829 1.32647942 1.98902088 26 Wicklow 4.513581 0.020437514 0.21417067 0.21406975 > mean(e.locmor[,1]) [1] 0.3366057 > lm.morantest(e.lm, nb2listw(eire.nb)) Global Moran's I for regression residuals data: model: lm(formula = OWNCONS ~ ROADACC, data = eire.df) weights: nb2listw(eire.nb) Moran I statistic standard deviate = 3.2575, p-value = 0.0005619 alternative hypothesis: greater sample estimates: Observed Moran's I Expectation Variance 0.33660565 -0.05877741 0.01473183 > hist(e.locmor[,"Pr. (Sad)"]) > e.wlm <- lm(OWNCONS ~ ROADACC, data=eire.df, weights=RETSALE) > e.locmorw1 <- summary(localmoran.sad(e.wlm, eire.nb, select=1:nrow(eire.df), resfun=weighted.residuals)) > e.locmorw1 Local Morans I Stand. dev. (N) Pr. (N) Saddlepoint 1 Carlow 0.160490657 0.41009538 3.408680e-01 0.5772973 2 Cavan -0.144663771 -0.27825575 6.095920e-01 -0.4530517 3 Clare 0.301676582 0.59021701 2.775226e-01 0.7898733 4 Cork 1.520488153 3.49016956 2.413571e-04 2.8366563 5 Donegal -0.435899664 -0.44665946 6.724395e-01 -0.6713609 6 Dublin -0.340222996 -0.60886675 7.286936e-01 -0.8565802 7 Galway 1.469009037 3.64546192 1.334560e-04 2.8227451 8 Kerry 0.268957279 0.49517211 3.102393e-01 0.6686101 9 Kildare 0.002996577 0.12659200 4.496317e-01 0.0997825 10 Kilkenny 0.497968801 1.20610829 1.138879e-01 1.3409138 11 Laoghis -0.026328708 -0.01713904 5.068372e-01 -0.0651175 12 Leitrim 0.277306386 0.80644537 2.099930e-01 1.0117649 13 Limerick 0.263122939 0.67591893 2.495461e-01 0.8775963 14 Longford 0.605211711 1.23874274 1.077204e-01 1.3537585 15 Louth 0.359469683 0.53572990 2.960726e-01 0.7328019 16 Mayo 1.742480472 3.68118786 1.160749e-04 3.0150016 17 Meath -0.112171618 -0.26680698 6.051911e-01 -0.4547053 18 Monaghan 0.241044892 0.46013751 3.227088e-01 0.6409416 19 Offaly 0.129191178 0.40988983 3.409434e-01 0.5720553 20 Roscommon 1.469671750 4.39927211 5.430728e-06 3.1321527 21 Sligo 0.095559559 0.31036587 3.781414e-01 0.3850306 22 Tipperary 0.088352646 0.39958273 3.447319e-01 0.5259210 23 Waterford 1.212658861 2.69846035 3.483052e-03 2.2929258 24 Westmeath 0.256165310 0.61222265 2.701952e-01 0.8162086 25 Wexford 0.619197906 1.31967483 9.347180e-02 1.4255383 26 Wicklow 0.006531073 0.13142161 4.477209e-01 0.1098672 Pr. (Sad) Expectation Variance Skewness Kurtosis Minimum 1 Carlow 0.281869320 -0.01840558 0.19029731 -0.1986977 6.709176 -5.665283 2 Cavan 0.674744237 -0.02184465 0.19482455 -0.2329761 6.717975 -5.769371 3 Clare 0.214800893 -0.02782578 0.31166901 -0.2346279 6.718435 -7.299407 4 Cork 0.002279433 -0.07147410 0.20805228 -0.7280203 7.002789 -6.495227 5 Donegal 0.749004675 -0.07638800 0.64784767 -0.4450323 6.803659 -10.931345 6 Dublin 0.804161523 -0.11187469 0.14065367 -1.3324828 7.767845 -5.846924 7 Galway 0.002380721 -0.04407925 0.17227545 -0.4973247 6.833103 -5.688263 8 Kerry 0.251872107 -0.05644300 0.43184063 -0.4031537 6.782459 -8.859407 9 Kildare 0.460258505 -0.04145378 0.12329287 -0.5519841 6.867423 -4.857131 10 Kilkenny 0.089974223 -0.02321457 0.18672759 -0.2528322 6.723714 -5.669156 11 Laoghis 0.525959778 -0.01882531 0.19166504 -0.2024943 6.710081 -5.689691 12 Leitrim 0.155825237 -0.03314655 0.14819776 -0.4041387 6.782933 -5.190860 13 Limerick 0.190081424 -0.04800976 0.21188592 -0.4885390 6.827925 -6.298874 14 Longford 0.087906718 -0.01321709 0.24923967 -0.1247567 6.694960 -6.392250 15 Louth 0.231839637 -0.02272663 0.50895713 -0.1500895 6.699098 -9.179410 16 Mayo 0.001284889 -0.09458039 0.24904116 -0.8745463 7.144787 -7.272523 17 Meath 0.675339370 -0.02548973 0.10555100 -0.3685280 6.766525 -4.353122 18 Monaghan 0.260780316 -0.02333303 0.33012248 -0.1912612 6.707452 -7.451275 19 Offaly 0.283642249 -0.01927989 0.13120470 -0.2505068 6.723017 -4.750083 20 Roscommon 0.000867648 -0.02385522 0.11525625 -0.3302939 6.750604 -4.517676 21 Sligo 0.350107359 -0.06927688 0.28207107 -0.6087587 6.906925 -7.416881 22 Tipperary 0.299471532 -0.03719246 0.09871568 -0.5534442 6.868390 -4.347214 23 Waterford 0.010926138 -0.04027429 0.21558757 -0.4070996 6.784366 -6.264083 24 Westmeath 0.207190421 -0.01522814 0.19650786 -0.1618342 6.701275 -5.716689 25 Wexford 0.077000826 -0.02786850 0.24041626 -0.2674357 6.728234 -6.450174 26 Wicklow 0.456257330 -0.04751424 0.16911517 -0.5404006 6.859847 -5.677417 Maximum omega sad.r sad.u 1 Carlow 5.223549 0.033637462 0.38794383 0.41751442 2 Cavan 5.245099 -0.022294725 -0.26091513 -0.27432856 3 Clare 6.631589 0.035302524 0.54866959 0.62630505 4 Cork 4.779848 0.134384022 2.56890121 5.11058941 5 Donegal 9.098033 -0.017507303 -0.40402088 -0.45010348 6 Dublin 3.161931 -0.040828131 -0.50710580 -0.60543071 7 Galway 4.630361 0.138454493 2.55314856 5.08170760 8 Kerry 7.504775 0.027195108 0.47167584 0.51758880 9 Kildare 3.862240 0.014230854 0.12280697 0.12246022 10 Kilkenny 5.112007 0.071351828 1.03314661 1.41988761 11 Laoghis 5.237883 -0.001502568 -0.01645549 -0.01646868 12 Leitrim 4.395343 0.066207108 0.74158109 0.90609823 13 Limerick 5.146640 0.050265468 0.63703133 0.74253221 14 Longford 6.075040 0.060534639 1.04112815 1.44165700 15 Louth 8.633971 0.025231866 0.49793592 0.55971045 16 Mayo 5.002594 0.135902733 2.75603129 5.62669411 17 Meath 3.741368 -0.028724497 -0.24912602 -0.26221742 18 Monaghan 6.891283 0.028042744 0.43280552 0.47360371 19 Offaly 4.287365 0.040883462 0.38909358 0.41780262 20 Roscommon 3.945151 0.180270100 2.87643937 6.00202551 21 Sligo 5.754236 0.023145822 0.30299868 0.31062426 22 Tipperary 3.454595 0.048932861 0.38768333 0.40902706 23 Waterford 5.297500 0.101874758 1.99944904 3.59542986 24 Westmeath 5.351214 0.044919886 0.56403221 0.65024353 25 Wexford 5.781330 0.066083430 1.11524637 1.57637406 26 Wicklow 4.537075 0.012609906 0.12748740 0.12720134 > e.locmorw2 <- summary(localmoran.sad(e.wlm, eire.nb, select=1:nrow(eire.df), resfun=rstudent)) > e.locmorw2 Local Morans I Stand. dev. (N) Pr. (N) Saddlepoint 1 Carlow 0.121997164 0.32185426 3.737816e-01 0.45871930 2 Cavan -0.110588620 -0.20105599 5.796726e-01 -0.34808741 3 Clare 0.308759283 0.60290381 2.732863e-01 0.80379674 4 Cork 1.404203115 3.23522979 6.077244e-04 2.69598105 5 Donegal -0.421182109 -0.42837428 6.658107e-01 -0.65187732 6 Dublin -0.443534307 -0.88433550 8.117424e-01 -1.05167518 7 Galway 1.376190254 3.42183495 3.110003e-04 2.70663064 8 Kerry 0.241623387 0.45357724 3.250666e-01 0.61515126 9 Kildare 0.008842913 0.14324202 4.430495e-01 0.12690939 10 Kilkenny 0.382893124 0.93980330 1.736592e-01 1.12810394 11 Laoghis -0.019904450 -0.00246494 5.009834e-01 -0.04176107 12 Leitrim 0.200483743 0.60688769 2.719627e-01 0.80241456 13 Limerick 0.238810092 0.62310059 2.666092e-01 0.81824678 14 Longford 0.466942853 0.96178354 1.680792e-01 1.14088225 15 Louth 0.271710988 0.41271732 3.399069e-01 0.58520655 16 Mayo 1.705850161 3.60778634 1.544103e-04 2.97346461 17 Meath -0.160603054 -0.41587901 6.612507e-01 -0.63254531 18 Monaghan 0.181378604 0.35629110 3.608113e-01 0.50697175 19 Offaly 0.107919508 0.35116431 3.627325e-01 0.49312417 20 Roscommon 1.249826037 3.75170355 8.781854e-05 2.81402777 21 Sligo 0.079431883 0.27999953 3.897389e-01 0.33741411 22 Tipperary 0.085153638 0.38940098 3.484898e-01 0.51126046 23 Waterford 1.022922345 2.28982205 1.101582e-02 2.06385578 24 Westmeath 0.201539331 0.48899468 3.124227e-01 0.67791734 25 Wexford 0.481114325 1.03805702 1.496218e-01 1.21094348 26 Wicklow -0.011694661 0.08710223 4.652951e-01 0.03786608 Pr. (Sad) Expectation Variance Skewness Kurtosis Minimum 1 Carlow 0.323217876 -0.01840558 0.19029731 -0.1986977 6.709176 -5.665283 2 Cavan 0.636112729 -0.02184465 0.19482455 -0.2329761 6.717975 -5.769371 3 Clare 0.210757187 -0.02782578 0.31166901 -0.2346279 6.718435 -7.299407 4 Cork 0.003509083 -0.07147410 0.20805228 -0.7280203 7.002789 -6.495227 5 Donegal 0.742759841 -0.07638800 0.64784767 -0.4450323 6.803659 -10.931345 6 Dublin 0.853525699 -0.11187469 0.14065367 -1.3324828 7.767845 -5.846924 7 Galway 0.003398492 -0.04407925 0.17227545 -0.4973247 6.833103 -5.688263 8 Kerry 0.269227417 -0.05644300 0.43184063 -0.4031537 6.782459 -8.859407 9 Kildare 0.449506058 -0.04145378 0.12329287 -0.5519841 6.867423 -4.857131 10 Kilkenny 0.129638014 -0.02321457 0.18672759 -0.2528322 6.723714 -5.669156 11 Laoghis 0.516655417 -0.01882531 0.19166504 -0.2024943 6.710081 -5.689691 12 Leitrim 0.211156597 -0.03314655 0.14819776 -0.4041387 6.782933 -5.190860 13 Limerick 0.206608144 -0.04800976 0.21188592 -0.4885390 6.827925 -6.298874 14 Longford 0.126959464 -0.01321709 0.24923967 -0.1247567 6.694960 -6.392250 15 Louth 0.279204420 -0.02272663 0.50895713 -0.1500895 6.699098 -9.179410 16 Mayo 0.001472292 -0.09458039 0.24904116 -0.8745463 7.144787 -7.272523 17 Meath 0.736484694 -0.02548973 0.10555100 -0.3685280 6.766525 -4.353122 18 Monaghan 0.306087322 -0.02333303 0.33012248 -0.1912612 6.707452 -7.451275 19 Offaly 0.310962427 -0.01927989 0.13120470 -0.2505068 6.723017 -4.750083 20 Roscommon 0.002446250 -0.02385522 0.11525625 -0.3302939 6.750604 -4.517676 21 Sligo 0.367902373 -0.06927688 0.28207107 -0.6087587 6.906925 -7.416881 22 Tipperary 0.304584343 -0.03719246 0.09871568 -0.5534442 6.868390 -4.347214 23 Waterford 0.019515696 -0.04027429 0.21558757 -0.4070996 6.784366 -6.264083 24 Westmeath 0.248912051 -0.01522814 0.19650786 -0.1618342 6.701275 -5.716689 25 Wexford 0.112958534 -0.02786850 0.24041626 -0.2674357 6.728234 -6.450174 26 Wicklow 0.484897230 -0.04751424 0.16911517 -0.5404006 6.859847 -5.677417 Maximum omega sad.r sad.u 1 Carlow 5.223549 0.0272472954 0.306852385 0.321490350 2 Cavan 5.245099 -0.0166242430 -0.190223798 -0.196022741 3 Clare 6.631589 0.0358559846 0.559584155 0.641527095 4 Cork 4.779848 0.1283688794 2.421993662 4.702934834 5 Donegal 9.098033 -0.0169574018 -0.388662370 -0.430528174 6 Dublin 3.161931 -0.0507848831 -0.696824139 -0.892299501 7 Galway 4.630361 0.1333224875 2.431707338 4.745166958 8 Kerry 7.504775 0.0252982005 0.433626352 0.469138111 9 Kildare 3.862240 0.0161278548 0.139072871 0.138837812 10 Kilkenny 5.112007 0.0622219791 0.835166590 1.066654825 11 Laoghis 5.237883 -0.0002164925 -0.002368023 -0.002368244 12 Leitrim 4.395343 0.0543844388 0.571625643 0.652237768 13 Limerick 5.146640 0.0473787285 0.590605630 0.675595582 14 Longford 6.075040 0.0528365356 0.840671447 1.082014178 15 Louth 8.633971 0.0204960239 0.389078238 0.419930705 16 Mayo 5.002594 0.1340509166 2.712635049 5.503894365 17 Meath 3.741368 -0.0415411327 -0.379736494 -0.417998694 18 Monaghan 6.891283 0.0226076552 0.338579266 0.358443998 19 Offaly 4.287365 0.0357600182 0.335019324 0.353243066 20 Roscommon 3.945151 0.1623235556 2.543240406 5.063795948 21 Sligo 5.754236 0.0209568244 0.273376649 0.278204612 22 Tipperary 3.454595 0.0478130890 0.377982061 0.397511387 23 Waterford 5.297500 0.0941811771 1.762051071 2.998984773 24 Westmeath 5.351214 0.0379323563 0.457473561 0.506014991 25 Wexford 5.781330 0.0582538352 0.911459483 1.197527949 26 Wicklow 4.537075 0.0083101099 0.084281843 0.083952776 > e.errorsar <- errorsarlm(OWNCONS ~ ROADACC, data=eire.df, + listw=nb2listw(eire.nb)) > e.errorsar Call: errorsarlm(formula = OWNCONS ~ ROADACC, data = eire.df, listw = nb2listw(eire.nb)) Type: error Coefficients: (Intercept) ROADACC lambda 2.892719569 0.002800913 0.783970989 Log likelihood: -64.12465 > e.clocmor <- summary(localmoran.sad(e.errorsar, eire.nb, select=1:nrow(eire.df))) > e.clocmor Local Morans I Stand. dev. (N) Pr. (N) Saddlepoint Pr. (Sad) 1 Carlow 0.216996683 -0.23901926 0.594454678 0.23886184 0.405606359 2 Cavan -0.372573613 -0.86382085 0.806156844 -1.57032046 0.941829712 3 Clare 0.231975105 -0.39573770 0.653850731 -0.01412279 0.505633989 4 Cork 0.781935479 -0.04503638 0.517960846 0.46824506 0.319804675 5 Donegal -1.690640590 -1.45417673 0.927051342 -2.07884411 0.981184159 6 Dublin -0.160696921 -0.66719838 0.747677287 -0.99638658 0.840468826 7 Galway 1.313714727 1.64460273 0.050025882 1.78369879 0.037236311 8 Kerry 0.365348659 -0.48706410 0.686893548 -0.15063115 0.559866657 9 Kildare -0.025575445 -0.48237140 0.685228933 -0.50743626 0.694075627 10 Kilkenny 0.576843308 0.36104345 0.359033484 0.82525579 0.204613193 11 Laoghis -0.059517978 -0.50300377 0.692519190 -0.64162073 0.739440265 12 Leitrim 0.384845866 0.12735264 0.449330650 0.61582501 0.269005011 13 Limerick 0.118179867 -0.57236200 0.716461624 -0.41657602 0.661505725 14 Longford 1.416432004 1.08802782 0.138291413 1.28377211 0.099610852 15 Louth 0.562429203 -0.32854059 0.628748522 0.16627427 0.433970556 16 Mayo 0.875727038 1.01197955 0.155773915 1.33880356 0.090317316 17 Meath 0.003678560 -0.59077624 0.722664823 -0.58846521 0.721889960 18 Monaghan 0.550983111 -0.26861659 0.605887626 0.22679194 0.410292764 19 Offaly 0.151555560 -0.01296477 0.505172052 0.44669970 0.327545950 20 Roscommon 2.043688390 2.37913310 0.008676704 3.05159819 0.001138133 21 Sligo -0.475798710 -1.04286177 0.851493842 -1.67839510 0.953365003 22 Tipperary -0.034541063 -0.60752056 0.728247248 -0.70912655 0.760877025 23 Waterford 0.857234228 0.59180803 0.276989574 0.98420674 0.162506935 24 Westmeath 0.451385718 -0.01202248 0.504796158 0.49676990 0.309675660 25 Wexford 0.643718339 0.21239755 0.415898450 0.70960108 0.238975775 26 Wicklow 0.024419502 -0.51385193 0.696322241 -0.40364018 0.656761333 Expectation Variance Skewness Kurtosis Minimum Maximum 1 Carlow 0.41510574 0.6869780 2.0117855 9.261988 -4.206946 14.169483 2 Cavan 0.84086832 1.9732887 2.2256282 9.916278 -4.555439 24.736279 3 Clare 0.78560219 1.9571306 2.1550023 9.687085 -5.534252 24.388704 4 Cork 0.85119474 2.3649862 2.1379028 9.633700 -6.317437 26.746111 5 Donegal 0.76633183 2.8547375 1.8788004 8.907007 -9.982656 28.374620 6 Dublin 0.53670402 1.0925846 2.0442431 9.354160 -5.066960 17.947857 7 Galway -0.16789312 0.8116046 -0.8605749 7.130082 -13.100271 9.070836 8 Kerry 1.64399605 6.8917473 2.2694519 10.066471 -7.074158 46.530063 9 Kildare 0.26242834 0.3564785 1.8360154 8.800025 -3.671416 9.969696 10 Kilkenny 0.28971957 0.6324399 1.5830238 8.231934 -5.881831 12.835101 11 Laoghis 0.23336759 0.3390420 1.7104386 8.504746 -3.959897 9.560720 12 Leitrim 0.29318752 0.5179980 1.7324831 8.554628 -4.816083 11.852584 13 Limerick 1.23120165 3.7815142 2.2791638 10.100716 -4.969517 34.518356 14 Longford 0.18291084 1.2853258 0.7489112 7.021392 -11.808447 16.198307 15 Louth 1.23755546 4.2227164 2.2318508 9.937200 -6.517068 36.218399 16 Mayo -0.04068769 0.8200506 -0.2115638 6.712314 -11.789109 10.812605 17 Meath 0.61648461 1.0759697 2.2181654 9.891351 -3.450422 18.246052 18 Monaghan 1.02287751 3.0861995 2.1961065 9.818688 -6.254862 30.803922 19 Offaly 0.15762584 0.2192235 1.4810040 8.031758 -3.668995 7.452015 20 Roscommon -0.63756938 1.2701051 -2.1636161 9.714273 -19.670778 4.369113 21 Sligo 0.36523619 0.6503910 1.8767733 8.901862 -4.774269 13.539937 22 Tipperary 0.48448255 0.7298814 2.1663926 9.723080 -3.289946 14.917527 23 Waterford 0.30429863 0.8729460 1.4393522 7.954516 -7.482000 14.785167 24 Westmeath 0.46292085 0.9205712 1.9622842 9.125722 -5.183761 16.293861 25 Wexford 0.42990119 1.0134121 1.7966973 8.704629 -6.403915 16.721543 26 Wicklow 0.52006242 0.9303831 2.1060292 9.536196 -4.220532 16.702030 omega sad.r sad.u 1 Carlow -0.006183657 -0.11988414 -0.11483747 2 Cavan -0.076730577 -1.41580886 -1.76201827 3 Clare -0.014488539 -0.37297689 -0.32625268 4 Cork 0.001664894 0.07041289 0.07241322 5 Donegal -0.039916017 -1.82964925 -2.88655418 6 Dublin -0.054218890 -0.92650741 -0.98847724 7 Galway 0.041810060 1.49306772 2.30427191 8 Kerry -0.013781253 -0.54171950 -0.43829323 9 Kildare -0.050569403 -0.56760272 -0.54854597 10 Kilkenny 0.016666016 0.46992951 0.55532915 11 Laoghis -0.052988992 -0.61500273 -0.62515327 12 Leitrim 0.011430634 0.25376401 0.27818400 13 Limerick -0.031417774 -0.74232781 -0.58287708 14 Longford 0.019745434 0.95318659 1.30625607 15 Louth -0.005622564 -0.23971180 -0.21748235 16 Mayo 0.030356932 1.04352038 1.42010951 17 Meath -0.057912215 -0.78252590 -0.67227636 18 Monaghan -0.004511205 -0.17504333 -0.16315407 19 Offaly 0.009772617 0.12658074 0.13181524 20 Roscommon 0.100863019 2.82165667 5.39860295 21 Sligo -0.076577219 -1.44263443 -2.02706181 22 Tipperary -0.068249867 -0.81232359 -0.74700313 23 Waterford 0.017479859 0.63251438 0.79009519 24 Westmeath 0.004353521 0.11813859 0.12354302 25 Wexford 0.010304716 0.34491868 0.39115131 26 Wicklow -0.039529611 -0.60645910 -0.53626901 > hist(e.clocmor[,"Pr. (Sad)"]) > > > > cleanEx(); ..nameEx <- "mat2listw" > > ### * mat2listw > > flush(stderr()); flush(stdout()) > > ### Name: mat2listw > ### Title: Convert a square spatial weights matrix to a weights list object > ### Aliases: mat2listw > ### Keywords: spatial > > ### ** Examples > > data(columbus) > col005 <- dnearneigh(coords, 0, 0.5, attr(col.gal.nb, "region.id")) > summary(col005) Neighbour list object: Number of regions: 49 Number of nonzero links: 170 Percentage nonzero weights: 7.080383 Average number of links: 3.469388 4 regions with no links: 1005 1006 1008 1043 Link number distribution: 0 1 2 3 4 5 6 7 8 9 4 11 5 8 3 9 2 2 3 2 11 least connected regions: 1001 1007 1018 1010 1045 1044 1046 1047 1049 1048 1015 with 1 link 2 most connected regions: 1038 1036 with 9 links > col005.w.mat <- nb2mat(col005, zero.policy=TRUE) > col005.w.b <- mat2listw(col005.w.mat) > summary(col005.w.b$neighbours) Neighbour list object: Number of regions: 49 Number of nonzero links: 170 Percentage nonzero weights: 7.080383 Average number of links: 3.469388 4 regions with no links: 1005 1006 1008 1043 Link number distribution: 0 1 2 3 4 5 6 7 8 9 4 11 5 8 3 9 2 2 3 2 11 least connected regions: 1001 1007 1018 1010 1045 1044 1046 1047 1049 1048 1015 with 1 link 2 most connected regions: 1038 1036 with 9 links > diffnb(col005, col005.w.b$neighbours) > > > > cleanEx(); ..nameEx <- "moran" > > ### * moran > > flush(stderr()); flush(stdout()) > > ### Name: moran > ### Title: Compute Moran's I > ### Aliases: moran > ### Keywords: spatial > > ### ** Examples > > data(oldcol) > col.W <- nb2listw(COL.nb, style="W") > crime <- spNamedVec("CRIME", COL.OLD) > str(moran(crime, col.W, length(COL.nb), Szero(col.W))) List of 2 $ I: num 0.511 $ K: num 2.23 > is.na(crime) <- sample(1:length(crime), 10) > str(moran(crime, col.W, length(COL.nb), Szero(col.W), NAOK=TRUE)) List of 2 $ I: num 0.468 $ K: num 2.65 > > > > cleanEx(); ..nameEx <- "moran.mc" > > ### * moran.mc > > flush(stderr()); flush(stdout()) > > ### Encoding: latin1 > > ### Name: moran.mc > ### Title: Permutation test for Moran's I statistic > ### Aliases: moran.mc > ### Keywords: spatial > > ### ** Examples > > data(oldcol) > colw <- nb2listw(COL.nb, style="W") > nsim <- 99 > set.seed(1234) > sim1 <- moran.mc(spNamedVec("CRIME", COL.OLD), listw=colw, nsim=nsim) > sim1 Monte-Carlo simulation of Moran's I data: spNamedVec("CRIME", COL.OLD) weights: colw number of simulations + 1: 100 statistic = 0.511, observed rank = 100, p-value = 0.01 alternative hypothesis: greater > mean(sim1$res[1:nsim]) [1] -0.01735822 > var(sim1$res[1:nsim]) [1] 0.008938155 > summary(sim1$res[1:nsim]) Min. 1st Qu. Median Mean 3rd Qu. Max. -0.238200 -0.083270 -0.007406 -0.017360 0.039720 0.259400 > MoranI.boot <- function(var, i, ...) { + var <- var[i] + return(moran(x=var, ...)$I) + } > set.seed(1234) > library(boot) > boot1 <- boot(spNamedVec("CRIME", COL.OLD), statistic=MoranI.boot, R=nsim, sim="permutation", listw=colw, n=nrow(COL.OLD), S0=Szero(colw)) > boot1 DATA PERMUTATION Call: boot(data = spNamedVec("CRIME", COL.OLD), statistic = MoranI.boot, R = nsim, sim = "permutation", listw = colw, n = nrow(COL.OLD), S0 = Szero(colw)) Bootstrap Statistics : original bias std. error t1* 0.5109513 -0.5283095 0.09454181 > plot(boot1) > mean(boot1$t) [1] -0.01735822 > var(boot1$t) [,1] [1,] 0.008938155 > summary(boot1$t) object Min. :-0.238206 1st Qu.:-0.083268 Median :-0.007406 Mean :-0.017358 3rd Qu.: 0.039717 Max. : 0.259444 > colold.lags <- nblag(COL.nb, 3) > set.seed(1234) > sim2 <- moran.mc(spNamedVec("CRIME", COL.OLD), nb2listw(colold.lags[[2]], + style="W"), nsim=nsim) > summary(sim2$res[1:nsim]) Min. 1st Qu. Median Mean 3rd Qu. Max. -0.18440 -0.06090 -0.01837 -0.01522 0.02860 0.23550 > sim3 <- moran.mc(spNamedVec("CRIME", COL.OLD), nb2listw(colold.lags[[3]], + style="W"), nsim=nsim) > summary(sim3$res[1:nsim]) Min. 1st Qu. Median Mean 3rd Qu. Max. -0.16810 -0.06701 -0.02035 -0.01733 0.02200 0.14340 > > > > cleanEx(); ..nameEx <- "moran.plot" > > ### * moran.plot > > flush(stderr()); flush(stdout()) > > ### Name: moran.plot > ### Title: Moran scatterplot > ### Aliases: moran.plot > ### Keywords: spatial > > ### ** Examples > > data(afcon) > moran.plot(spNamedVec("totcon", afcon), nb2listw(paper.nb), + labels=as.character(afcon$name), pch=19) Potentially influential observations of lm(formula = wx ~ x) : dfb.1_ dfb.x dffit cov.r cook.d hat EGYPT -0.33 0.56 0.59 1.48_* 0.17 0.32_* SUDAN 0.29 -0.51 -0.53 1.34_* 0.14 0.25_* ETHIOPIA 0.10 0.18 0.41 0.83_* 0.08 0.03 RWANDA 0.45 -0.28 0.46 0.85_* 0.10 0.04 > moran.plot(scale(spNamedVec("totcon", afcon)), nb2listw(paper.nb), + labels=as.character(afcon$name), xlim=c(-2, 4), ylim=c(-2,4), pch=19) Potentially influential observations of lm(formula = wx ~ x) : dfb.1_ dfb.x dffit cov.r cook.d hat EGYPT 0.16 0.56 0.59 1.48_* 0.17 0.32_* SUDAN -0.17 -0.51 -0.53 1.34_* 0.14 0.25_* ETHIOPIA 0.37 0.18 0.41 0.83_* 0.08 0.03 RWANDA 0.36 -0.28 0.46 0.85_* 0.10 0.04 > > > > cleanEx(); ..nameEx <- "moran.test" > > ### * moran.test > > flush(stderr()); flush(stdout()) > > ### Name: moran.test > ### Title: Moran's I test for spatial autocorrelation > ### Aliases: moran.test > ### Keywords: spatial > > ### ** Examples > > data(oldcol) > moran.test(spNamedVec("CRIME", COL.OLD), nb2listw(COL.nb, style="W")) Moran's I test under randomisation data: spNamedVec("CRIME", COL.OLD) weights: nb2listw(COL.nb, style = "W") Moran I statistic standard deviate = 5.6341, p-value = 8.797e-09 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.510951264 -0.020833333 0.008908762 > moran.test(spNamedVec("CRIME", COL.OLD), nb2listw(COL.nb, style="B")) Moran's I test under randomisation data: spNamedVec("CRIME", COL.OLD) weights: nb2listw(COL.nb, style = "B") Moran I statistic standard deviate = 6.2116, p-value = 2.622e-10 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.52063815 -0.02083333 0.00759872 > moran.test(spNamedVec("CRIME", COL.OLD), nb2listw(COL.nb, style="C")) Moran's I test under randomisation data: spNamedVec("CRIME", COL.OLD) weights: nb2listw(COL.nb, style = "C") Moran I statistic standard deviate = 6.2116, p-value = 2.622e-10 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.52063815 -0.02083333 0.00759872 > moran.test(spNamedVec("CRIME", COL.OLD), nb2listw(COL.nb, style="S")) Moran's I test under randomisation data: spNamedVec("CRIME", COL.OLD) weights: nb2listw(COL.nb, style = "S") Moran I statistic standard deviate = 5.9786, p-value = 1.125e-09 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.512957470 -0.020833333 0.007971504 > moran.test(spNamedVec("CRIME", COL.OLD), nb2listw(COL.nb, style="W"), + randomisation=FALSE) Moran's I test under normality data: spNamedVec("CRIME", COL.OLD) weights: nb2listw(COL.nb, style = "W") Moran I statistic standard deviate = 5.6754, p-value = 6.92e-09 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.510951264 -0.020833333 0.008779831 > colold.lags <- nblag(COL.nb, 3) > moran.test(spNamedVec("CRIME", COL.OLD), nb2listw(colold.lags[[2]], + style="W")) Moran's I test under randomisation data: spNamedVec("CRIME", COL.OLD) weights: nb2listw(colold.lags[[2]], style = "W") Moran I statistic standard deviate = 2.6076, p-value = 0.004559 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.168485742 -0.020833333 0.005271314 > moran.test(spNamedVec("CRIME", COL.OLD), nb2listw(colold.lags[[3]], + style="W")) Moran's I test under randomisation data: spNamedVec("CRIME", COL.OLD) weights: nb2listw(colold.lags[[3]], style = "W") Moran I statistic standard deviate = -1.7896, p-value = 0.9632 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance -0.138930745 -0.020833333 0.004354683 > print(is.symmetric.nb(COL.nb)) [1] TRUE > COL.k4.nb <- knn2nb(knearneigh(coords.OLD, 4)) > print(is.symmetric.nb(COL.k4.nb)) Non-symmetric neighbours list [1] FALSE > moran.test(spNamedVec("CRIME", COL.OLD), nb2listw(COL.k4.nb, style="W")) Moran's I test under randomisation data: spNamedVec("CRIME", COL.OLD) weights: nb2listw(COL.k4.nb, style = "W") Moran I statistic standard deviate = 6.734, p-value = 8.254e-12 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.582551727 -0.020833333 0.008028696 > moran.test(spNamedVec("CRIME", COL.OLD), nb2listw(COL.k4.nb, style="W"), + randomisation=FALSE) Moran's I test under normality data: spNamedVec("CRIME", COL.OLD) weights: nb2listw(COL.k4.nb, style = "W") Moran I statistic standard deviate = 6.7859, p-value = 5.767e-12 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.582551727 -0.020833333 0.007906215 > cat("Note: non-symmetric weights matrix, use listw2U()") Note: non-symmetric weights matrix, use listw2U()> moran.test(spNamedVec("CRIME", COL.OLD), listw2U(nb2listw(COL.k4.nb, + style="W"))) Moran's I test under randomisation data: spNamedVec("CRIME", COL.OLD) weights: listw2U(nb2listw(COL.k4.nb, style = "W")) Moran I statistic standard deviate = 6.6554, p-value = 1.412e-11 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.582551727 -0.020833333 0.008219304 > moran.test(spNamedVec("CRIME", COL.OLD), listw2U(nb2listw(COL.k4.nb, + style="W")), randomisation=FALSE) Moran's I test under normality data: spNamedVec("CRIME", COL.OLD) weights: listw2U(nb2listw(COL.k4.nb, style = "W")) Moran I statistic standard deviate = 6.7042, p-value = 1.013e-11 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.582551727 -0.020833333 0.008100198 > ranks <- rank(COL.OLD$CRIME) > names(ranks) <- rownames(COL.OLD) > moran.test(ranks, nb2listw(COL.nb, style="W"), rank=TRUE) Moran's I test under randomisation data: ranks using rank correction weights: nb2listw(COL.nb, style = "W") Moran I statistic standard deviate = 6.3815, p-value = 8.766e-11 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.584333495 -0.020833333 0.008992923 > crime <- spNamedVec("CRIME", COL.OLD) > is.na(crime) <- sample(1:length(crime), 10) > res <- try(moran.test(crime, nb2listw(COL.nb, style="W"), na.action=na.fail)) Error in na.fail.default(x) : missing values in object > res [1] "Error in na.fail.default(x) : missing values in object\n" attr(,"class") [1] "try-error" > moran.test(crime, nb2listw(COL.nb, style="W"), zero.policy=TRUE, + na.action=na.omit) Moran's I test under randomisation data: crime weights: nb2listw(COL.nb, style = "W") omitted: 3, 10, 14, 18, 26, 27, 28, 40, 41, 42 Moran I statistic standard deviate = 4.3361, p-value = 7.252e-06 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.48158092 -0.02631579 0.01372000 > moran.test(crime, nb2listw(COL.nb, style="W"), zero.policy=TRUE, + na.action=na.exclude) Moran's I test under randomisation data: crime weights: nb2listw(COL.nb, style = "W") omitted: 3, 10, 14, 18, 26, 27, 28, 40, 41, 42 Moran I statistic standard deviate = 4.3361, p-value = 7.252e-06 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.48158092 -0.02631579 0.01372000 > moran.test(crime, nb2listw(COL.nb, style="W"), na.action=na.pass) Moran's I test under randomisation data: crime weights: nb2listw(COL.nb, style = "W") Moran I statistic standard deviate = 5.2041, p-value = 9.745e-08 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.468028838 -0.020833333 0.008824189 > > > > cleanEx(); ..nameEx <- "nb2blocknb" > > ### * nb2blocknb > > flush(stderr()); flush(stdout()) > > ### Name: nb2blocknb > ### Title: Block up neighbour list for location-less observations > ### Aliases: nb2blocknb > ### Keywords: spatial > > ### ** Examples > > data(boston) > summary(as.vector(table(boston.c$TOWN))) Min. 1st Qu. Median Mean 3rd Qu. Max. 1.0 2.0 4.0 5.5 7.0 30.0 > townaggr <- aggregate(boston.utm, list(town=boston.c$TOWN), mean) > block.rel <- graph2nb(relativeneigh(as.matrix(townaggr[,2:3])), as.character(townaggr[,1]), sym=TRUE) > block.rel Neighbour list object: Number of regions: 92 Number of nonzero links: 240 Percentage nonzero weights: 2.835539 Average number of links: 2.608696 > print(is.symmetric.nb(block.rel)) [1] TRUE > plot(block.rel, as.matrix(townaggr[,2:3])) > points(boston.utm, pch=18, col="lightgreen") > block.nb <- nb2blocknb(block.rel, as.character(boston.c$TOWN)) > block.nb Neighbour list object: Number of regions: 506 Number of nonzero links: 15234 Percentage nonzero weights: 5.949945 Average number of links: 30.10672 > print(is.symmetric.nb(block.nb)) [1] TRUE > plot(block.nb, boston.utm) > points(boston.utm, pch=18, col="lightgreen") > moran.test(boston.c$CMEDV, nb2listw(boston.soi)) Moran's I test under randomisation data: boston.c$CMEDV weights: nb2listw(boston.soi) Moran I statistic standard deviate = 21.7861, p-value < 2.2e-16 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.690285059 -0.001980198 0.001009685 > moran.test(boston.c$CMEDV, nb2listw(block.nb)) Moran's I test under randomisation data: boston.c$CMEDV weights: nb2listw(block.nb) Moran I statistic standard deviate = 22.4546, p-value < 2.2e-16 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.3122905961 -0.0019801980 0.0001958827 > > > > cleanEx(); ..nameEx <- "nb2lines" > > ### * nb2lines > > flush(stderr()); flush(stdout()) > > ### Name: nb2lines > ### Title: Use arc-type shapefiles for import and export of weights > ### Aliases: nb2lines listw2lines df2sn > ### Keywords: spatial > > ### ** Examples > > data(columbus) > res <- listw2lines(nb2listw(col.gal.nb), coords) > str(res$df) `data.frame': 230 obs. of 5 variables: $ i : int 1 1 2 2 2 3 3 3 3 4 ... $ j : int 2 3 1 3 4 1 2 4 5 2 ... $ i_ID:Class 'AsIs' chr [1:230] "1005" "1005" "1001" "1001" ... $ j_ID:Class 'AsIs' chr [1:230] "1001" "1006" "1005" "1006" ... $ wt : num 0.500 0.500 0.333 0.333 0.333 ... > fn <- paste(tempdir(), "nbshape", sep="/") > write.linelistShape(res$ll, res$df, file=fn) > inMap <- read.shape(fn) Shapefile Type: Line # of Shapes: 230 > str(inMap$att.data) `data.frame': 230 obs. of 5 variables: $ i : int 1 1 2 2 2 3 3 3 3 4 ... $ j : int 2 3 1 3 4 1 2 4 5 2 ... $ i_ID: Factor w/ 49 levels "1001","1002",..: 5 5 1 1 1 6 6 6 6 2 ... $ j_ID: Factor w/ 49 levels "1001","1002",..: 1 6 5 6 2 5 1 2 7 1 ... $ wt : num 0.500 0.500 0.333 0.333 0.333 ... - attr(*, "data_types")= chr "N" "N" "C" "C" ... > diffnb(sn2listw(df2sn(inMap$att.data))$neighbours, col.gal.nb) > identical(coords, unique(t(sapply(Map2lines(inMap), function(x) x[1,])))) [1] TRUE > > > > cleanEx(); ..nameEx <- "nb2listw" > > ### * nb2listw > > flush(stderr()); flush(stdout()) > > ### Name: nb2listw > ### Title: Spatial weights for neighbours lists > ### Aliases: nb2listw > ### Keywords: spatial > > ### ** Examples > > data(columbus) > cards <- card(col.gal.nb) > col.w <- nb2listw(col.gal.nb) > plot(cards, unlist(lapply(col.w$weights, sum)),xlim=c(0,10), + ylim=c(0,10), xlab="number of links", ylab="row sums of weights") > col.b <- nb2listw(col.gal.nb, style="B") > points(cards, unlist(lapply(col.b$weights, sum)), col="red") > col.c <- nb2listw(col.gal.nb, style="C") > points(cards, unlist(lapply(col.c$weights, sum)), col="green") > col.u <- nb2listw(col.gal.nb, style="U") > points(cards, unlist(lapply(col.u$weights, sum)), col="orange") > col.s <- nb2listw(col.gal.nb, style="S") > points(cards, unlist(lapply(col.s$weights, sum)), col="blue") > legend(x=c(0, 1), y=c(7, 9), legend=c("W", "B", "C", "U", "S"), + col=c("black", "red", "green", "orange", "blue"), pch=rep(1,5)) > dlist <- nbdists(col.gal.nb, coords) > dlist <- lapply(dlist, function(x) 1/x) > col.w.d <- nb2listw(col.gal.nb, glist=dlist) > summary(unlist(col.w$weights)) Min. 1st Qu. Median Mean 3rd Qu. Max. 0.1000 0.1429 0.1667 0.2130 0.2500 0.5000 > summary(unlist(col.w.d$weights)) Min. 1st Qu. Median Mean 3rd Qu. Max. 0.06977 0.13110 0.17710 0.21300 0.27120 0.67180 > > > > cleanEx(); ..nameEx <- "nb2mat" > > ### * nb2mat > > flush(stderr()); flush(stdout()) > > ### Name: nb2mat > ### Title: Spatial weights matrices for neighbours lists > ### Aliases: nb2mat listw2mat > ### Keywords: spatial > > ### ** Examples > > data(columbus) > col005 <- dnearneigh(coords, 0, 0.5, attr(col.gal.nb, "region.id")) > summary(col005) Neighbour list object: Number of regions: 49 Number of nonzero links: 170 Percentage nonzero weights: 7.080383 Average number of links: 3.469388 4 regions with no links: 1005 1006 1008 1043 Link number distribution: 0 1 2 3 4 5 6 7 8 9 4 11 5 8 3 9 2 2 3 2 11 least connected regions: 1001 1007 1018 1010 1045 1044 1046 1047 1049 1048 1015 with 1 link 2 most connected regions: 1038 1036 with 9 links > col005.w.mat <- nb2mat(col005, zero.policy=TRUE) > table(round(apply(col005.w.mat, 1, sum))) 0 1 4 45 > > > > cleanEx(); ..nameEx <- "nbdists" > > ### * nbdists > > flush(stderr()); flush(stdout()) > > ### Name: nbdists > ### Title: Spatial link distance measures > ### Aliases: nbdists > ### Keywords: spatial > > ### ** Examples > > data(columbus) > dlist <- nbdists(col.gal.nb, coords) > dlist <- lapply(dlist, function(x) 1/x) > stem(unlist(dlist)) The decimal point is at the | 1 | 1111112222223333334444444444 1 | 555555556666667777777777888888888899999999999999999999 2 | 00000000111111111111111122222222222222333333333333334444 2 | 55555555556666666666666677777777888888999999 3 | 0000111111222233334444 3 | 77779999 4 | 223344 4 | 77 5 | 001144 5 | 6 | 6 | 99 7 | 7 | 88 > > > > cleanEx(); ..nameEx <- "nblag" > > ### * nblag > > flush(stderr()); flush(stdout()) > > ### Name: nblag > ### Title: Higher order neighbours lists > ### Aliases: nblag > ### Keywords: spatial > > ### ** Examples > > data(columbus) > summary(col.gal.nb, coords) Neighbour list object: Number of regions: 49 Number of nonzero links: 230 Percentage nonzero weights: 9.579342 Average number of links: 4.693878 Link number distribution: 2 3 4 5 6 7 8 9 10 7 7 13 4 9 6 1 1 1 7 least connected regions: 1005 1008 1045 1047 1049 1048 1015 with 2 links 1 most connected region: 1017 with 10 links Summary of link distances: Min. 1st Qu. Median Mean 3rd Qu. Max. 0.1276 0.3613 0.4566 0.4694 0.5536 0.8924 The decimal point is 1 digit(s) to the left of the | 1 | 3344 1 | 99 2 | 000011333344 2 | 556677779999 3 | 000011222222223344444444 3 | 556666777777888888889999999999 4 | 00001111112233333333334444 4 | 55666666666666777777777788888899 5 | 0011112222222222222233334444 5 | 556666667788 6 | 000000112244 6 | 5577889999 7 | 11112244 7 | 557777 8 | 1144 8 | 55999999 > library(maptools) > plot(polys, border="grey", forcefill=FALSE) > plot(col.gal.nb, coords, add=TRUE) > title(main="GAL order 1 (black) and 2 (red) links") > col.lags <- nblag(col.gal.nb, 2) > summary(col.lags[[2]], coords) Neighbour list object: Number of regions: 49 Number of nonzero links: 406 Percentage nonzero weights: 16.90962 Average number of links: 8.285714 Link number distribution: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 2 5 4 2 3 5 4 2 3 7 3 4 1 1 1 1 1 least connected region: 1046 with 1 link 1 most connected region: 1032 with 17 links Summary of link distances: Min. 1st Qu. Median Mean 3rd Qu. Max. 0.3209 0.7126 0.8481 0.9023 1.0860 1.6740 The decimal point is 1 digit(s) to the left of the | 3 | 2233557799 4 | 1166777788888888 5 | 0011224455555566666688889999 6 | 11113333334455556666666666889999999999 7 | 00000011112222222233334444444455555555556666667777777777777777889999 8 | 000011111111222222222233333344444444445555555555666666999999 9 | 001111222222222233444444555555556666667777778899 10 | 0000002222223333333344666666777788889999 11 | 00112233334444555566777788 12 | 1122223333555566667777888888889999 13 | 0000001166668899 14 | 002244558888 15 | 00667788 16 | 77 > plot(col.lags[[2]], coords, add=TRUE, col="red", lty=2) > > > > cleanEx(); ..nameEx <- "nboperations" > > ### * nboperations > > flush(stderr()); flush(stdout()) > > ### Name: nb.set.operations > ### Title: Set operations on neighborhood objects > ### Aliases: intersect.nb union.nb setdiff.nb complement.nb > ### Keywords: spatial > > ### ** Examples > > data(columbus) > col.tri.nb <- tri2nb(coords) > oldpar <- par(mfrow=c(1,2)) > col.soi.nb <- graph2nb(soi.graph(col.tri.nb, coords)) > library(maptools) > plot(polys, border="grey", forcefill=FALSE) > plot(col.soi.nb, coords, add=TRUE) > title(main="Sphere of Influence Graph") > plot(polys, border="grey", forcefill=FALSE) > plot(complement.nb(col.soi.nb), coords, add=TRUE) > title(main="Complement of Sphere of Influence Graph") > par(mfrow=c(2,2)) > col2 <- droplinks(col.gal.nb, 21) > plot(intersect.nb(col.gal.nb, col2), coords) > title(main="Intersect") > plot(union.nb(col.gal.nb, col2), coords) > title(main="Union") > plot(setdiff.nb(col.gal.nb, col2), coords) > title(main="Set diff") > par(oldpar) > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "nc.sids" > > ### * nc.sids > > flush(stderr()); flush(stdout()) > > ### Name: nc.sids > ### Title: North Carolina SIDS data > ### Aliases: nc.sids ncCR85.nb ncCC89.nb sidspolys sidscents > ### Keywords: datasets > > ### ** Examples > > library(maptools) > data(nc.sids) > plot(sidspolys, border="grey", forcefill=FALSE) > plot(ncCR85.nb, sidscents, add=TRUE, col="blue") > plot(sidspolys, border="grey", forcefill=FALSE) > plot(ncCC89.nb, cbind(nc.sids$lon, nc.sids$lat), + add=TRUE, col="blue") > > > > cleanEx(); ..nameEx <- "p.adjustSP" > > ### * p.adjustSP > > flush(stderr()); flush(stdout()) > > ### Name: p.adjustSP > ### Title: Adjust local association measures' p-values > ### Aliases: p.adjustSP > ### Keywords: spatial > > ### ** Examples > > data(afcon) > oid <- order(afcon$id) > resG <- as.vector(localG(spNamedVec("totcon", afcon), nb2listw(include.self(paper.nb)))) > non <- format.pval(pnorm(2*(abs(resG)), lower.tail=FALSE), 2) > bon <- format.pval(p.adjustSP(pnorm(2*(abs(resG)), lower.tail=FALSE), paper.nb, "bonferroni"), 2) > tot <- format.pval(p.adjust(pnorm(2*(abs(resG)), lower.tail=FALSE), "bonferroni", n=length(resG)), 2) > data.frame(resG, non, bon, tot, row.names=afcon$name)[oid,] resG non bon tot THE GAMBIA -0.98383592 0.02455 0.04911 1.0000 MALI -1.69893391 0.00034 0.00272 0.0143 SENEGAL -1.46321911 0.00171 0.00857 0.0720 BENIN -1.30139679 0.00462 0.02312 0.1942 MAURITANIA -0.60496775 0.11315 0.56576 1.0000 NIGER -1.04877003 0.01797 0.14378 0.7549 IVORY COAST -1.41712454 0.00230 0.01378 0.0965 GUINEA -1.44888005 0.00188 0.01128 0.0789 BURKINA FASO -1.75085492 0.00023 0.00162 0.0097 LIBERIA -1.04053617 0.01871 0.07485 0.7860 SIERRA LEONE -0.87032623 0.04087 0.12262 1.0000 GHANA -1.10269327 0.01371 0.05485 0.5760 TOGO -0.99053008 0.02379 0.09517 0.9993 CAMEROON -1.13328519 0.01171 0.07025 0.4917 NIGERIA -1.17261672 0.00951 0.04754 0.3993 GABON -0.78935857 0.05720 0.17160 1.0000 CENTRAL AFRICAN REPUBLIC 1.17349763 0.00946 0.05678 0.3974 CHAD 0.46259185 0.17744 1.00000 1.0000 CONGO -0.20253005 0.34272 1.00000 1.0000 ZAIRE 2.02270432 2.6e-05 0.00026 0.0011 ANGOLA 1.23450728 0.00677 0.02710 0.2845 UGANDA 3.33600851 1.3e-11 7.6e-11 5.3e-10 KENYA 3.50301896 1.2e-12 7.4e-12 5.1e-11 TANZANIA 1.09843592 0.01401 0.12613 0.5886 BURUNDI 0.77417084 0.06077 0.24308 1.0000 RWANDA 1.45720776 0.00178 0.00891 0.0748 SOMALIA 1.18316273 0.00898 0.02695 0.3773 ETHIOPIA 2.62720027 7.4e-08 3.0e-07 3.1e-06 ZAMBIA 0.75273285 0.06610 0.59492 1.0000 ZIMBABWE -0.19956472 0.34490 1.00000 1.0000 MALAWI 0.21195283 0.33582 1.00000 1.0000 MOZAMBIQUE -0.28761679 0.28257 1.00000 1.0000 SOUTH AFRICA -0.86814954 0.04126 0.33004 1.0000 LESOTHO -0.29841469 0.27531 0.55062 1.0000 BOTSWANA 0.04090396 0.46740 1.00000 1.0000 SWAZILAND -0.65938417 0.09362 0.28087 1.0000 MOROCCO 0.02191606 0.48252 1.00000 1.0000 ALGERIA -0.36307938 0.23387 1.00000 1.0000 TUNISIA 0.57910139 0.12339 0.37017 1.0000 LIBYA 2.55272169 1.7e-07 1.2e-06 6.9e-06 SUDAN 4.03925235 3.3e-16 3.0e-15 1.4e-14 EGYPT 4.42133637 < 2e-16 < 2e-16 < 2e-16 > > > > cleanEx(); ..nameEx <- "plot.nb" > > ### * plot.nb > > flush(stderr()); flush(stdout()) > > ### Name: plot.nb > ### Title: Plot a neighbours list > ### Aliases: plot.nb plot.listw > ### Keywords: spatial > > ### ** Examples > > data(columbus) > plot(col.gal.nb, coords) > title(main="GAL order 1 links with first nearest neighbours in red") > col.knn <- knearneigh(coords, k=1) > plot(knn2nb(col.knn), coords, add=TRUE, col="red", length=0.08) > > > > cleanEx(); ..nameEx <- "poly2nb" > > ### * poly2nb > > flush(stderr()); flush(stdout()) > > ### Name: poly2nb > ### Title: Construct neighbours list from polygon list > ### Aliases: poly2nb > ### Keywords: spatial > > ### ** Examples > > data(columbus) > xx <- poly2nb(polys) > dxx <- diffnb(xx, col.gal.nb) Neighbour difference for region id: 1007 in relation to id: 1036 Neighbour difference for region id: 1036 in relation to id: 1007 Neighbour difference for region id: 1032 in relation to id: 1034 Neighbour difference for region id: 1034 in relation to id: 1032 Neighbour difference for region id: 1045 in relation to id: 1047 Neighbour difference for region id: 1047 in relation to id: 1045 > library(maptools) > plot(polys, border="grey", forcefill=FALSE) > plot(col.gal.nb, coords, add=TRUE) > plot(dxx, coords, add=TRUE, col="red") > title(main="Differences (red) in Columbus GAL weights (black)\nand polygon generated queen weights") > xxx <- poly2nb(polys, queen=FALSE) > dxxx <- diffnb(xxx, col.gal.nb) Neighbour difference for region id: 1003 in relation to id: 1039 Neighbour difference for region id: 1018 in relation to id: 1032 Neighbour difference for region id: 1010 in relation to id: 1019 Neighbour difference for region id: 1039 in relation to id: 1003 Neighbour difference for region id: 1019 in relation to id: 1010 Neighbour difference for region id: 1035 in relation to id: 1033 Neighbour difference for region id: 1032 in relation to id: 1018 1031 Neighbour difference for region id: 1020 in relation to id: 1033 Neighbour difference for region id: 1031 in relation to id: 1032 1030 Neighbour difference for region id: 1033 in relation to id: 1035 1020 Neighbour difference for region id: 1023 in relation to id: 1029 Neighbour difference for region id: 1030 in relation to id: 1031 Neighbour difference for region id: 1029 in relation to id: 1023 > plot(polys, border = "grey", forcefill=FALSE) > plot(col.gal.nb, coords, add = TRUE) > plot(dxxx, coords, add = TRUE, col = "red") > title(main="Differences (red) in Columbus GAL weights (black)\nand polygon generated rook weights") > cards <- card(xx) > maxconts <- which(cards == max(cards)) > if(length(maxconts) > 1) maxconts <- maxconts[1] > fg <- rep("grey", length(polys)) > fg[maxconts] <- "red" > fg[xx[[maxconts]]] <- "green" > plot(polys, col=fg, forcefill=FALSE) > title(main="Region with largest number of contiguities") > > > > cleanEx(); ..nameEx <- "predict.sarlm" > > ### * predict.sarlm > > flush(stderr()); flush(stdout()) > > ### Name: predict.sarlm > ### Title: Prediction for spatial simultaneous autoregressive linear model > ### objects > ### Aliases: predict.sarlm print.sarlm.pred > ### Keywords: spatial > > ### ** Examples > > data(oldcol) > COL.lag.eig <- lagsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, nb2listw(COL.nb)) > COL.mix.eig <- lagsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, nb2listw(COL.nb), + type="mixed") > COL.err.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, nb2listw(COL.nb)) > print(p1 <- predict(COL.mix.eig)) fit trend signal 1001 26.044311 14.8543508 11.189960 1002 44.034234 29.2632112 14.771023 1003 43.511934 25.8193818 17.692553 1004 37.656561 16.4555583 21.201002 1005 10.902976 0.3664066 10.536570 1006 36.829798 24.2905246 12.539274 1007 44.290467 27.0386615 17.251806 1008 38.853571 21.5342393 17.319331 1009 50.870854 29.5092783 21.361576 1010 16.401300 5.6029104 10.798389 1011 36.354390 28.6415353 7.712855 1012 20.452836 12.4607277 7.992108 1013 20.324088 14.4173433 5.906745 1014 19.243496 10.2606419 8.982854 1015 19.747775 12.2556861 7.492089 1016 6.962527 -2.0137491 8.976276 1017 7.452143 -6.3808928 13.833036 1018 28.481587 14.2125594 14.269028 1019 43.351392 28.0442064 15.307186 1020 50.359682 30.6608153 19.698867 1021 38.905226 24.7490977 14.156128 1022 44.724478 28.8314299 15.893048 1023 37.888974 23.7778863 14.111087 1024 45.527017 26.9163190 18.610698 1025 32.429571 17.1892401 15.240331 1026 26.490842 14.8893980 11.601444 1027 35.629158 23.4577209 12.171437 1028 35.574326 21.9001006 13.674226 1029 38.598639 23.1818442 15.416795 1030 36.602053 14.8614072 21.740646 1031 50.320031 30.1013982 20.218633 1032 53.698863 31.2094168 22.489447 1033 49.364208 26.5151201 22.849088 1034 46.262357 25.5538226 20.708534 1035 39.177121 15.7689329 23.408188 1036 54.984344 32.6590841 22.325260 1037 51.611458 33.1290203 18.482438 1038 51.998831 30.7428313 21.256000 1039 43.651605 27.4107880 16.240817 1040 44.196841 25.9409252 18.255916 1041 49.310592 29.5106497 19.799943 1042 37.995310 15.7039024 22.291408 1043 46.908709 28.2687603 18.639948 1044 28.976789 19.5389223 9.437867 1045 25.343793 17.1838200 8.159973 1046 24.006252 16.0103703 7.995882 1047 25.034907 18.4616473 6.573260 1048 10.478529 3.3573578 7.121171 1049 13.495623 5.3356502 8.159973 > print(p2 <- predict(COL.mix.eig, newdata=COL.OLD, listw=nb2listw(COL.nb))) fit trend signal 1001 29.038788 14.8543508 14.184437 1002 46.227075 29.2632112 16.963864 1003 45.640479 25.8193818 19.821097 1004 36.643520 16.4555583 20.187962 1005 14.819940 0.3664066 14.453533 1006 38.764777 24.2905246 14.474252 1007 45.715716 27.0386615 18.677055 1008 37.514611 21.5342393 15.980372 1009 49.324228 29.5092783 19.814950 1010 17.510607 5.6029104 11.907696 1011 34.973608 28.6415353 6.332072 1012 21.079100 12.4607277 8.618372 1013 19.704134 14.4173433 5.286791 1014 16.365521 10.2606419 6.104879 1015 17.063856 12.2556861 4.808170 1016 6.190282 -2.0137491 8.204031 1017 5.967260 -6.3808928 12.348153 1018 29.250462 14.2125594 15.037902 1019 41.530036 28.0442064 13.485830 1020 49.344770 30.6608153 18.683954 1021 39.508818 24.7490977 14.759720 1022 42.772692 28.8314299 13.941262 1023 37.114901 23.7778863 13.337015 1024 43.622499 26.9163190 16.706180 1025 33.247197 17.1892401 16.057957 1026 30.301331 14.8893980 15.411933 1027 38.316063 23.4577209 14.858342 1028 36.886068 21.9001006 14.985967 1029 38.970564 23.1818442 15.788720 1030 33.014615 14.8614072 18.153208 1031 48.209875 30.1013982 18.108477 1032 50.808064 31.2094168 19.598647 1033 44.555996 26.5151201 18.040876 1034 43.232773 25.5538226 17.678951 1035 35.009061 15.7689329 19.240128 1036 52.113364 32.6590841 19.454280 1037 52.189015 33.1290203 19.059995 1038 51.631805 30.7428313 20.888973 1039 46.543565 27.4107880 19.132776 1040 45.036095 25.9409252 19.095170 1041 45.907835 29.5106497 16.397185 1042 35.337110 15.7039024 19.633208 1043 43.948398 28.2687603 15.679638 1044 32.091257 19.5389223 12.552334 1045 29.647005 17.1838200 12.463185 1046 26.375304 16.0103703 10.364934 1047 27.235807 18.4616473 8.774160 1048 14.785518 3.3573578 11.428160 1049 17.798835 5.3356502 12.463185 > AIC(COL.mix.eig) [1] 376.787 > sqrt(deviance(COL.mix.eig)/length(COL.nb)) [1] 9.580773 > sqrt(sum((COL.OLD$CRIME - as.vector(p1))^2)/length(COL.nb)) [1] 9.580773 > sqrt(sum((COL.OLD$CRIME - as.vector(p2))^2)/length(COL.nb)) [1] 10.35029 > AIC(COL.err.eig) [1] 376.7609 > sqrt(deviance(COL.err.eig)/length(COL.nb)) [1] 9.776221 > sqrt(sum((COL.OLD$CRIME - as.vector(predict(COL.err.eig)))^2)/length(COL.nb)) [1] 9.776221 > sqrt(sum((COL.OLD$CRIME - as.vector(predict(COL.err.eig, newdata=COL.OLD, + listw=nb2listw(COL.nb))))^2)/length(COL.nb)) [1] 11.61744 > AIC(COL.lag.eig) [1] 374.7809 > sqrt(deviance(COL.lag.eig)/length(COL.nb)) [1] 9.772129 > sqrt(sum((COL.OLD$CRIME - as.vector(predict(COL.lag.eig)))^2)/length(COL.nb)) [1] 9.772129 > sqrt(sum((COL.OLD$CRIME - as.vector(predict(COL.lag.eig, newdata=COL.OLD, + listw=nb2listw(COL.nb))))^2)/length(COL.nb)) [1] 10.72654 > > > > cleanEx(); ..nameEx <- "probmap" > > ### * probmap > > flush(stderr()); flush(stdout()) > > ### Name: probmap > ### Title: Probability mapping for rates > ### Aliases: probmap > ### Keywords: spatial > > ### ** Examples > > data(auckland) > res <- probmap(auckland$Deaths.1977.85, 9*auckland$Under.5.1981) > brks <- c(-Inf,2,2.5,3,3.5,Inf) > cols <- grey(6:2/7) > library(maptools) > plot(auckpolys, col=cols[findInterval(res$raw*1000, brks)], forcefill=FALSE) > legend(c(70,90), c(70,95), fill=cols, legend=leglabs(brks), bty="n") > title(main="Crude (raw) estimates of infant mortality per 1000 per year") > brks <- c(-Inf,47,83,118,154,190,Inf) > cols <- cm.colors(6) > plot(auckpolys, col=cols[findInterval(res$relRisk, brks)], forcefill=FALSE) > legend(c(70,90), c(70,95), fill=cols, legend=leglabs(brks), bty="n") > title(main="Standardised mortality ratios for Auckland child deaths") > brks <- c(0,0.05,0.1,0.2,0.8,0.9,0.95,1) > cols <- cm.colors(7) > plot(auckpolys, col=cols[findInterval(res$pmap, brks)], forcefill=FALSE) > legend(c(70,90), c(70,95), fill=cols, legend=leglabs(brks), bty="n") > title(main="Poisson probabilities for Auckland child mortality") > > > > cleanEx(); ..nameEx <- "read.gal" > > ### * read.gal > > flush(stderr()); flush(stdout()) > > ### Name: read.gal > ### Title: Read a GAL lattice file into a neighbours list > ### Aliases: read.gal read.geoda > ### Keywords: spatial > > ### ** Examples > > us48.fipsno <- read.geoda(system.file("etc/weights/us48.txt", + package="spdep")[1]) > us48.q <- read.gal(system.file("etc/weights/us48_q.GAL", package="spdep")[1], + us48.fipsno$Fipsno) > us48.r <- read.gal(system.file("etc/weights/us48_rk.GAL", package="spdep")[1], + us48.fipsno$Fipsno) > data(state) > if (as.numeric(paste(version$major, version$minor, sep="")) < 19) { + m50.48 <- match(us48.fipsno$"State.name", state.name) + } else { + m50.48 <- match(us48.fipsno$"State_name", state.name) + } > plot(us48.q, as.matrix(as.data.frame(state.center))[m50.48,]) > plot(diffnb(us48.r, us48.q), + as.matrix(as.data.frame(state.center))[m50.48,], add=TRUE, col="red") Neighbour difference for region id: 4 in relation to id: 8 Neighbour difference for region id: 8 in relation to id: 4 Neighbour difference for region id: 35 in relation to id: 49 Neighbour difference for region id: 49 in relation to id: 35 > title(main="Differences between rook and queen criteria imported neighbours lists") > > > > cleanEx(); ..nameEx <- "read.gwt2nb" > > ### * read.gwt2nb > > flush(stderr()); flush(stdout()) > > ### Name: read.gwt2nb > ### Title: Read and write spatial neighbour files > ### Aliases: read.gwt2nb write.sn2gwt read.dat2listw write.sn2dat > ### Keywords: spatial > > ### ** Examples > > data(baltimore) > STATION <- baltimore$STATION > gwt1 <- read.gwt2nb(system.file("etc/weights/baltk4.GWT", package="spdep")[1], + STATION) Warning in read.gwt2nb(system.file("etc/weights/baltk4.GWT", package = "spdep")[1], : 102, 115, 208 are not destinations > cat(paste("Neighbours list symmetry;", is.symmetric.nb(gwt1, FALSE, TRUE), + "\n")) Neighbours list symmetry; FALSE > listw1 <- nb2listw(gwt1, style="B", glist=attr(gwt1, "GeoDa")$dist) > tmpGWT <- tempfile() > write.sn2gwt(listw2sn(listw1), tmpGWT) > gwt2 <- read.gwt2nb(tmpGWT, STATION) Warning in read.gwt2nb(tmpGWT, STATION) : 102, 115, 208 are not destinations > cat(paste("Neighbours list symmetry;", is.symmetric.nb(gwt2, FALSE, TRUE), + "\n")) Neighbours list symmetry; FALSE > data(oldcol) > diffnb(gwt1, gwt2) > tmpMAT <- tempfile() > COL.W <- nb2listw(COL.nb) > write.sn2dat(listw2sn(COL.W), tmpMAT) > listwmat1 <- read.dat2listw(tmpMAT) > diffnb(listwmat1$neighbours, COL.nb, verbose=TRUE) Warning in diffnb(listwmat1$neighbours, COL.nb, verbose = TRUE) : region.id differ; using ids of first list > listwmat2 <- read.dat2listw(system.file("etc/weights/wmat.dat", + package="spdep")[1]) > diffnb(listwmat1$neighbours, listwmat2$neighbours, verbose=TRUE) > > > > cleanEx(); ..nameEx <- "set.spChkOption" > > ### * set.spChkOption > > flush(stderr()); flush(stdout()) > > ### Name: set.spChkOption > ### Title: Control checking of spatial object IDs > ### Aliases: set.spChkOption get.spChkOption chkIDs spNamedVec > ### Keywords: spatial > > ### ** Examples > > data(oldcol) > rownames(COL.OLD) [1] "1001" "1002" "1003" "1004" "1005" "1006" "1007" "1008" "1009" "1010" [11] "1011" "1012" "1013" "1014" "1015" "1016" "1017" "1018" "1019" "1020" [21] "1021" "1022" "1023" "1024" "1025" "1026" "1027" "1028" "1029" "1030" [31] "1031" "1032" "1033" "1034" "1035" "1036" "1037" "1038" "1039" "1040" [41] "1041" "1042" "1043" "1044" "1045" "1046" "1047" "1048" "1049" > data(columbus) > rownames(columbus) [1] "1005" "1001" "1006" "1002" "1007" "1008" "1004" "1003" "1018" "1010" [11] "1038" "1037" "1039" "1040" "1009" "1036" "1011" "1042" "1041" "1017" [21] "1043" "1019" "1012" "1035" "1032" "1020" "1021" "1031" "1033" "1034" [31] "1045" "1013" "1022" "1044" "1023" "1046" "1030" "1024" "1047" "1016" [41] "1014" "1049" "1029" "1025" "1028" "1048" "1015" "1027" "1026" > get.spChkOption() [1] FALSE > oldChk <- set.spChkOption(TRUE) > get.spChkOption() [1] TRUE > chkIDs(COL.OLD, nb2listw(COL.nb)) [1] TRUE > chkIDs(columbus, nb2listw(col.gal.nb)) [1] TRUE > chkIDs(columbus, nb2listw(COL.nb)) [1] FALSE > tmp <- try(moran.test(spNamedVec("CRIME", COL.OLD), nb2listw(COL.nb))) > print(tmp) Moran's I test under randomisation data: spNamedVec("CRIME", COL.OLD) weights: nb2listw(COL.nb) Moran I statistic standard deviate = 5.6341, p-value = 8.797e-09 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.510951264 -0.020833333 0.008908762 > tmp <- try(moran.test(spNamedVec("CRIME", columbus), nb2listw(col.gal.nb))) > print(tmp) Moran's I test under randomisation data: spNamedVec("CRIME", columbus) weights: nb2listw(col.gal.nb) Moran I statistic standard deviate = 5.3427, p-value = 4.578e-08 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.485770914 -0.020833333 0.008991121 > tmp <- try(moran.test(spNamedVec("CRIME", columbus), nb2listw(COL.nb))) Error in moran.test(spNamedVec("CRIME", columbus), nb2listw(COL.nb)) : Check of data and weights ID integrity failed > print(tmp) [1] "Error in moran.test(spNamedVec(\"CRIME\", columbus), nb2listw(COL.nb)) : \n\tCheck of data and weights ID integrity failed\n" attr(,"class") [1] "try-error" > set.spChkOption(FALSE) [1] TRUE > get.spChkOption() [1] FALSE > moran.test(spNamedVec("CRIME", columbus), nb2listw(COL.nb)) Moran's I test under randomisation data: spNamedVec("CRIME", columbus) weights: nb2listw(COL.nb) Moran I statistic standard deviate = 3.8402, p-value = 6.147e-05 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.341628707 -0.020833333 0.008908762 > tmp <- try(moran.test(spNamedVec("CRIME", columbus), nb2listw(COL.nb), + spChk=TRUE)) Error in moran.test(spNamedVec("CRIME", columbus), nb2listw(COL.nb), spChk = TRUE) : Check of data and weights ID integrity failed > print(tmp) [1] "Error in moran.test(spNamedVec(\"CRIME\", columbus), nb2listw(COL.nb), spChk = TRUE) : \n\tCheck of data and weights ID integrity failed\n" attr(,"class") [1] "try-error" > set.spChkOption(oldChk) [1] FALSE > get.spChkOption() [1] FALSE > > > > cleanEx(); ..nameEx <- "similar.listw" > > ### * similar.listw > > flush(stderr()); flush(stdout()) > > ### Name: similar.listw > ### Title: Create symmetric similar weights lists > ### Aliases: similar.listw > ### Keywords: spatial > > ### ** Examples > > data(oldcol) > COL.W <- nb2listw(COL.nb, style="W") > COL.S <- nb2listw(COL.nb, style="S") > log(prod(1 - 0.5 * eigenw(COL.W))) [1] -1.627660 > log(prod(1 - 0.5 * eigenw(similar.listw(COL.W)))) [1] -1.627660 > Det <- getMethod("det", "matrix.csr") > log(Det(asMatrixCsrIrW(asMatrixCsrListw(similar.listw(COL.W)), 0.5))) [1] -1.627660 > log(prod(1 - 0.5 * eigenw(COL.S))) [1] -1.602757 > log(prod(1 - 0.5 * eigenw(similar.listw(COL.S)))) [1] -1.602757 > log(Det(asMatrixCsrIrW(asMatrixCsrListw(similar.listw(COL.S)), 0.5))) [1] -1.602757 > > > > cleanEx(); ..nameEx <- "sp.correlogram" > > ### * sp.correlogram > > flush(stderr()); flush(stdout()) > > ### Name: sp.correlogram > ### Title: Spatial correlogram > ### Aliases: sp.correlogram plot.spcor print.spcor > ### Keywords: spatial > > ### ** Examples > > data(nc.sids) > ft.SID74 <- sqrt(1000)*(sqrt(nc.sids$SID74/nc.sids$BIR74) + + sqrt((nc.sids$SID74+1)/nc.sids$BIR74)) > tr.SIDS74 <- ft.SID74*sqrt(nc.sids$BIR74) > names(tr.SIDS74) <- rownames(nc.sids) > print(sp.correlogram(ncCC89.nb, tr.SIDS74, order=8, method="corr", + zero.policy=TRUE)) Spatial correlogram for tr.SIDS74 method: Spatial autocorrelation 1 2 3 4 5 6 0.38193491 0.47679881 0.11740653 0.09935901 0.27819159 0.30153012 7 8 -0.05150923 0.05283813 > print(sp.correlogram(ncCC89.nb, tr.SIDS74, order=8, method="I", + zero.policy=TRUE)) Spatial correlogram for tr.SIDS74 method: Moran's I estimate expectation variance 1 0.231168467 -0.01030928 0.005537764 2 0.224693022 -0.01030928 0.003781723 3 0.019357594 -0.01030928 0.002938570 4 0.004225498 -0.01030928 0.002497404 5 0.087554814 -0.01030928 0.002287489 6 0.075836203 -0.01030928 0.002158346 7 -0.075224296 -0.01030928 0.002228181 8 -0.026106302 -0.01030928 0.002521056 > plot(sp.correlogram(ncCC89.nb, tr.SIDS74, order=8, method="I", + zero.policy=TRUE)) > plot(sp.correlogram(ncCC89.nb, tr.SIDS74, order=8, method="corr", + zero.policy=TRUE)) > drop.no.neighs <- !(1:length(ncCC89.nb) %in% which(card(ncCC89.nb) == 0)) > sub.ncCC89.nb <- subset(ncCC89.nb, drop.no.neighs) > plot(sp.correlogram(sub.ncCC89.nb, subset(tr.SIDS74, drop.no.neighs), + order=8, method="corr")) > > > > cleanEx(); ..nameEx <- "sp.mantel.mc" > > ### * sp.mantel.mc > > flush(stderr()); flush(stdout()) > > ### Name: sp.mantel.mc > ### Title: Mantel-Hubert spatial general cross product statistic > ### Aliases: sp.mantel.mc plot.mc.sim > ### Keywords: spatial > > ### ** Examples > > data(oldcol) > sim1 <- sp.mantel.mc(spNamedVec("CRIME", COL.OLD), nb2listw(COL.nb), + nsim=99, type="geary", alternative="less") > sim1 Mantel permutation test for geary measure data: spNamedVec("CRIME", COL.OLD) weights: nb2listw(COL.nb) number of simulations + 1: 100 statistic = 51.9273, observed rank = 1, p-value = 0.01 alternative hypothesis: less sample estimates: mean of permutations sd of permutations 97.467742 7.576027 > plot(sim1) > sp.mantel.mc(spNamedVec("CRIME", COL.OLD), nb2listw(COL.nb), nsim=99, + type="sokal", alternative="less") Mantel permutation test for sokal measure data: spNamedVec("CRIME", COL.OLD) weights: nb2listw(COL.nb) number of simulations + 1: 100 statistic = 36.6946, observed rank = 1, p-value = 0.01 alternative hypothesis: less sample estimates: mean of permutations sd of permutations 55.979566 3.252045 > sp.mantel.mc(spNamedVec("CRIME", COL.OLD), nb2listw(COL.nb), nsim=99, + type="moran") Mantel permutation test for moran measure data: spNamedVec("CRIME", COL.OLD) weights: nb2listw(COL.nb) number of simulations + 1: 100 statistic = 24.5257, observed rank = 100, p-value = 0.01 alternative hypothesis: greater sample estimates: mean of permutations sd of permutations -0.5243846 4.5409376 > > > > cleanEx(); ..nameEx <- "spweights.constants" > > ### * spweights.constants > > flush(stderr()); flush(stdout()) > > ### Name: spweights.constants > ### Title: Provides constants for spatial weights matrices > ### Aliases: spweights.constants Szero > ### Keywords: spatial > > ### ** Examples > > data(oldcol) > B <- spweights.constants(nb2listw(COL.nb, style="B")) > W <- spweights.constants(nb2listw(COL.nb, style="W")) > C <- spweights.constants(nb2listw(COL.nb, style="C")) > S <- spweights.constants(nb2listw(COL.nb, style="S")) > U <- spweights.constants(nb2listw(COL.nb, style="U")) > print(data.frame(rbind(unlist(B), unlist(W), unlist(C), unlist(S), unlist(U)), + row.names=c("B", "W", "C", "S", "U"))) n n1 n2 n3 nn S0 S1 S2 B 49 48 47 46 2401 232 464.00000000 5.136000e+03 W 49 48 47 46 2401 49 23.29434146 2.048729e+02 C 49 48 47 46 2401 49 20.69827586 2.291085e+02 S 49 48 47 46 2401 49 21.25561347 2.134568e+02 U 49 48 47 46 2401 1 0.00862069 9.542212e-02 > > > > cleanEx(); ..nameEx <- "subset.listw" > > ### * subset.listw > > flush(stderr()); flush(stdout()) > > ### Name: subset.listw > ### Title: Subset a spatial weights list > ### Aliases: subset.listw > ### Keywords: spatial > > ### ** Examples > > data(columbus) > to.be.dropped <- c(31, 34, 36, 39, 42, 46) > pre <- nb2listw(col.gal.nb) > print(pre) Characteristics of weights list object: Neighbour list object: Number of regions: 49 Number of nonzero links: 230 Percentage nonzero weights: 9.579342 Average number of links: 4.693878 Weights style: W Weights constants summary: n nn S0 S1 S2 W 49 2401 49 23.48489 204.6687 > post <- subset(pre, !(1:length(col.gal.nb) %in% to.be.dropped)) > print(post) Characteristics of weights list object: Neighbour list object: Number of regions: 43 Number of nonzero links: 212 Percentage nonzero weights: 11.46566 Average number of links: 4.930233 Weights style: W Weights constants summary: n nn S0 S1 S2 W 43 1849 43 19.26584 178.4604 > > > > cleanEx(); ..nameEx <- "subset.nb" > > ### * subset.nb > > flush(stderr()); flush(stdout()) > > ### Name: subset.nb > ### Title: Subset a neighbours list > ### Aliases: subset.nb > ### Keywords: spatial > > ### ** Examples > > data(columbus) > plot(col.gal.nb, coords) > to.be.dropped <- c(31, 34, 36, 39, 42, 46) > text(coords[to.be.dropped,1], coords[to.be.dropped,2], labels=to.be.dropped, + pos=2, offset=0.3) > sub.col.gal.nb <- subset(col.gal.nb, + !(1:length(col.gal.nb) %in% to.be.dropped)) > plot(sub.col.gal.nb, coords[-to.be.dropped,], col="red", add=TRUE) > which(!(attr(col.gal.nb, "region.id") %in% + attr(sub.col.gal.nb, "region.id"))) [1] 31 34 36 39 42 46 > > > > cleanEx(); ..nameEx <- "summary.nb" > > ### * summary.nb > > flush(stderr()); flush(stdout()) > > ### Name: summary.nb > ### Title: Print and summary function for neighbours and weights lists > ### Aliases: summary.nb print.nb summary.listw print.listw > ### Keywords: spatial > > ### ** Examples > > data(columbus) > col.gal.nb Neighbour list object: Number of regions: 49 Number of nonzero links: 230 Percentage nonzero weights: 9.579342 Average number of links: 4.693878 > summary(col.gal.nb, coords) Neighbour list object: Number of regions: 49 Number of nonzero links: 230 Percentage nonzero weights: 9.579342 Average number of links: 4.693878 Link number distribution: 2 3 4 5 6 7 8 9 10 7 7 13 4 9 6 1 1 1 7 least connected regions: 1005 1008 1045 1047 1049 1048 1015 with 2 links 1 most connected region: 1017 with 10 links Summary of link distances: Min. 1st Qu. Median Mean 3rd Qu. Max. 0.1276 0.3613 0.4566 0.4694 0.5536 0.8924 The decimal point is 1 digit(s) to the left of the | 1 | 3344 1 | 99 2 | 000011333344 2 | 556677779999 3 | 000011222222223344444444 3 | 556666777777888888889999999999 4 | 00001111112233333333334444 4 | 55666666666666777777777788888899 5 | 0011112222222222222233334444 5 | 556666667788 6 | 000000112244 6 | 5577889999 7 | 11112244 7 | 557777 8 | 1144 8 | 55999999 > col.listw <- nb2listw(col.gal.nb, style="W") > col.listw Characteristics of weights list object: Neighbour list object: Number of regions: 49 Number of nonzero links: 230 Percentage nonzero weights: 9.579342 Average number of links: 4.693878 Weights style: W Weights constants summary: n nn S0 S1 S2 W 49 2401 49 23.48489 204.6687 > summary(col.listw) Characteristics of weights list object: Neighbour list object: Number of regions: 49 Number of nonzero links: 230 Percentage nonzero weights: 9.579342 Average number of links: 4.693878 Link number distribution: 2 3 4 5 6 7 8 9 10 7 7 13 4 9 6 1 1 1 7 least connected regions: 1005 1008 1045 1047 1049 1048 1015 with 2 links 1 most connected region: 1017 with 10 links Weights style: W Weights constants summary: n nn S0 S1 S2 W 49 2401 49 23.48489 204.6687 > > > > cleanEx(); ..nameEx <- "summary.sarlm" > > ### * summary.sarlm > > flush(stderr()); flush(stdout()) > > ### Name: summary.sarlm > ### Title: summary method for class sarlm > ### Aliases: summary.sarlm print.sarlm print.summary.sarlm > ### Keywords: spatial > > ### ** Examples > > data(oldcol) > COL.mix.eig <- lagsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, + nb2listw(COL.nb), type="mixed", method="eigen", quiet=FALSE) Spatial mixed autoregressive model Jacobian calculated using neighbourhood matrix eigenvalues Computing eigenvalues ... (eigen) rho: -0.5674437 function value: -193.3853 (eigen) rho: 0.03126655 function value: -183.7273 (eigen) rho: 0.4012898 function value: -181.4045 (eigen) rho: 0.5248287 function value: -181.5759 (eigen) rho: 0.4184076 function value: -181.3946 (eigen) rho: 0.4255293 function value: -181.3935 (eigen) rho: 0.4263929 function value: -181.3935 (eigen) rho: 0.426337 function value: -181.3935 (eigen) rho: 0.4263355 function value: -181.3935 (eigen) rho: 0.4263355 function value: -181.3935 (eigen) rho: 0.4263355 function value: -181.3935 > summary(COL.mix.eig, correlation=TRUE) Call: lagsarlm(formula = CRIME ~ INC + HOVAL, data = COL.OLD, listw = nb2listw(COL.nb), type = "mixed", method = "eigen", quiet = FALSE) Residuals: Min 1Q Median 3Q Max -37.47829 -6.46731 -0.33835 6.05200 22.62969 Type: mixed Coefficients: (asymptotic standard errors) Estimate Std. Error z value Pr(>|z|) (Intercept) 42.822415 12.667205 3.3806 0.0007233 INC -0.914223 0.331094 -2.7612 0.0057586 HOVAL -0.293738 0.089212 -3.2926 0.0009927 lag.INC -0.520284 0.565129 -0.9206 0.3572355 lag.HOVAL 0.245640 0.178917 1.3729 0.1697756 Rho: 0.42634 LR test value: 5.3693 p-value: 0.020494 Asymptotic standard error: 0.15623 z-value: 2.7288 p-value: 0.0063561 Wald statistic: 7.4465 p-value: 0.0063561 Log likelihood: -181.3935 for mixed model ML residual variance (sigma squared): 91.791, (sigma: 9.5808) Number of observations: 49 Number of parameters estimated: 7 AIC: 376.79, (AIC for lm: 380.16) LM test for residual autocorrelation test value: 0.28919 p-value: 0.59074 Correlation of Coefficients: sigma rho (Intercept) INC HOVAL lag.INC rho -0.18 (Intercept) 0.16 -0.89 INC -0.03 0.14 -0.19 HOVAL 0.02 -0.09 0.03 -0.45 lag.INC -0.09 0.49 -0.53 -0.36 0.05 lag.HOVAL -0.04 0.19 -0.36 0.19 -0.24 -0.41 > > > > cleanEx(); ..nameEx <- "testnb" > > ### * testnb > > flush(stderr()); flush(stdout()) > > ### Name: is.symmetric.nb > ### Title: Test a neighbours list for symmetry > ### Aliases: is.symmetric.nb sym.attr.nb make.sym.nb is.symmetric.glist > ### Keywords: spatial > > ### ** Examples > > data(columbus) > print(is.symmetric.nb(col.gal.nb, verbose=TRUE, force=TRUE)) [1] TRUE > k4 <- knn2nb(knearneigh(coords, k=4), row.names=rownames(columbus)) > k4 <- sym.attr.nb(k4) > print(is.symmetric.nb(k4)) Non-symmetric neighbours list [1] FALSE > k4.sym <- make.sym.nb(k4) > print(is.symmetric.nb(k4.sym)) [1] TRUE > > > > cleanEx(); ..nameEx <- "tri2nb" > > ### * tri2nb > > flush(stderr()); flush(stdout()) > > ### Name: tri2nb > ### Title: Neighbours list from tri object > ### Aliases: tri2nb > ### Keywords: spatial > > ### ** Examples > > require(tripack) [1] TRUE > data(columbus) > col.tri.nb <- tri2nb(coords, row.names=rownames(columbus)) > library(maptools) > plot(polys, border="grey", forcefill=FALSE) > plot(col.tri.nb, coords, add=TRUE) > title(main="Raw triangulation links") > x <- seq(0,1,0.1) > y <- seq(0,2,0.2) > xy <- expand.grid(x, y) > try(xy.nb <- tri2nb(xy)) Error in tri.mesh(x = coords[, 1], y = coords[, 2]) : error in trmesh > seed <- 1234 > xid <- sample(1:nrow(xy)) > xy.nb <- tri2nb(xy[xid,]) > plot(xy.nb, xy[xid,]) > > > > cleanEx(); ..nameEx <- "used.cars" > > ### * used.cars > > flush(stderr()); flush(stdout()) > > ### Name: used.cars > ### Title: US 1960 used car prices > ### Aliases: used.cars usa48.nb > ### Keywords: datasets > > ### ** Examples > > data(used.cars) > moran.test(spNamedVec("price.1960", used.cars), nb2listw(usa48.nb)) Moran's I test under randomisation data: spNamedVec("price.1960", used.cars) weights: nb2listw(usa48.nb) Moran I statistic standard deviate = 8.1752, p-value < 2.2e-16 alternative hypothesis: greater sample estimates: Moran I statistic Expectation Variance 0.783561543 -0.021276596 0.009692214 > moran.plot(spNamedVec("price.1960", used.cars), nb2listw(usa48.nb), + labels=rownames(used.cars)) Potentially influential observations of lm(formula = wx ~ x) : dfb.1_ dfb.x dffit cov.r cook.d hat ID 0.01 -0.01 -0.01 1.15_* 0.00 0.09 UT -0.07 0.07 0.08 1.13_* 0.00 0.08 WA -0.27 0.29 0.45 0.86_* 0.09 0.03 WI 0.38 -0.36 0.51 0.86_* 0.12 0.04 WY 0.08 -0.08 -0.09 1.14_* 0.00 0.09 > uc.lm <- lm(price.1960 ~ tax.charges, data=used.cars) > summary(uc.lm) Call: lm(formula = price.1960 ~ tax.charges, data = used.cars) Residuals: Min 1Q Median 3Q Max -116.701 -45.053 -1.461 43.400 107.807 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1435.7506 27.5796 52.058 < 2e-16 *** tax.charges 0.6872 0.1754 3.918 0.000294 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 57.01 on 46 degrees of freedom Multiple R-Squared: 0.2503, Adjusted R-squared: 0.234 F-statistic: 15.35 on 1 and 46 DF, p-value: 0.0002939 > lm.morantest(uc.lm, nb2listw(usa48.nb)) Global Moran's I for regression residuals data: model: lm(formula = price.1960 ~ tax.charges, data = used.cars) weights: nb2listw(usa48.nb) Moran I statistic standard deviate = 6.3869, p-value = 8.466e-11 alternative hypothesis: greater sample estimates: Observed Moran's I Expectation Variance 0.574817771 -0.030300549 0.008976437 > lm.morantest.sad(uc.lm, nb2listw(usa48.nb)) Saddlepoint approximation for global Moran's I (Barndorff-Nielsen formula) data: model:lm(formula = price.1960 ~ tax.charges, data = used.cars) weights: nb2listw(usa48.nb) Saddlepoint approximation = 5.6688, p-value = 7.19e-09 alternative hypothesis: greater sample estimates: Observed Moran's I 0.5748178 > lm.LMtests(uc.lm, nb2listw(usa48.nb)) Lagrange multiplier diagnostics for spatial dependence data: model: lm(formula = price.1960 ~ tax.charges, data = used.cars) weights: nb2listw(usa48.nb) LMerr = 31.7926, df = 1, p-value = 1.715e-08 > uc.err <- errorsarlm(price.1960 ~ tax.charges, data=used.cars, + nb2listw(usa48.nb), tol.solve=1.0e-13, tol.opt=.Machine$double.eps^0.3) > summary(uc.err) Call:errorsarlm(formula = price.1960 ~ tax.charges, data = used.cars, listw = nb2listw(usa48.nb), tol.solve = 1e-13, tol.opt = .Machine$double.eps^0.3) Residuals: Min 1Q Median 3Q Max -74.8241 -17.4590 2.4061 21.2784 64.5967 Type: error Coefficients: (asymptotic standard errors) Estimate Std. Error z value Pr(>|z|) (Intercept) 1528.34521 31.96239 47.8170 <2e-16 tax.charges 0.08831 0.11923 0.7406 0.4589 Lambda: 0.81899 LR test value: 40.899 p-value: 1.6030e-10 Asymptotic standard error: 0.074052 z-value: 11.06 p-value: < 2.22e-16 Wald statistic: 122.32 p-value: < 2.22e-16 Log likelihood: -240.7163 for error model ML residual variance (sigma squared): 1043.9, (sigma: 32.309) Number of observations: 48 Number of parameters estimated: 4 AIC: 489.43, (AIC for lm: 528.33) > uc.lag <- lagsarlm(price.1960 ~ tax.charges, data=used.cars, + nb2listw(usa48.nb), tol.solve=1.0e-13, tol.opt=.Machine$double.eps^0.3) > summary(uc.lag) Call:lagsarlm(formula = price.1960 ~ tax.charges, data = used.cars, listw = nb2listw(usa48.nb), tol.solve = 1e-13, tol.opt = .Machine$double.eps^0.3) Residuals: Min 1Q Median 3Q Max -77.6781 -16.9505 4.2498 19.5486 58.9811 Type: lag Coefficients: (asymptotic standard errors) Estimate Std. Error z value Pr(>|z|) (Intercept) 309.42997 123.03283 2.5150 0.01190 tax.charges 0.16711 0.10212 1.6364 0.10175 Rho: 0.78302 LR test value: 42.681 p-value: 6.4426e-11 Asymptotic standard error: 0.081637 z-value: 9.5914 p-value: < 2.22e-16 Wald statistic: 91.995 p-value: < 2.22e-16 Log likelihood: -239.8252 for lag model ML residual variance (sigma squared): 1036.7, (sigma: 32.197) Number of observations: 48 Number of parameters estimated: 4 AIC: 487.65, (AIC for lm: 528.33) LM test for residual autocorrelation test value: 2.1139 p-value: 0.14596 > uc.lag1 <- lagsarlm(price.1960 ~ 1, data=used.cars, + nb2listw(usa48.nb), tol.solve=1.0e-13, tol.opt=.Machine$double.eps^0.3) > summary(uc.lag1) Call: lagsarlm(formula = price.1960 ~ 1, data = used.cars, listw = nb2listw(usa48.nb), tol.solve = 1e-13, tol.opt = .Machine$double.eps^0.3) Residuals: Min 1Q Median 3Q Max -76.152 -18.221 5.249 21.631 63.498 Type: lag Coefficients: (asymptotic standard errors) Estimate Std. Error z value Pr(>|z|) (Intercept) 263.50 109.61 2.4038 0.01622 Rho: 0.82919 LR test value: 54.202 p-value: 1.8086e-13 Asymptotic standard error: 0.070993 z-value: 11.68 p-value: < 2.22e-16 Wald statistic: 136.42 p-value: < 2.22e-16 Log likelihood: -240.977 for lag model ML residual variance (sigma squared): 1045.4, (sigma: 32.333) Number of observations: 48 Number of parameters estimated: 3 AIC: 487.95, (AIC for lm: 540.16) LM test for residual autocorrelation test value: 2.1495 p-value: 0.14262 > uc.err1 <- errorsarlm(price.1960 ~ 1, data=used.cars, + nb2listw(usa48.nb), tol.solve=1.0e-13, tol.opt=.Machine$double.eps^0.3) > summary(uc.err1) Call: errorsarlm(formula = price.1960 ~ 1, data = used.cars, listw = nb2listw(usa48.nb), tol.solve = 1e-13, tol.opt = .Machine$double.eps^0.3) Residuals: Min 1Q Median 3Q Max -76.152 -18.221 5.249 21.631 63.498 Type: error Coefficients: (asymptotic standard errors) Estimate Std. Error z value Pr(>|z|) (Intercept) 1542.607 27.321 56.462 < 2.2e-16 Lambda: 0.82919 LR test value: 54.202 p-value: 1.8086e-13 Asymptotic standard error: 0.070993 z-value: 11.68 p-value: < 2.22e-16 Wald statistic: 136.42 p-value: < 2.22e-16 Log likelihood: -240.977 for error model ML residual variance (sigma squared): 1045.4, (sigma: 32.333) Number of observations: 48 Number of parameters estimated: 3 AIC: 487.95, (AIC for lm: 540.16) > > > > cleanEx(); ..nameEx <- "write.nb.gal" > > ### * write.nb.gal > > flush(stderr()); flush(stdout()) > > ### Name: write.nb.gal > ### Title: Write a neighbours list as a GAL lattice file > ### Aliases: write.nb.gal > ### Keywords: spatial > > ### ** Examples > > data(columbus) > ind <- rownames(columbus) > GALfile <- tempfile("GAL") > write.nb.gal(col.gal.nb, GALfile, oldstyle=FALSE, ind="ind") > col.queen <- read.gal(GALfile, region.id=ind) > unlink(GALfile) > summary(diffnb(col.queen, col.gal.nb)) Neighbour list object: Number of regions: 49 Number of nonzero links: 0 Percentage nonzero weights: 0 Average number of links: 0 49 regions with no links: 1005 1001 1006 1002 1007 1008 1004 1003 1018 1010 1038 1037 1039 1040 1009 1036 1011 1042 1041 1017 1043 1019 1012 1035 1032 1020 1021 1031 1033 1034 1045 1013 1022 1044 1023 1046 1030 1024 1047 1016 1014 1049 1029 1025 1028 1048 1015 1027 1026 Link number distribution: 0 49 > > > > ### *