Subscribe to R-sig-geo feed
This is an archive for R-sig-geo, not a forum. It is not possible to post through Nabble - you may not start a new thread nor follow up an existing thread. If you wish to post, but are not subscribed to the list through the list homepage, subscribe first (through the list homepage, not via Nabble) and post from your subscribed email address. Until 2015-06-20, subscribers could post through Nabble, but policy has been changed as too many non-subscribers misunderstood the interface.
Updated: 1 hour 31 min ago

Slow writing of point features to SpatialLite-DB or Geopackage

Thu, 08/24/2017 - 10:00
Dear list

I am searching alternatives to ESRI shapefiles for the storage of GPS data, i.e. tagged point features, and came across SpatialLite or Geopackage. Unfortunately writing to both formats is very slow compared to shapefiles making practical use impossible.

library(sf)
library(rgdal)
library(RSQLite)

n<- 1000
d <-data.frame(a=1:n, X=rnorm(n,1,1), Y=rnorm(n,1,1))
mp1 <- st_as_sf(d, coords=c("X","Y"))

t1 <- system.time(st_write(mp1, dsn = 'C:/Temp/data1.shp', driver = 'ESRI Shapefile'))
t2 <- system.time(st_write(mp1, dsn = 'C:/Temp/test.sqlite', layer = 'data1', driver = 'SQLite'))
t3 <- system.time(st_write(mp1, "C:/Temp/data1.gpkg"))

rbind(t1,t2,t3)[,1:3]

   user.self sys.self elapsed
t1      0.03     0.03    0.09
t2      0.53     5.04   29.33
t3      0.48     4.29   32.19

As n increases, processing time explodes for SpatialLite and Geopackage, and I usually have a couple of 10000 points to store. Any experiences of others would be highly appreciated.
Many thanks
Manuel


------
R version 3.4.1 (2017-06-30)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=German_Switzerland.1252  LC_CTYPE=German_Switzerland.1252  
[3] LC_MONETARY=German_Switzerland.1252 LC_NUMERIC=C                      
[5] LC_TIME=German_Switzerland.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base    

other attached packages:
[1] sf_0.5-3    RSQLite_2.0 rgdal_1.2-8 sp_1.2-5  

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.12    lattice_0.20-35 digest_0.6.12   grid_3.4.1      DBI_0.7        
 [6] magrittr_1.5    units_0.4-5     rlang_0.1.2     blob_1.1.0      tools_3.4.1    
[11] udunits2_0.13   bit64_0.9-7     bit_1.1-12      compiler_3.4.1  memoise_1.1.0  
[16] tibble_1.3.4  

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: spGLM

Thu, 08/24/2017 - 08:54
Hi Bedilu,

Thanks for the post. Given your description, you should not be getting
that error. Would you mind emailing me directly an example with data
that reproduces the error?

Thanks-
Andy

