Questions tagged [spdep]

An R package to provide functions for spatial regression, dependence, and weighting analysis.

spdep
Filter by
Sorted by
Tagged with
1 vote
0 answers
15 views

Handling missing values in grid-based data for Geary's C

I would like to compute Geary's C or Moran's I indices of spatial autocorrelation for a set of grid-based datasets. I have a bunch of 12x3 grids such as this one: ## Define a 12x3 grid: loc <- ...
Philopolis's user avatar
0 votes
1 answer
48 views

spdep: How to extract variables of localG object

I used the localG_perm() function which unlike localmoran_perm() doesn't return a dataframe but instead a localG num object. I'm having trouble extracting the variables ("Gi", "E.Gi&...
Corbjn's user avatar
  • 286
0 votes
0 answers
27 views

Error with calculating localG (Getis-Ord* ststistic) for a set of spatial points

I want to calculate the Getis-Ord* statistic for each point in an R simple feature (SF) point object to detect "hotspots" among land cover classes. To do this, I am using the localG function ...
Gayle Tyree's user avatar
1 vote
1 answer
97 views

manually fixing colors in the map

The data is: d.fit.spatial.1914 <- structure(list(country = c("Albania", "Austria", "Belgium", "Netherlands", "Poland", &...
Rustam's user avatar
  • 133
0 votes
0 answers
54 views

How to calculate IDW (inverse distance weight) for multipolygon geometry in R (spdep lib)

I have a sfc dataframe and would like to change the weights for my distances from equal weights to IDW. I tried many conversions from multipolygon sfc to other types (like polygon, point, etc.), but ...
ElMago's user avatar
  • 11
0 votes
2 answers
123 views

Difficulty with poly2nb() and nb2mat() in spdep package

I would appreciate some advice on making a spatial weights matrix using the spdep() package. (1) If I have spatial data download from the rnaturalearth package, and a list of countries in another ...
Lindsay's user avatar
  • 153
1 vote
0 answers
216 views

no 'nobs' method available: Using the MuMIn package with simultaneous autoregression models

I'm hoping someone can help me figure out why the MuMIn package is not working with my simultaneous autoregression models. I have double checked the documentation for the package and it lists sarlm as ...
Kristin's user avatar
  • 11
0 votes
1 answer
62 views

How to create a graph file for INLA using region names

i.e. use the region.id of class nb from the spdep package rather than ignoring it as spdep::nb2INLA does? I've been trying to link a column in my data containing these regions as a factor, to an INLA ...
JCran's user avatar
  • 375
1 vote
1 answer
387 views

Robust Standard Errors in spatial error models

I am fitting a Spatial Error Model using the errorsarlm() function in the spdep library. The Breusch-Pagan test for spatial models, calculated using the bptest.sarlm() function, suggest the presence ...
Orlando Sabogal's user avatar
2 votes
1 answer
470 views

Converting a normal list into a nb/spdep object in R?

I need to create a neighbours list from a spatial polygon. At the moment i am using the function poly2nb, but unfortunately it is not very accurate, and some polygons with no common points are ...
mrc's user avatar
  • 21
0 votes
1 answer
83 views

global moran in spdep package in R

In function moran in spdep package, which argument is being related to the weight matrix (or distance matrix)? moran(x, listw, n, S0, zero.policy=NULL, NAOK=FALSE) I have a matrix W2 which is the ...
Rojer's user avatar
  • 335
2 votes
1 answer
530 views

Given a spatial (hexagonal) grid how can I obtain a sample of higher order neighbors?

I would like to "thin" a grid made with sf::st_make_grid and obtain a subset of higher order neighbors. First order neighbors share at least one side, 2nd order neighbors share a side with ...
MihaiV's user avatar
  • 147
0 votes
1 answer
97 views

Error message when using the function autocov_dist from spdep package

I'm using the function autocov_dist from spdep package to estimate the aucovariate. I'm using inverse distance as a weight. When I tested it on my data I got this error message: Error in autocov_dist(...
user1988's user avatar
0 votes
1 answer
648 views

Getting different test results between Moran.I and moran.test

I tried to run Moran's I test for the spatial autocorrelation test by using the function Moran.Ifrom the package ape and moran.test from the package spdep I got different results by applying the two ...
user1988's user avatar
0 votes
1 answer
225 views

Neighboring Zipcodes from State Polygons

First time posting on SO I have a shapefile that has the geometries for each Zipcode along with state name. I want to figure out which zipcodes lie on the state borders. The way I figured to achieve ...
Sunit Kolabkar's user avatar
0 votes
1 answer
199 views

parallelizing function poly2nb {spdep}

The documentation for spdep::poly2nb contains the following entry under Arguments: foundInBox: default NULL using R code, possibly parallelised if a snow cluster is available, otherwise a list of ...
Gabriel De Oliveira Caetano's user avatar
1 vote
1 answer
346 views

Include ID in an spatial weight matrix R

I have a data frame like this one: dataSp <- read.table( text = ' ID LATITUDE LONGITUDE A -85 134 B 34 2 C 42 3 D 45 ...
Lilia's user avatar
  • 121
1 vote
0 answers
46 views

Creating a giant matrix for use in CARBayes without running out of memory

I am trying to do an areal unit analysis using the package CARBayes. As part of the analysis, I am using the below code. my issue comes when I try to create the neighbour matrix with nb2mat. My sp ...
hclutter's user avatar
0 votes
2 answers
1k views

Generate Neighbour List object for spatial lines in R

My goal is to generate an object of neighbourhood relationships between spatial lines in a road network. If my data were spatial polygons I could use spdep::poly2nb to do this, but I'm having trouble ...
mark's user avatar
  • 547
0 votes
0 answers
341 views

all adjustment methods result in same adjusted P values in localmoran() from spdep

I am using localmoran from spdep, which adjusts p values for multiple comparisons based on p.adjustSP. I want to use the holm correction, but I'm not sure if something is wrong as I noticed that ...
pbandj's user avatar
  • 11
1 vote
0 answers
118 views

How to estimate SAR spatial model without row-normalizing the matrix?

I am trying to estimate a SAR spatial model without row-normalizing the matrix. For some reason, when I do not row-normalize, the command does not return the correct estimates. Am I missing something ...
Miranda's user avatar
  • 158
1 vote
1 answer
709 views

How to estimate spatial SAR model with islands?

I am trying to estimate a spatial SAR model using the lagsarlm command and I get the following error: Error in lagsarlm(f1, data = df, spatialList, tol.solve = 1e-30) : NAs in lagged ...
Miranda's user avatar
  • 158
0 votes
1 answer
163 views

Rasterizing Spdep's localG output

I'm reasonably new to R and I am trying to rasterize the output of spdep's localG function. This code: neigh2<-dnearneigh(profcurvPts, 0, 2) list<-nb2listw(neigh2) gistar<-localG(...
Jim Young's user avatar
1 vote
2 answers
139 views

Plotting graphs from class `nb` - How to change points color?

It is easier to explain what am I trying to do through the following reproducible example: library(sf) library(brazilmaps) library(spdep) # loading cities map cities_mg <- brazilmaps::get_brmap(...
lcgodoy's user avatar
  • 793
2 votes
1 answer
542 views

neighbour list with poly2nb() works on 2004 census shapefile but not on 2011

I'm trying to construct neighbours list from polygon list for Lower Layer Super Output Areas (LSOA) in London. I got my shapefiles from the London Datastore, by downloading here: https://data.london....
Rekarrr's user avatar
  • 366
0 votes
1 answer
445 views

How to solve "impacts()" neighbors length error after running spdep::lagsarlm (Spatial Autoregressive Regression model)?

I have 9,150 polygons in my dataset. I was trying to run a spatial autoregressive model (SAR) in spdep to test spatial dependence of my outcome variable. After running the model, I wanted to examine ...
Denys D.'s user avatar
7 votes
2 answers
618 views

GAM with mrf smooth - errors (mismatch between nb/polys area names and data area names

I am trying to fit Polish local government election results in 2015 following the superb blog by @GavinSimpson. https://www.fromthebottomoftheheap.net/2017/10/19/first-steps-with-mrf-smooths/ I ...
Jacek Kotowski's user avatar
1 vote
0 answers
38 views

Compute distance based Local Moran for 527k+ point dataset using spdep library

As the title says, I'm trying to compute Local Moran for a 527k point dataset using the spdep package, creating neighborhoods based on distance. The generalized process I'm doing is the following: ...
Arodas's user avatar
  • 11
1 vote
2 answers
725 views

Problems updating packages igraph and spdep

I´m trying to install the package NormqPCR and I have to update two packages, igraph and spdep, but until now I couldn´t and I can´t figure out what I must supouse to do. This is the code. if (!...
Gerardo Irigoyen's user avatar
0 votes
1 answer
177 views

GAM with MRF smoother: create neighbourhood structure with duplicate coordinates

I want to use the mgcv package in R to run the model df <- as.data.frame(spdf) mod <- gam(y ~ s(geoid, bs = 'mrf', xt = list(nb = nb), k = 20) + s(month, bs = 'cc', k = 12),...
user3036416's user avatar
  • 1,235
0 votes
1 answer
205 views

execution time spatial models in r

I have a problem regarding to the execution time of a SAR model with the 'spdep' package. I pass two different dataset of the same dimension to the same function, it takes very different times (a few ...
Chiara's user avatar
  • 1
1 vote
0 answers
219 views

How to optimize finding trace of a square matrix multiplication?

I'm trying to optimize spdep function of R for my use case since it is very slow for large databases. I was doing mostly fine but I stuck at one point, where I am trying to find trace of my weights ...
orcmor's user avatar
  • 13
6 votes
0 answers
769 views

Spatial Regressions with Panel Data in R

I have a panel dataset with several hundred regions, ~10 years and spatial data for the regions. I created a weight matrix with the spdeppackage (via the standard way, and then, nb2listw). I have, ...
Jonathan Old's user avatar
2 votes
1 answer
399 views

Standard errors of impacts in a spatial regression lagsarlm

I am using a spatial lag and durbin regression models and I would like to estimate the standard errors of the impacts. Any ideas on how to do this? Reproducible example below using a durbin model # ...
rafa.pereira's user avatar
  • 13.5k
0 votes
1 answer
624 views

How to calculate local autocorrelation via Geary's C in R?

Calculating local autocorrelation via Moran's I is easy with the localmoran() function from the package spdep. But is it possible to calculate Geary's coefficient for local autocorrelation in R? I ...
Tzvetan Moev's user avatar
1 vote
1 answer
282 views

R error with spatial point data frame when using lapply

I have a list of lists called flat_head. dput(flat_head) structure(list(`0.25_0.05` = list(c(66, 102, 4.84), c(56, 75, 3.63), c(15, 134, 0)), `0.25_0.1` = list(c(147, 27, 0), c(98, 18, 4.84), c(...
user2359494's user avatar
2 votes
2 answers
3k views

SLX Model - Spatial Econometrics with panel in R data using splm package and slag function

I need to estimate spatial econometric models with spatial lags of X (SLX) either alone, combined with spatial autoregressive models (SAR) or with spatial error model (SEM). When they are combined, ...
dfamaral's user avatar
  • 115
3 votes
1 answer
787 views

texreg table for impacts of spatial lag model

I am using spdep to run a spatial regression using a Durbin lag model. This type of model returns direct, indirect and total effects for each regression coefficient and their level of significance. Is ...
rafa.pereira's user avatar
  • 13.5k
4 votes
3 answers
4k views

Map of bivariate spatial correlation in R (bivariate LISA)

I would like to create a map showing the bi-variate spatial correlation between two variables. This could be done either by doing a LISA map of bivariate Moran's I spatial correlation or using the L ...
rafa.pereira's user avatar
  • 13.5k
1 vote
0 answers
763 views

Spatial Autocorrelation between time series in R

So I'm using the spdep package in R to do this. I need to use the localmoran function in it to get clusters of hot/cold spots in the study area. After going through the reference guide, I got it to ...
ace_01S's user avatar
  • 407
2 votes
1 answer
889 views

How to create correct spatial lag variables for a raster in R?

lag.listw creates incorrect spatial lag values when I use the function spdep::cell2nb. I have a raster file and want to create a new raster where each cell has the average value of its neighboring ...
eliascis's user avatar
  • 317
0 votes
1 answer
394 views

Extract spatial ids from weights list object, spdep R

I have used mat2listw{spdep} to create a weights list object that I will later use in a spatial regression. I would like to retrieve from this weights list object the ids of the polygons used to ...
rafa.pereira's user avatar
  • 13.5k
0 votes
1 answer
475 views

How to input dissimilarity matrix in spatial analysis in spdep R

Aim: I want to create a dissimilarity matrix between pairs of coordinates. I want to use this matrix as an input to calculate local spatial clusters using Moran's I (LISA) and latter in geographically ...
rafa.pereira's user avatar
  • 13.5k
1 vote
0 answers
115 views

Spdep: Test for heteroscedasticity in GMerrosar residuals

Using spdep in R, and after conducting a Jarque-Bera test confirming non-normality of the residuals resulting from the maximum likelihood estimation of my Spatial Error Model, I used the generalized ...
Houssem's user avatar
  • 143
2 votes
1 answer
774 views

Does mat2listw function in R return a row-standardized spatial weight matrix?

In the discussion in the accepted answer in this question, user3050574 said that: "... it is my understanding that mat2listw creates a row standardized weight matrix from a matrix that is currently ...
Teng Huang's user avatar
9 votes
3 answers
7k views

Create a map of spatial clusters LISA in R

I would like to create a map showing local spatial cluster of a phenomenon, preferably using Local Moran (LISA). In the reproducible example below, I calculate the local moran's index using spdep but ...
rafa.pereira's user avatar
  • 13.5k
1 vote
0 answers
219 views

Modify SPDEP package - insert new function

I am trying to modify the stsls function of the R package spdep. The function compute a spatial autoregressive function using a two stage least square. For both stages, the function uses the same ...
vscia's user avatar
  • 11
5 votes
0 answers
1k views

K-means clustering of spatially constrained data - skater in spdep package

I want to cluster the codebook from a self-organizing map using k-means clustering. However, given the 'spatial' nature of the data, I want to constrain the clustering so that only contiguous nodes ...
msoftrain's user avatar
  • 1,027
0 votes
1 answer
1k views

Spatial correlogram

I am trying to run a spatial auto correlogram for a project looking at deforestation in the Atlantic forest, Brazil. I am however confused as to why I am hitting this problem. Problem When I run ...
Guy Benett's user avatar
1 vote
0 answers
262 views

Missing links in a spdep (R) Queen Contiguity Neighborhood

I'm puzzled by the following result in plotting the Queen Contiguity Neighbors using the spdep library in R. library(spdep) Using a World shape file wrld_simp to get the centroid points (spatial ...
Luca De Benedictis's user avatar