[R-sig-Geo] Error when performing a spatial eigenvector selection in R
Roger Bivand
Roger@Biv@nd @ending from nhh@no
Wed Oct 10 21:49:49 CEST 2018
On Wed, 10 Oct 2018, DIEGO CEPEDA GOMEZ wrote:
> Dear all,
>
> I am currently trying to do a Gaussian linear regression in R with data
> that may be spatially autocorrelated. My dataset contains geographic
> coordinates (value of longitude, value of latitude), species, independent
> variables (BS and LTS) and some explanatory variables; it looks like:
>
> head(dataset)
>
> coordinates SPECIES BS LTS DEPTH OCEAN(155, 47)
> Cristaphyes abyssorum 8.66 28.3 5373 WPac(150, 41) Cristaphyes
> abyssorum 8.66 28.3 5250 WPac (-72, -41) Cristaphyes anomalus
> 8.69 NA 35 EPac(-74, -44) Cristaphyes anomalus 8.69 NA
> 35 EPac(-57, -46) Cristaphyes anomalus 8.69 NA NA WAtl(29,
> 80) Cristaphyes arctous 8.32 27.0 393 EAtl
>
> tail(dataset)
>
> coordinates SPECIES BS LTS DEPTH OCEAN(-80, 27)
> Zelinkaderes brightae NA 20.1 13.04 WAtl(-80, 27)
> Zelinkaderes floridensis 7.10 12.4 140.00 WAtl(35, 25)
> Zelinkaderes klepali NA 25.0 1.00 WInd(9, 57)
> Zelinkaderes submersus 7.99 21.4 30.00 EAtl(130, 36)
> Zelinkaderes yong NA 12.7 4.50 WAtl
>
> The dataset also include the values of latitude and longitude in separated
> columns.
>
> I extracted positive eigenvector-based spatial filters from a truncated
> matrix of geographic distances among sampling sites. I would like to treat
> spatial filters as candidate explanatory variables in my linear regression
> model. I did this as following:
>
> First of all, I created a neighbor list object (nb). In my case of
> irregular samplings, I used the function knearneight of the R package spdep:
>
> knea8 <-knearneight(coordinates(dataset), longlat=TRUE, k=8)
>
> neib8 <-knn2nb(knea8)
>
> Then, I created a spatial weighting matrix with the function nb2listw of
> the R package spdep:
>
> nb2listw(neib8)
>
> distgab8 <- nbdists(neib8, coordinates(dataset))
>
> str(distgab8)
>
> fdist<-lapply(distgab8, function(x) 1-x/max(dist(coordinates(dataset))))
>
> listwgab8 <- nb2listw(neib8, glist = fdist8, style = "B")
>
> Then, I built spatial predictors to incorporate them in the Gaussian linear
> regression. I did this with the mem function of the R package adespatial,
> as following:
If you are choosing adespatial::mem(), it will probably work differently
from spdep::SpatialFilering(), based on
Tiefelsdorf M, Griffith DA. (2007) Semiparametric Filtering of
Spatial Autocorrelation: The Eigenvector Approach. Environment and
Planning A, 39 (5) 1193 - 1221.
In that approach, the eigenvectors are chosen to reduce the residual
spatial autocorrelation.
>
> mem.gab8 <- mem(listwgab8)
>
> Additionally, Moran's I were computed and tested for each eigenvector with
> the moran.randtest function, as following:
>
> moranI8 <-moran.randtest(mem.gab8, listwgab8, 99)
>
> I obtained some eigenvectors with significant positive spatial
> autocorrelation. Now, I would like to include them in the Gaussian linear
> regression. I tried to do this with the function ME of spdep, as following:
>
Use spdep::SpatialFilering() rather than spdep::ME() for the Gaussian
case. Probably your listwgab8 refers to a different number of observations
than dataset (any missing values in your variables?).
Roger
> GLM1 <- ME(BS~LATITUDE, data=dataset, listw=listwgab8,
> family=gaussian, nsim=99, alpha=0.05)
>
> Unfortunately, I receive this error:
>
> Error in sW %*% var : Cholmod error 'X and/or Y have wrong dimensions' at
> file ../MatrixOps/cholmod_sdmult.c, line 90
>
>
> Would anybody know how I could solve this error? Or, if is there another
> way to perform a spatial eigenvector selection in a Gaussian linear
> regression?
>
> Thank you in advance
>
> Best wishes,
>
> Diego
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: Roger.Bivand using nhh.no
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
More information about the R-sig-Geo
mailing list