On 08/24/2017 12:33 AM, Bedilu Ejigu wrote:
>   When I run a spatial model in R using spGLM function from spBayes package,
> the following error message popup.
>
> Error in spGLM(ane ~ 1, family = "binomial", data = FemaleAug, coords
> = coord,  :
>    error: either the coords have more than two columns or then number
> of rows is different than
>            data used in the model formula
>
>
> But, the number of  columns in for coords are two, and the number of
> rows also similar  with the dataset used in the model
>
>> dim(coord)[1] 15233     2> dim(FemaleAug)[1] 15233    11
>
> *_______________________________________________*
>
>
>
> <https://urldefense.proofpoint.com/v2/url?u=https-3A__www.avast.com_sig-2Demail-3Futm-5Fmedium-3Demail-26utm-5Fsource-3Dlink-26utm-5Fcampaign-3Dsig-2Demail-26utm-5Fcontent-3Dwebmail-26utm-5Fterm-3Dicon&d=DwICAg&c=nE__W8dFE-shTxStwXtp0A&r=vOgWsEpXC-0Xwo-gVRww3A&m=PJ3MQSOol3LkkKQUUYhaakIn9sHbYI1BvcPIdqRqgdI&s=TkyWuUAovom0L7MuZNEJ-3vBzLo0zHdYA04P_XwGR5I&e= >
> Virus-free.
> www.avast.com
> <https://urldefense.proofpoint.com/v2/url?u=https-3A__www.avast.com_sig-2Demail-3Futm-5Fmedium-3Demail-26utm-5Fsource-3Dlink-26utm-5Fcampaign-3Dsig-2Demail-26utm-5Fcontent-3Dwebmail-26utm-5Fterm-3Dlink&d=DwICAg&c=nE__W8dFE-shTxStwXtp0A&r=vOgWsEpXC-0Xwo-gVRww3A&m=PJ3MQSOol3LkkKQUUYhaakIn9sHbYI1BvcPIdqRqgdI&s=BfdbRCOLnk-n-yL_fJCSiI0Ek0jyFindH4HfroFg_BE&e= >
> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dsig-2Dgeo&d=DwICAg&c=nE__W8dFE-shTxStwXtp0A&r=vOgWsEpXC-0Xwo-gVRww3A&m=PJ3MQSOol3LkkKQUUYhaakIn9sHbYI1BvcPIdqRqgdI&s=99t4yTictDFtDmoddyYrTfGsS4HVtiR38GYMKohfFxM&e=
>
--
Andrew Finley, PhD
Natural Resources Building
Michigan State University
East Lansing, MI 48824-1222
Phone: 517-898-5970
Skype: finle014
Fax: 517-432-1143
Web: http://blue.for.msu.edu

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

spGLM

Wed, 08/23/2017 - 23:33
 When I run a spatial model in R using spGLM function from spBayes package,
the following error message popup.

Error in spGLM(ane ~ 1, family = "binomial", data = FemaleAug, coords
= coord,  :
  error: either the coords have more than two columns or then number
of rows is different than
          data used in the model formula


But, the number of  columns in for coords are two, and the number of
rows also similar  with the dataset used in the model

> dim(coord)[1] 15233     2> dim(FemaleAug)[1] 15233    11

*_______________________________________________*



<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
Virus-free.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: useR! spatial presentations

Tue, 08/22/2017 - 08:18
Mike Treglia's comment, "Spatial stuff in #rstats is moving so fast! tough to keep up... but a good problem I guess" is spot on. I feel like I need to wear a bicycle helmet, elbow and knee pads, a seat belt and maybe a few pillows strapped on every time I sit down with the stuff.


> On Aug 22, 2017, at 9:05 AM, Roger Bivand <[hidden email]> wrote:
>
> Edzer spotted:
>
> https://twitter.com/Geospex/status/899670406944231424
>
> and I copied the link here - thanks to Geospex/anonymous ...
>
> On Tue, 22 Aug 2017, Ben Tupper wrote:
>
>> A gold mine!  Thanks for sharing these.
>>
>>
>>> On Aug 22, 2017, at 5:40 AM, Roger Bivand <[hidden email]> wrote:
>>>
>>> A useful listing of video links fro useR! in Brussels on spatial topics:
>>>
>>> https://gist.github.com/anonymous/3d5b56cb16526db96dcaa0a579980187
>>>
>>> --
>>> Roger Bivand
>>> Department of Economics, Norwegian School of Economics,
>>> Helleveien 30, N-5045 Bergen, Norway.
>>> voice: +47 55 95 93 55; e-mail: [hidden email]
>>> Editor-in-Chief of The R Journal, https://journal.r-project.org/index.html
>>> http://orcid.org/0000-0003-2392-6140
>>> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> [hidden email]
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>> Ben Tupper
>> Bigelow Laboratory for Ocean Sciences
>> 60 Bigelow Drive, P.O. Box 380
>> East Boothbay, Maine 04544
>> http://www.bigelow.org
>>
>> Ecocast Reports: http://seascapemodeling.org/ecocast.html
>> Tick Reports: https://report.bigelow.org/tick/
>> Jellyfish Reports: https://jellyfish.bigelow.org/jellyfish/
>>
>>
>>
>>
>
> --
> Roger Bivand
> Department of Economics, Norwegian School of Economics,
> Helleveien 30, N-5045 Bergen, Norway.
> voice: +47 55 95 93 55; e-mail: [hidden email]
> Editor-in-Chief of The R Journal, https://journal.r-project.org/index.html
> http://orcid.org/0000-0003-2392-6140
> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecocast Reports: http://seascapemodeling.org/ecocast.html
Tick Reports: https://report.bigelow.org/tick/
Jellyfish Reports: https://jellyfish.bigelow.org/jellyfish/

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: useR! spatial presentations

Tue, 08/22/2017 - 08:05
Edzer spotted:

https://twitter.com/Geospex/status/899670406944231424

and I copied the link here - thanks to Geospex/anonymous ...

On Tue, 22 Aug 2017, Ben Tupper wrote:

> A gold mine!  Thanks for sharing these.
>
>
>> On Aug 22, 2017, at 5:40 AM, Roger Bivand <[hidden email]> wrote:
>>
>> A useful listing of video links fro useR! in Brussels on spatial topics:
>>
>> https://gist.github.com/anonymous/3d5b56cb16526db96dcaa0a579980187
>>
>> --
>> Roger Bivand
>> Department of Economics, Norwegian School of Economics,
>> Helleveien 30, N-5045 Bergen, Norway.
>> voice: +47 55 95 93 55; e-mail: [hidden email]
>> Editor-in-Chief of The R Journal, https://journal.r-project.org/index.html
>> http://orcid.org/0000-0003-2392-6140
>> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> [hidden email]
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
> Ben Tupper
> Bigelow Laboratory for Ocean Sciences
> 60 Bigelow Drive, P.O. Box 380
> East Boothbay, Maine 04544
> http://www.bigelow.org
>
> Ecocast Reports: http://seascapemodeling.org/ecocast.html
> Tick Reports: https://report.bigelow.org/tick/
> Jellyfish Reports: https://jellyfish.bigelow.org/jellyfish/
>
>
>
>
--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: [hidden email]
Editor-in-Chief of The R Journal, https://journal.r-project.org/index.html
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway

Re: useR! spatial presentations

Tue, 08/22/2017 - 07:39
A gold mine!  Thanks for sharing these.


> On Aug 22, 2017, at 5:40 AM, Roger Bivand <[hidden email]> wrote:
>
> A useful listing of video links fro useR! in Brussels on spatial topics:
>
> https://gist.github.com/anonymous/3d5b56cb16526db96dcaa0a579980187
>
> --
> Roger Bivand
> Department of Economics, Norwegian School of Economics,
> Helleveien 30, N-5045 Bergen, Norway.
> voice: +47 55 95 93 55; e-mail: [hidden email]
> Editor-in-Chief of The R Journal, https://journal.r-project.org/index.html
> http://orcid.org/0000-0003-2392-6140
> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecocast Reports: http://seascapemodeling.org/ecocast.html
Tick Reports: https://report.bigelow.org/tick/
Jellyfish Reports: https://jellyfish.bigelow.org/jellyfish/

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

useR! spatial presentations

Tue, 08/22/2017 - 04:40
A useful listing of video links fro useR! in Brussels on spatial topics:

https://gist.github.com/anonymous/3d5b56cb16526db96dcaa0a579980187

--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: [hidden email]
Editor-in-Chief of The R Journal, https://journal.r-project.org/index.html
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway

Re: How to extract values from adjacent raster cells that are not touched by SpatialLines?

Sat, 08/19/2017 - 13:52
Hi Andre,

I'm not completely sure if this is what you are looking for, but here is a
worked example on how to get cell indices (thus, data) from neighbouring
cells. Essentially, I'm using the adjancency() function from raster,
reducing to unrepeated cells, and excluding the ones that fall under a line
object.

library(raster)
r <- raster(ncol=10,nrow=10) # generate a raster object
r[] <- 0 # populate values with 0's
p <- rasterToPolygons(r) # get a polygon for each cell (for visual purposes)

# make a line object (SpatialLines)
x <- c(-124.66110, -93.04031, -52.37858, 24.44486, 15.98469, 52.12075,
88.49592)
y <- c(-46.021148, -27.197684, -6.804443, 10.113111, 28.375197, 8.851744,
-12.463264)
xy <- data.frame(cbind(x,y))
spl <- SpatialLines(list(Lines(list(Line(xy)), ID=1)))

# get adjacent cells
lcells <- cellFromLine(r, spl)[[1]] # cells from line
r[lcells] <- 1 # mark line cells with 1
ad <- adjacent(r, lcells, 4) # this gives you a matrix with adjacent cells,
                                          # you can specify 8 or 16
neighbouring cells,
                                          # here I'm using 4
# sorting and removing duplicates
ad <- sort(as.vector(ad))
ad <- ad[!duplicated(ad)]
ad2 <- ad[ ! ad %in% lcells ]
r[ad2] <- 2

# to visualize the example:
plot(r)
plot(p, add=T)
plot(spl, add=T, col="red")

# Obviously, you con extract the values of adjacent cells simply with:
r[ad2]
[1] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2


Hope this helps,
Santiago

--
==========================
Santiago Sanchez-Ramirez, PhD
Postdoctoral Associate
Ecology and Evolutionary Biology
University of Toronto
==========================

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

How to extract values from adjacent raster cells that are not touched by SpatialLines?

Fri, 08/18/2017 - 15:34
[hidden email]

Hi all,

I've been trying to extract values from a single attribute raster (area, in
m2) that overlaps with different lines (that is, a .shp SpatialLines).

I am using the extract() function but it only extracts values from
cells that are touched (that is, crossed) by the lines.  The problem is
that my raster has adjacent cells both right and left of the cell that
is actually touched by the lines.  Thus, when I add up the extracted values
a significant amount of area (m2) is lost due to cells that were not
touched by the line and therefore values were not extracted.

I tried to work it around by:

Step 1 - first aggregating my raster to a lower resolution (i.e. increasing
the fact argument) and then
Step 2 - rasterizing the lines using this aggregated raster (created in
step 1) as a mold to make sure the rasterized lines would get thick enough
to cover the horizontal spread of cells in my original resolution raster.
Step 3 - Then I resample the rasterized lines (created in step 2) back to
the original resolution I started with.
Step 4 - Finally, extracted the values from the resampled rasterized lines
(created in step 3).

However, it didn't quite work as now the total area (m2) varies according
to the fact="" value I use when first aggregating the raster (in step 1).

I also tried using crop() and mask() but had no success as well.

I really appreciate if anyone has already dealt with a similar problem and
can help me out here.  Here are the codes I've been running to try to get
it to work:


# input raster file

g.025 <- raster("ras.asc")

g.1 <- aggregate(g.025, fact=2, fun=sum)



# input SpatialLines

Spline1 <- readOGR("/Users/xxxxx.shp")

Spline2 <- readOGR("/Users/xxxxx.shp")

Spline3 <- readOGR("/Users/xxxxx.shp")



# rasterizing using low resolution raster (aggregated)

c1 <- rasterize(Spline1, g.1, field=Spline1$type, fun=sum)

c2 <- rasterize(Spline2, g.1, field=Spline2$type, fun=sum)

c3 <- rasterize(Spline3, g.1, field=Spline3$type, fun=sum)



# resampling back to higher resolution

c1 <- resample(c1, g.025)

c2 <- resample(c2, g.025)

c3 <- resample(c3, g.025)



# preparing to extract area (m2) values from raster “g.025”

c1tab <- as.data.frame(c1, xy=T)

c2tab <- as.data.frame(c2, xy=T)

c3tab <- as.data.frame(c3, xy=T)

c1tab <- c1tab[which(is.na(c1tab$layer)!=T),]

c2tab <- c2tab[which(is.na(c2tab$layer)!=T),]

c3tab <- c3tab[which(is.na(c3tab$layer)!=T),]



# extracting area (m2) values from raster “g.025”

c1tab[,4] <- extract(g.025, c1tab[,1:2])

c2tab[,4] <- extract(g.025, c2tab[,1:2])

c3tab[,4] <- extract(g.025, c3tab[,1:2])

names(c1tab)[4] <- "area_m2"

names(c2tab)[4] <- "area_m2"

names(c3tab)[4] <- "area_m2"



# sum total area (m2)

c1_area <- sum(c1tab$area_m2)

c2_area <- sum(c2tab$area_m2)

c3_area <- sum(c3tab$area_m2)

tot_area <- sum(c1_area, c2_area, c3_area)


Thanks!

Andre Rovai
Department of Oceanography and Coastal Sciences
Louisiana State University

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: How can I read a path containing multibyte characters using the read_sf () function?

Thu, 08/17/2017 - 15:10
Hi Ogawa,

I can reproduce the error on Windows, though the error message isn't
very useful. The useful part is the part that comes after that, the
part you didn't include in your question:

In addition: Warning message:
In normalizePath(path.expand(path), winslash, mustWork) :
  path[1]="<U+30C7><U+30FC><U+30BF>/test.shp": The filename, directory
name, or volume label syntax is incorrect

Taking the extrodanary step of googling for the problem I find a bug
report as the first result in
https://www.google.com/search?q=R+normalizePath(path.expand(path)%2C+winslash%2C+mustWork)+utf-8+windows

The upshot from that bug report is that you can either
a) stop using windows (it works on Mac and Linux),
b) use the development version of R where this issue is now fixed on
Windows, or
c) wait for R 3.5 to be released.

