Description Usage Arguments Details Value Control arguments Author(s) See Also Examples
This function compute the global spatial runs test for spatial independence of a categorical spatial data set.
1 2 3 |
formula |
a symbolic description of the factor (optional). |
data |
an (optional) data frame or a sf object containing the variable to testing for. |
xf |
a factor (optional). |
listw |
una lista de vecinos (tipo knn o nb) o una matrix W que indique el orden de cada $m_i-entorno$ (por ejemplo de inversa distancia). Para calcular el número de rachas en cada m_i-entorno debe establecerse un orden, por ejemplo del vecino más próximo al más lejano. |
alternative |
a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater" or "less". |
distr |
distribution of the test "asymptotic" (default) or "bootstrap" |
nsim |
Number of permutations to obtain confidence intervals (CI). Default value is NULL to don't get CI of number of runs. |
control |
List of additional control arguments. |
El orden de las vecindades ($m_i-entornos$) es crítico.
Para obetener el número de rachas observadas en cada $m_i-entorno$,
cada elemento debe asociarse a un conjunto de vecinos ordenados por proximidad.
Tres clases de listas pueden incluirse para identificar $m_i-entornos$:
knn | Matrices de la clase knn que consideran los vecinos por orden de proximidad.
Ver knn2knn_order |
nb | Si los vecinos se obtiene a partir de un objeto sf, el código internamente llamará
a la función nb2nb_order los ordenará en orden de proximidad de los centroides. |
matrix | Si se introduce simplemente una matriz basasa en la inversa de la distancia,
también se llamará internamente a la función nb2nb_order para transformar la matriz
de la clase matrix a una matriz de la clase nb con vecinos ordenados. |
Two alternative sets of arguments can be included in this function to compute the spatial runs test:
Alternative 1 | A factor (xf) and a list of neighborhood (listw ) of the class knn. |
Alternative 2 | A sf object (data) and formula to specify the factor. A list of neighborhood (listw) |
A object of the htest and sprunstest class
data.name | a character string giving the names of the data. |
method | the type of test applied (). |
SR | total number of runs |
dnr | empirical distribution of the number of runs |
statistic | Value of the homogeneity runs statistic. Negative sign indicates global homogeneity |
alternative | a character string describing the alternative hypothesis. |
p.value | p-value of the SRQ |
pseudo.value | the pseudo p-value of the SRQ test if nsim is not NULL |
MeanNeig | Mean of the Maximum number of neighborhood |
MaxNeig | Maximum number of neighborhood |
listw | The list of neighborhood |
nsim | number of boots (only for boots version) |
SRGP | nsim simulated values of statistic. |
SRLP | matrix with the number of runs for eacl localization. |
seedinit | Numerical value for the seed (only for boot version). Default value seedinit=123 |
Fernando López | fernando.lopez@upct.es |
Román Mínguez | roman.minguez@uclm.es |
Antonio Páez | paezha@gmail.com |
Manuel Ruiz | manuel.ruiz@upct.es |
@references
Ruiz, M., López, F., and Páez, A. (2010). A test for global and local homogeneity of categorical data based on spatial runs. Geographical Analysis.
local.sp.runs.test
, dgp.spq
, Q.test
,
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | # Case 1: SRQ test based on factor and knn
rm(list = ls())
n <- 100
cx <- runif(n)
cy <- runif(n)
x <- cbind(cx,cy)
listw <- knearneigh(cbind(cx,cy), k=3)
p <- c(1/6,3/6,2/6)
rho <- 0.5
xf <- dgp.spq(listw = listw, p = p, rho = rho)
srq <- sp.runs.test(xf = xf, listw = listw)
print(srq)
plot(srq)
# Version boots
control <- list(seedinit = 1255)
srq <- sp.runs.test(xf = xf, listw = listw, distr = "bootstrap" , nsim = 299, control = control)
print(srq)
plot(srq)
# Case 2: SRQ test with formula, a sf object (points) and knn
rm(list = ls())
data("FastFood")
x <- cbind(FastFood.sf$Lon,FastFood.sf$Lat)
listw <- spdep::knearneigh(x, k=4)
formula <- ~ Type
srq <- sp.runs.test(formula = formula, data = FastFood.sf, listw = listw)
print(srq)
plot(srq)
# Version boots
srq <- sp.runs.test(formula = formula, data = FastFood.sf, listw = listw, distr = "bootstrap", nsim = 199)
print(srq)
plot(srq)
# Case 3: SRQ test (permutation) using formula with a sf object (polygons) and nb
rm(list = ls())
library(sf)
fname <- system.file("shape/nc.shp", package="sf")
nc <- st_read(fname)
listw <- spdep::poly2nb(as(nc,"Spatial"), queen = FALSE)
p <- c(1/6,3/6,2/6)
rho = 0.5
co <- sf::st_coordinates(sf::st_centroid(nc))
nc$xf <- dgp.spq(listw = listw, p = p, rho = rho)
plot(nc["xf"])
formula <- ~ xf
srq <- sp.runs.test(formula = formula, data = nc, listw = listw, distr = "bootstrap", nsim = 399)
print(srq)
plot(srq)
# Case 4: SRQ test (Asymptotic) using formula with a sf object (polygons) and nb
rm(list = ls())
# PARA PROBAR ELEMENTOS SIN VECINOS
data(Spain)
listw <- spdep::poly2nb(spain.sf, queen = FALSE)
plot(spain.sf["Coast"])
formula <- ~ Coast
srq <- sp.runs.test(formula = formula, data = spain.sf, listw = listw)
print(srq)
plot(srq)
# Version boots
srq <- sp.runs.test(formula = formula, data = spain.sf, listw = listw, distr = "bootstrap", nsim = 299)
print(srq)
plot(srq)
# Case 5: SRQ test based on a distance matrix (inverse distance)
rm(list = ls())
N <- 100
cx <- runif(N)
cy <- runif(N)
data <- as.data.frame(cbind(cx,cy))
data <- st_as_sf(data,coords = c("cx","cy"))
n = dim(data)[1]
dis <- 1/matrix(as.numeric(st_distance(data,data)),ncol=n,nrow=n)
diag(dis) <- 0
dis <- (dis < quantile(dis,.10))*dis
p <- c(1/6,3/6,2/6)
rho <- 0.5
xf <- dgp.spq(listw = dis , p = p, rho = rho)
srq <- sp.runs.test(xf = xf, listw = dis)
print(srq)
plot(srq)
srq <- sp.runs.test(xf = xf, listw = dis, data = data)
print(srq)
plot(srq)
# Version boots
srq <- sp.runs.test(xf = xf, listw = dis, data = data, distr = "bootstrap", nsim = 299)
print(srq)
plot(srq)
# Case 6: SRQ test based on a distance matrix (inverse distance)
rm(list = ls())
data("FastFood")
n = dim(FastFood.sf)[1]
dis <- 1000000/matrix(as.numeric(st_distance(FastFood.sf,FastFood.sf)), ncol = n, nrow = n)
diag(dis) <- 0
dis <- (dis < quantile(dis,.005))*dis
p <- c(1/6,3/6,2/6)
rho = 0.5
co <- sf::st_coordinates(sf::st_centroid(FastFood.sf))
FastFood.sf$xf <- dgp.spq(p = p, listw = dis, rho = rho)
plot(FastFood.sf["xf"])
formula <- ~ xf
# Version boots
srq <- sp.runs.test(formula = formula, data = FastFood.sf, listw = dis, distr = "bootstrap", nsim = 299)
print(srq)
plot(srq)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.