Learn R Programming

⚠️There's a newer version (0.1.3.6) of this package.Take me there.

spqdata

spqdata

[ [ [

The goal of spqdep is to provide tools for the analysis of spatial qualitative data.

Installation

You can install the released version of spqdata from CRAN with:

#install.packages("spqdata")

And the development version from GitHub with:

# install.packages("devtools")
#devtools::install_github("f8l5h9/spqdata")

Abstract

Qualitative spatial variables are important in many fields of research. However, unlike the decades-worth of research devoted to the spatial association of quantitative variables, the exploratory analysis of spatial qualitative variables is relatively less developed. The objective of the present paper is to present a new R-package to test for spatial dependence in categorical spatial data. Several tests have been proposed, namely, the classical joint count statistics, the Q-test based on symbolic dynamics, the Scan-test based on scan methodology and a new spatial test based on spatial-runs. All tests can be applied to categorical spatial cross-section data with two or more categories and asymptotic and bootstrap permutation distribution are implemented. The R package is completely documented, including several examples and an user-guide is available as a vignette. The package spqdep is available in CRAN and is ideal for research and teaching activities.

Example

This is a basic example which shows you how to solve a common problem

library(spqdep)
N <- 200
set.seed(1234)
cx <- runif(N)
cy <- runif(N)
listw <- spdep::knearneigh(cbind(cx,cy), k = 10)
p <- c(1/3,2/3)
rho <- 0.9
control <- list(seedinit = 1234)
fx <- dgp.spq(p = p, listw = listw, rho = rho,control = control)
scan <- scan.test(fx = fx, nsim = 199, case = "A", nv = 100, coor = cbind(cx,cy),
distr = "bernoulli", windows="elliptic")
print(scan)
#> 
#>  Scan test. Distribution: bernoulli
#> 
#> data:  fx
#> scan-loglik = 12.727, p-value < 2.2e-16
#> alternative hypothesis: High
#> sample estimates:
#>                                         
#> Total observations in the MLC =    21.00
#> Expected cases in the MLC =       103.85
#> Observed cases in the MLC =        17.00
summary(scan)
#> 
#> Summary of data:
#> Distribution....................: bernoulli
#> Type of cluster (alternative)...: High
#> Number of locations.............: 200
#> Cathegory case..................: A
#> Total number of observations....: 67
#> Names of cathegories............: A B
#> Total per category..............: 67 133
#> Percent per category............: 0.34 0.66
#> ---------------------------------
#> 
#> Scan statistic: Most Likely Cluster
#> Total observations in the MLC........: 21
#> Names of cathegories.................: A B
#> Percent per category total...........: 0.34 0.66
#> Percent per category inside cluster..: 0.81 0.19
#> Value of statisitic (loglik ratio)...: 12.7268
#> p-value..............................: 0
#> 
#> IDs of cluster detect:
#> Location IDs included...:  110 112 1 193 165 95 89 91 59 35 85 78 37 51 152 19 83 32 30 133 105
#> ---------------------------------
#> 
#> 
#> Secondary Cluster. Number 1 
#> Total observations in secondary cluster.:  5 
#> Names of cathegories.................: A B
#> Percent per category total...........: 0.34 0.66
#> Percent per category inside cluster..: 0 1
#> Value of statisitic (loglik ratio)...: 4.4561
#> p-value..............................: 0.75
#> Location IDs included................:  62 69 75 186 98
#> 
#> 
#> Secondary Cluster. Number 2 
#> Total observations in secondary cluster.:  4 
#> Names of cathegories.................: A B
#> Percent per category total...........: 0.34 0.66
#> Percent per category inside cluster..: 0 1
#> Value of statisitic (loglik ratio)...: 3.3265
#> p-value..............................: 0.975
#> Location IDs included................:  116 124 117 185
#> 
#> 
#> Secondary Cluster. Number 3 
#> Total observations in secondary cluster.:  6 
#> Names of cathegories.................: A B
#> Percent per category total...........: 0.34 0.66
#> Percent per category inside cluster..: 0.17 0.83
#> Value of statisitic (loglik ratio)...: 2.343
#> p-value..............................: 0.995
#> Location IDs included................:  38 164 43 8 88 79
#> 
#> 
#> Secondary Cluster. Number 4 
#> Total observations in secondary cluster.:  6 
#> Names of cathegories.................: A B
#> Percent per category total...........: 0.34 0.66
#> Percent per category inside cluster..: 0.67 0.33
#> Value of statisitic (loglik ratio)...: 2.343
#> p-value..............................: 0.995
#> Location IDs included................:  44 191 70 160 11 84
#> 
#> 
#> Secondary Cluster. Number 5 
#> Total observations in secondary cluster.:  6 
#> Names of cathegories.................: A B
#> Percent per category total...........: 0.34 0.66
#> Percent per category inside cluster..: 0.67 0.33
#> Value of statisitic (loglik ratio)...: 2.343
#> p-value..............................: 0.995
#> Location IDs included................:  129 177 162 56 31 77
plot(scan)

Copy Link

Version

Install

install.packages('spqdep')

Monthly Downloads

181

Version

0.1.3.3

License

MIT + file LICENSE

Maintainer

Fernando A Lopez

Last Published

October 21st, 2024

Functions in spqdep (0.1.3.3)

Q.map.test

Compute the QE and QI tests of Equivalence and Independence between maps
Boots.sf

Boots.sf.
methods_spqtest

Methods for class spqtest
nb2nb_order

A function to order the elements of the m_i-subrrounds
Q.test

A function to compute Q test for spatial qualitative data
print.summary.spjctest

Print method for objects of class summary.spjctest.
plot.sprunstest

Plot the empirical distribution of runs
local.sp.runs.test

A function to calculate the local spatial runs tests.
methods_qmap

Method for class qmap
m.surround

A function to generate m-surroundings
FastFood.sf

Selection of fast food restaurants in Toronto
methods_localsrq

Methods for class localsrq
methods_scantest

Methods for class scantest
methods_localjc

Methods for class localjc
methods_m_surr

Method for class m_surr
summary.spjctest

Summary of estimated objects of class spjctest.
summary.spqtest

Summary of estimated objects of class spqtest.
scan.test

Compute the scan test
sp.runs.test

Compute the global spatial runs test.
cr_symb

A function to create symbols
spqdep-package

Testing for Spatial Dependence of Qualitative Data in Cross Section.
print.summary.spqtest

Print method for objects of class summary.spqtest.
similarity.test

Compute the similarity test.
provinces_spain

Provinces in Spain.
Newark.sf

Extract of 1880 US Census for Newark, New Jersey.
dgp.spq

Generation of qualitative process with spatial structure
jc.test

A function to compute joint-count test for binomial and multinomial (asymptotic and permutation distributions).
local.jc.test

A function to calculate the local Join Count tests.