With tongue only partially in cheek I suggest that a) is your best option.

Best,
Ista

On Thu, Aug 17, 2017 at 7:32 AM, 小川福嗣 <[hidden email]> wrote:
> Dears,
>
> How can I read data containing multibyte characters in windows
> using the read_sf () function?
>
> library(sf)
> nc <- st_read(system.file("shape/nc.shp", package="sf"))
> write_sf(nc, dsn=enc2utf8("データ"), layer="test", driver="ESRI Shapefile")
> dsn = enc2utf8("データ/test.shp")
> read_sf(dsn)
>
> ERROR:
> Cannot open data source C:\Users*****\nc\データ
> Error in CPL_read_ogr(dsn, layer, as.character(options), quiet, type, :
> Open failed.
>
> best,
> Ogawa
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

How can I read a path containing multibyte characters using the read_sf () function?

Thu, 08/17/2017 - 06:32
Dears,

How can I read data containing multibyte characters in windows
using the read_sf () function?

library(sf)
nc <- st_read(system.file("shape/nc.shp", package="sf"))
write_sf(nc, dsn=enc2utf8("データ"), layer="test", driver="ESRI Shapefile")
dsn = enc2utf8("データ/test.shp")
read_sf(dsn)

ERROR:
Cannot open data source C:\Users*****\nc\データ
Error in CPL_read_ogr(dsn, layer, as.character(options), quiet, type, :
Open failed.

best,
Ogawa

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Correlation between a nominal and a continious rasters

Tue, 08/15/2017 - 08:07


Hi all

I need to find how much two *raster* variables are correlated. One of these
variables is categorical (*nominal* such as land-cover) and the other one
is *continuous*.

I also need to do the same analysis for a *Binary raster layer* (0,1)
and a *continuous
raster layer*.  Could you please give me some bits of advice about the best
methods in this regard in R?

Excuse me if you find my question so elementary because I’m new in R.



Best regards

Iman

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

layer to change nodata values

Mon, 08/14/2017 - 13:07
Hi all,
> I downloaded global water surface layer from Pekel et al., 2016. The data (band values) has 0 to 255. 0 = 0 water, 1 = 1%, 2= 2%….100=100% water and after then 255 (which is no data according to paper). I want to keep this values from 0 to 100 only in the raster and want to change values 255 into nodata. How can I make r code? I have following code but I am not sure it is good not?

a <- raster(“waterlayer.tif)
max <- 100
a[a >= max] <- NA

Hari Sharma
Taiwan




        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: How to test spatial dependence in errorsarlm

Mon, 08/14/2017 - 02:43
On Mon, 14 Aug 2017, Javier García wrote:

> So testing for spatial dependence on the residuals by means of the
> lm.LMtests (option LMerr, the only that works with residuals) is wrong,
> isn't it? I had read in some forum that this was a posible way to test it...

There was some speculation that these tests might be used on an lm fit of
the (I - \lambda W) y ~ (I - \lambda W) X model. These speculations have
never been checked rigorously, so nobody knows whether they are of any
value, probably not, and certainly we know nothing of their inferential
basis.

>
> In my case the Moran test and the LM tests (both LMerr and LMlag, and
> also their robust versions) are strongly rejected (p-values between
> 4.307e-06 and 2.2e-16). As the rejection is stronger for the spatial
> error model, my suspicion was that this could be the best model to
> capture the spatial dependence (in fact the log-likelihood is bigger for
> the spatial error model, and the AIC lower). However, how can I know
> whether the spatial error model is a good option if I cannot test the
> absence of spatial dependence in the residuals?

You by definition fix X and W as known, exogeneous, quantities. If X (and
functional forms) and/or W do not meet these requirements, there is little
good guidance. It depends on what you want: predict house prices where
they are not observed; estimate \beta values; estimate the impact of a
unit change in an X variable on house prices (y); whatever. A best-fit
model suggests that you want to predict, but isn't necessary for impacts
or betas if you trust X (and its functional forms) and W.

> And how can I know, as you suspect, whether I have a
> misspecification problem?

See a good deal of work by Daniel McMillen on these issues.

> Moreover, I also estimated the Durbin model, and in this case the LM
> test on the residuals suggests no spatial dependence (for the spatial
> lag model I get the opposite conclusion), but due to the nature of my
> regression I don't think that this model is suitable (the regressors are
> characteristics of houses such as size, number of rooms, etc).

This suggests that SLX or SDEM (see LeSage 2014 and SLX articles for a
discussion) may address many of the issues of spatial autocorrelation by
including (selected) WX. The Durbin versions of spdep functions do not
(yet) let you choose which WX to include, always including all X - this is
on my medium-term to-do list.

Roger

>
> Thanks a lot for your time.
> Best
> Javi
>
> -----Mensaje original-----
> De: Roger Bivand [mailto:[hidden email]]
> Enviado el: domingo, 13 de agosto de 2017 12:45
> Para: Javier García
> CC: [hidden email]
> Asunto: Re: [R-sig-Geo] How to test spatial dependence in errorsarlm
>
> On Sun, 13 Aug 2017, Javier García wrote:
>
>> Hello everybody:
>>
>>
>>
>> I have estimated a spatial error model and now I would like to test
>> whether that model has really ?deleted? the spatial dependence. For
>> the spatial lag model and for the Durbin model the function lagsarlm
>> gives the LM test for residual autocorrelation test value, but the
> function errorsarlm does not.
>> Does anyone know how to do it in R?
>>
>
> As you should be aware from the literature, the only LM test that has been
> written (the maths) is a test for residual error autocorrelation for spatial
> lag models. Doing it in R will not help until someone (you?) does the maths.
> Computing a value is easy, but knowing what to infer from it is hard. By
> definition, if your model is well-specified, the residual autocorrelation is
> fully captured by its coefficient. I suspect that your model suffers from
> mis-specification problems.
>
> Roger
>
>>
>>
>> Thanks a lot in advance.
>>
>>
>>
>> Javi
>>
>>
>>
>>
>>
>>
>> JAVIER GARCÍA
>>
>>
>>
>> Departamento de Economía Aplicada III (Econometría y Estadística)
>>
>> Facultad de Economía y Empresa (Sección Sarriko)
>> Avda. Lehendakari Aguirre 83
>>
>> 48015 BILBAO
>> T.: +34 601 7126 F.: +34 601 3754
>> <http://www.ehu.es/> www.ehu.es
>>
>>
> http://www.unibertsitate-hedakuntza.ehu.es/p268-content/es/contenidos/inform
>>
> acion/manual_id_corp/es_manual/images/firma_email_upv_euskampus_bilingue.gif
>>
>>
>>
>>
>>
>>
>
> --
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: [hidden email]
Editor-in-Chief of The R Journal, https://journal.r-project.org/index.html
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway

Re: How to test spatial dependence in errorsarlm

Sun, 08/13/2017 - 21:18
So testing for spatial dependence on the residuals by means of the
lm.LMtests (option LMerr, the only that works with residuals) is wrong,
isn't it? I had read in some forum that this was a posible way to test it...

In my case the Moran test and the LM tests (both LMerr and LMlag, and also
their robust versions) are strongly rejected (p-values between 4.307e-06
and 2.2e-16). As the rejection is stronger for the spatial error model, my
suspicion was that this could be the best model to capture the spatial
dependence (in fact the log-likelihood is bigger for the spatial error
model, and the AIC lower). However, how can I know whether the spatial error
model is a good option if I cannot test the absence of spatial dependence in
the residuals? And how can I know, as you suspect, whether I have a
misspecification problem? Moreover, I also estimated the Durbin model, and
in this case the LM test on the residuals suggests no spatial dependence
(for the spatial lag model I get the opposite conclusion), but due to the
nature of my regression I don't think that this model is suitable (the
regressors are characteristics of houses such as size, number of rooms,
etc).

Thanks a lot for your time.
Best
Javi    

-----Mensaje original-----
De: Roger Bivand [mailto:[hidden email]]
Enviado el: domingo, 13 de agosto de 2017 12:45
Para: Javier García
CC: [hidden email]
Asunto: Re: [R-sig-Geo] How to test spatial dependence in errorsarlm

On Sun, 13 Aug 2017, Javier García wrote:

> Hello everybody:
>
>
>
> I have estimated a spatial error model and now I would like to test
> whether that model has really ?deleted? the spatial dependence. For
> the spatial lag model and for the Durbin model the function lagsarlm
> gives the LM test for residual autocorrelation test value, but the
function errorsarlm does not.
> Does anyone know how to do it in R?
>

As you should be aware from the literature, the only LM test that has been
written (the maths) is a test for residual error autocorrelation for spatial
lag models. Doing it in R will not help until someone (you?) does the maths.
Computing a value is easy, but knowing what to infer from it is hard. By
definition, if your model is well-specified, the residual autocorrelation is
fully captured by its coefficient. I suspect that your model suffers from
mis-specification problems.

Roger

>
>
> Thanks a lot in advance.
>
>
>
> Javi
>
>
>
>
>
>
> JAVIER GARCÍA
>
>
>
> Departamento de Economía Aplicada III (Econometría y Estadística)
>
> Facultad de Economía y Empresa (Sección Sarriko)
> Avda. Lehendakari Aguirre 83
>
> 48015 BILBAO
> T.: +34 601 7126 F.: +34 601 3754
> <http://www.ehu.es/> www.ehu.es
>
> http://www.unibertsitate-hedakuntza.ehu.es/p268-content/es/contenidos/inform
>
acion/manual_id_corp/es_manual/images/firma_email_upv_euskampus_bilingue.gif
>
>
>
>
>
>

--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: [hidden email]
Editor-in-Chief of The R Journal, https://journal.r-project.org/index.html
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: Heteroscedasticity in Spatial Error Model

Sun, 08/13/2017 - 05:49
On Sun, 13 Aug 2017, Javier García wrote:

> Hello again:
>
>
>
> Please, could anyone tell me how to estimate robust standard errors for a
> spatial error model? The residuals of my model show heteroscedasticity
> evidence, but the functions I have looked at only work with lm type objects.
>

The documented approaches use GM rather than ML for fitting - see the
sphet package and https://www.jstatsoft.org/index.php/jss/issue/view/v063.
You should really try to remove the sources of model mis-specification
instead of spreading coefficient standard errors by guesswork. The may
stem from MAUP, missing covariates and/or wrong functional forms.

Roger

>
>
> Thanks a lot in advance.
>
>
>
> Javi
>
>
>
>
>
>
> JAVIER GARCÍA
>
>
>
> Departamento de Economía Aplicada III (Econometría y Estadística)
>
> Facultad de Economía y Empresa (Sección Sarriko)
> Avda. Lehendakari Aguirre 83
>
> 48015 BILBAO
> T.: +34 601 7126 F.: +34 601 3754
> <http://www.ehu.es/> www.ehu.es
>
> http://www.unibertsitate-hedakuntza.ehu.es/p268-content/es/contenidos/inform
> acion/manual_id_corp/es_manual/images/firma_email_upv_euskampus_bilingue.gif
>
>
>
>
>
> --
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: [hidden email]
Editor-in-Chief of The R Journal, https://journal.r-project.org/index.html
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway

Re: How to test spatial dependence in errorsarlm

Sun, 08/13/2017 - 05:44
On Sun, 13 Aug 2017, Javier García wrote:

> Hello everybody:
>
>
>
> I have estimated a spatial error model and now I would like to test whether
> that model has really ?deleted? the spatial dependence. For the spatial lag
> model and for the Durbin model the function lagsarlm gives the LM test for
> residual autocorrelation test value, but the function errorsarlm does not.
> Does anyone know how to do it in R?
> As you should be aware from the literature, the only LM test that has been
written (the maths) is a test for residual error autocorrelation for
spatial lag models. Doing it in R will not help until someone (you?) does
the maths. Computing a value is easy, but knowing what to infer from it is
hard. By definition, if your model is well-specified, the residual
autocorrelation is fully captured by its coefficient. I suspect that your
model suffers from mis-specification problems.

Roger

>
>
> Thanks a lot in advance.
>
>
>
> Javi
>
>
>
>
>
>
> JAVIER GARCÍA
>
>
>
> Departamento de Economía Aplicada III (Econometría y Estadística)
>
> Facultad de Economía y Empresa (Sección Sarriko)
> Avda. Lehendakari Aguirre 83
>
> 48015 BILBAO
> T.: +34 601 7126 F.: +34 601 3754
> <http://www.ehu.es/> www.ehu.es
>
> http://www.unibertsitate-hedakuntza.ehu.es/p268-content/es/contenidos/inform
> acion/manual_id_corp/es_manual/images/firma_email_upv_euskampus_bilingue.gif
>
>
>
>
>
> --
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: [hidden email]
Editor-in-Chief of The R Journal, https://journal.r-project.org/index.html
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway

Heteroscedasticity in Spatial Error Model

Sat, 08/12/2017 - 21:00
v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);}

Hello again:

 

Please, could anyone tell me how to estimate robust standard errors for a spatial error model? The residuals of my model show heteroscedasticity evidence, but the functions I have looked at only work with lm type objects.

 

Thanks a lot in advance.

 

Javi

 

JAVIER GARCÍA

 

Departamento de Economía Aplicada III (Econometría y Estadística)

Facultad de Economía y Empresa (Sección Sarriko)
Avda. Lehendakari Aguirre 83

48015 BILBAO
T.: +34 601 7126 F.: +34 601 3754
www.ehu.es

 

 


_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

How to test spatial dependence in errorsarlm

Sat, 08/12/2017 - 20:35
v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);}

Hello everybody:

 

I have estimated a spatial error model and now I would like to test whether that model has really “deleted” the spatial dependence. For the spatial lag model and for the Durbin model the function lagsarlm gives the LM test for residual autocorrelation test value, but the function errorsarlm does not. Does anyone know how to do it in R?

 

Thanks a lot in advance.

 

Javi

 

JAVIER GARCÍA

 

Departamento de Economía Aplicada III (Econometría y Estadística)

Facultad de Economía y Empresa (Sección Sarriko)
Avda. Lehendakari Aguirre 83

48015 BILBAO
T.: +34 601 7126 F.: +34 601 3754
www.ehu.es

 

 


_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Regression with rasters using calc::raster

Tue, 08/08/2017 - 21:42
Dears,

I'm trying to fit the Firth's Penalized MLE GLM implemented in logistf
package to a set of rasters but I'm facing errors and problems I couldn't
realize until now.

# Lets generate 2 rasters reproducing what I'm facing
r <- raster(nrow=10, ncol=10)

# binary response raster-variable with 9 bands
s1 <- lapply(1:9, function(i) setValues(r, sample(0:1,ncell(r),replace =
T)))
s1 <- stack(s1)

# one explanatory raster-variable
val <- sample(0:60,ncell(r),replace = T)
s2 <- raster(nrow=10, ncol=10,vals=val)

plot(s1)
plot(s2)

# a second explanatory variable. Nine values
exp_2 <- c(27.00,30.02,31.07,32.72,33.73,35.12,35.65,36.06,38.32)

Now, I want to fit a model using Firth's Penalized MLE GLM implemented in
logistf (i have reasons for this not reproduced here) using calc from
raster package. That's where the mystery lives.

The rationale is each cell in:
s1/layer1 ~ 27.00 + corresponding cell in s2 + 27.00:corresponding cell in
s2
s1/layer2 ~ 30.02 + corresponding cell in s2 + 30.02:corresponding cell in
s2
s1/layer3 ~ 31.07 + corresponding cell in s2 + 31.07:corresponding cell in
s2
... and so on for all 9 bands of my response raster-variable, which are
paired with values from exp_2.

# I tried something like this:
fun <- function(x) { logistf(x ~ exp_2 + s2 + exp_2:s2)$coefficients }
coefs <- calc(s1,fun)

But it was clear it wouldn't work. The tricky part is to tell R I want each
value of exp_2 to be used with each rasterlayer of s1 for this model.

Any idea would be appreciated. Ideas?
Thanks in advance

*Jefferson Ferreira-Ferreira, **PhD (abd)*

*Geographer*



*Ecosystem Dynamics Observatory <http://tscanada.wix.com/ecodyn> -
EcoDyn/UNESP*
*Department of **Geography *
*Institute of Geosciences and Exact Sciences** (IGCE)*
*São Paulo State University (UNESP)*
*Rio Claro, SP - Brazil*

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Pages