[R-sig-Geo] Doubt about SPLM function

2020-09-14 Thread Pietro Andre Telatin Paschoalino
Hello everyone,

Could someone help me with splm (Spatial Panel Model By Maximum Likelihood) in 
R?

I want to know if is possible to cluster the standard errors by my individuals 
(like as in plm function). After a lot of research a found that there are more 
people with the same doubt, you can see this here, the person has the same 
problem as me:

https://stackoverflow.com/questions/36869932/clustered-standard-errors-in-spatial-panel-linear-models-splm

Thank you all.

[https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-i...@2.png?v=73d79a89bded]
r - Clustered Standard Errors in Spatial Panel Linear Models (splm) - Stack 
Overflow
I am running spatial panel models (using splm) of census tracts in the U.S. 
between 1990 and 2010 with neighbor matrices based upon distance or contiguity. 
But I also want to cluster the standard e...
stackoverflow.com

Pietro Andre Telatin Paschoalino
Doutorando em Ci�ncias Econ�micas da Universidade Estadual de Maring� - PCE.

[https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif]
Virus-free. 
www.avast.com

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


[R-sig-Geo] "no applicable method" for focal() function in raster

2020-09-14 Thread Jaime Burbano Girón
Hi everyone,

I want to apply a moving window (3x3) to estimate conditional entropy
(Nowosad & Stepinsky, 2019) over a heterogeneous landscape:
*entropy=function(r){*




*  entropy=lsm_l_condent(r, neighbourhood = 4, ordered = TRUE, base =
"log2")  return(entropy$value)}w=matrix(1,3,3)result=focal(r, w,
fun=entropy)*

However, I get this error:
*Error in .focal_fun(values(x), w, as.integer(dim(out)), runfun, NAonly) : *
*Evaluation error: no applicable method for 'lsm_l_condent' applied to an
object of class "c('double', 'numeric')".*

But, when I run entropy function in the entire landscape it works:

*> entropy(r)[1] 2.178874*

*r* is a INT4U raster object:






*class  : RasterLayer dimensions : 886, 999, 885114  (nrow, ncol,
ncell)resolution : 300, 300  (x, y)extent : 934805.7, 1234506, 1006566,
1272366  (xmin, xmax, ymin, ymax)crs: +proj=tmerc
+lat_0=4.5962004167 +lon_0=-74.077507917 +k=1 +x_0=100
+y_0=100 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs values
  : 99, 321113  (min, max)*

There is any idea to solve the "no applicable method" error? Or any idea to
estimate conditional entropy applying a moving window?

Thanks in advance for the help.

Best,

Jaime

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] stars objects and case_when

2020-09-14 Thread Edzer Pebesma
Thank you for pointing to this possibility, I'll add it to the stars 
docs somewhere.


This works but only slightly adapted, e.g. as

out = read_stars(system.file("tif/L7_ETMs.tif", package = "stars")) %>%
  slice(band, 1) %>%
  setNames("x") %>%
  mutate(x = case_when (x<100 ~ NA_real_,   x>100 & x<150 ~ 2))

where:
- I uses setNames("x") so that the attribute is renamed to "x", and you 
can use x in the case_when expressions (rather than the lengthy 
"L7_ETMs.tif")
- I chnaged NA into NA_real_ : the first RHS of the formulas need to be 
all of the same type; as typeof(NA) is "logical", it breaks on the 
second RHS which returns a numeric; if you would TRUE or FALSE rather 
than 2 in the second case_when formula, using NA would be the right 
thing to do in the first.


The examples of case_when document the need for typed NA in RHS: this is 
intended behavior.



On 9/14/20 4:39 PM, Julian M. Burgos wrote:

Dear list,

I am wondering if there is a way to use logical statements to replace values of a stars 
object, for example the case_when function or some other "tidyverse friendly" 
approach.  For example, I can do something like this:

st1 <- read_stars(system.file("tif/L7_ETMs.tif", package = "stars")) %>%
   slice(band, 1)

st1[st1 < 100] <- NA
st1[st1 > 100 & st1 < 150] <- 2

... and so for.  But I am wondering if there is a way to do this as part of a 
pipe, looking something like this:

st1 <- read_stars(system.file("tif/L7_ETMs.tif", package = "stars")) %>%
   slice(band, 1) %>%
   mutate(x <- case_when (x<100 ~ NA,
  x>100 & x<150 ~ 2))

Any ideas?

Takk,

Julian

--
Julian Mariano Burgos, PhD
Hafrannsóknastofnun, rannsókna- og ráðgjafarstofnun hafs og vatna/
Marine and Freshwater Research Institute
Botnsjávarsviðs / Demersal Division
   Fornubúðir 5, IS-220 Hafnarfjörður, Iceland
www.hafogvatn.is
Sími/Telephone : +354-5752037
Netfang/Email: julian.bur...@hafogvatn.is

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo



--
Edzer Pebesma
Institute for Geoinformatics
Heisenbergstrasse 2, 48149 Muenster, Germany
Phone: +49 251 8333081

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] proj.db can't be found when rgdal is loaded (sometimes)

2020-09-14 Thread Roger Bivand

On Mon, 14 Sep 2020, Christian John via R-sig-Geo wrote:


Hi there folks,

I am running into problems using sf objects when rgdal has been loaded.
When I run:


The following is not a reprex. What we need is the output of:


sf::sf_extSoftVersion()

  GEOS   GDAL proj.4 GDAL_with_GEOS USE_PROJ_H
   "3.8.1""3.1.3""7.1.1" "true" "true"

rgdal::rgdal_extSoftVersion()

  GDAL GDAL_with_GEOS   PROJ sp
   "3.1.3" "TRUE""7.1.1""1.4-4"

(in my case). In your case, the PROJ seen by sf is 7.1.1, by rgdal is 
5.2.0. Loading rgdal after sf resets PROJ_LIB to the pre-PROJ 6 version. 
You appear to have installed rgdal binary from CRAN, but installed sf 
(using homebrew ?) and local GEOS/GDAL/PROJ. Either re-install rgdal to 
match, or re-install sf from CRAN as a binary. Installing CRAM MacOS 
binaries should ensure coherence. If problems persist, report back (and 
perhaps on R-sig-Mac, I have no way to check which GDAL/PROJ versions are 
bundled with CAN MacOS binaries.


We are exploring a shared GDAL/PROJ metadata package, but are stuck on the 
same problem - users do not take steps to keep their R packages cleanly 
built on external software, and package maintainers must expect a 
reasonable amount of insight from users.


This list has been given plenty of information that PROJ < 6 and PROJ >= 6 
are different universes, so mixing packages using both is not supported. 
In this case, sf needs proj.db, but cannot find it once rgdal has been 
loaded, pointing PROJ_LIB to a directory without it.


Roger




Sys.getenv("PROJ_LIB")
library(sf); library(rnaturalearth); library(ggplot2)
Sys.getenv("PROJ_LIB")
ROI1 = ne_countries(returnclass = 'sf') %>%
 st_combine() %>%
 st_buffer(0.5)  %>%
 st_wrap_dateline()
ggplot() + geom_sf(data = ROI1)
library(rgdal)
Sys.getenv("PROJ_LIB")
ROI2 = ne_countries(returnclass = 'sf') %>%
 st_combine() %>%
 st_buffer(0.5)  %>%
 st_wrap_dateline()
ggplot() + geom_sf(data = ROI2)

everything plots fine. The sf startup message is:

Linking to GEOS 3.8.1, GDAL 3.1.2, PROJ 7.1.1

The PROJ_LIB changes upon loading rgdal from "" to
"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rgdal/proj".
Loading rgdal generates the message:

Loading required package: sp
rgdal: version: 1.5-16, (SVN revision 1050)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 2.4.2, released 2019/06/28
Path to GDAL shared files:
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rgdal/gdal
GDAL binary built with GEOS: FALSE
Loaded PROJ runtime: Rel. 5.2.0, September 15th, 2018, [PJ_VERSION: 520]
Path to PROJ shared files:
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rgdal/proj
Linking to sp version:1.4-2
Overwritten PROJ_LIB was
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rgdal/proj
Warning message:
package ‘rgdal’ was built under R version 3.6.2

which explains the update in the PROJ_LIB. Notably, the gdal and proj
runtime in the rgdal startup message are completely different from the sf
versions. If I run:

Sys.getenv("PROJ_LIB")
library(sf); library(rnaturalearth); library(ggplot2)
Sys.getenv("PROJ_LIB")
library(rgdal)
Sys.getenv("PROJ_LIB")
ROI2 = ne_countries(returnclass = 'sf') %>%
 st_combine() %>%
 st_buffer(0.5)  %>%
 st_wrap_dateline()
ggplot() + geom_sf(data = ROI2)

which is the same as above, but without the ROI1 generation and plotting, I
get a stack overflow error upon plotting ROI2. All other messages are the
same, except when I run the ggplot() line, I get:

Error: node stack overflow
In addition: There were 50 or more warnings (use warnings() to see the
first 50)
Error during wrapup: node stack overflow

Warnings 1:50 are all

1: In CPL_crs_from_input(x) :
 GDAL Error 1: PROJ: proj_create_from_database: Cannot find proj.db

So, it seems like loading rgdal before doing anything sf:: related causes
the issue. Any ideas for troubleshooting? Session info can be found below.

Best,
Christian


sessionInfo()

R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.6

Matrix products: default
BLAS:
/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK:
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] rgdal_1.5-16sp_1.3-2ggplot2_3.3.0
rnaturalearth_0.1.0
[5] sf_0.9-5

loaded via a namespace (and not attached):
[1] Rcpp_1.0.3 rstudioapi_0.10magrittr_1.5   units_0.6-5

[5] munsell_0.5.0  tidyselect_0.2.5   colorspace_1.4-1
lattice_0.20-38
[9] R6_2.4.1   rlang_0.4.2dplyr_0.8.3tools_3

[R-sig-Geo] proj.db can't be found when rgdal is loaded (sometimes)

2020-09-14 Thread Christian John via R-sig-Geo
Hi there folks,

I am running into problems using sf objects when rgdal has been loaded.
When I run:

Sys.getenv("PROJ_LIB")
library(sf); library(rnaturalearth); library(ggplot2)
Sys.getenv("PROJ_LIB")
ROI1 = ne_countries(returnclass = 'sf') %>%
  st_combine() %>%
  st_buffer(0.5)  %>%
  st_wrap_dateline()
ggplot() + geom_sf(data = ROI1)
library(rgdal)
Sys.getenv("PROJ_LIB")
ROI2 = ne_countries(returnclass = 'sf') %>%
  st_combine() %>%
  st_buffer(0.5)  %>%
  st_wrap_dateline()
ggplot() + geom_sf(data = ROI2)

everything plots fine. The sf startup message is:

Linking to GEOS 3.8.1, GDAL 3.1.2, PROJ 7.1.1

The PROJ_LIB changes upon loading rgdal from "" to
"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rgdal/proj".
Loading rgdal generates the message:

Loading required package: sp
rgdal: version: 1.5-16, (SVN revision 1050)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 2.4.2, released 2019/06/28
Path to GDAL shared files:
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rgdal/gdal
GDAL binary built with GEOS: FALSE
Loaded PROJ runtime: Rel. 5.2.0, September 15th, 2018, [PJ_VERSION: 520]
Path to PROJ shared files:
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rgdal/proj
Linking to sp version:1.4-2
Overwritten PROJ_LIB was
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rgdal/proj
Warning message:
package ‘rgdal’ was built under R version 3.6.2

which explains the update in the PROJ_LIB. Notably, the gdal and proj
runtime in the rgdal startup message are completely different from the sf
versions. If I run:

Sys.getenv("PROJ_LIB")
library(sf); library(rnaturalearth); library(ggplot2)
Sys.getenv("PROJ_LIB")
library(rgdal)
Sys.getenv("PROJ_LIB")
ROI2 = ne_countries(returnclass = 'sf') %>%
  st_combine() %>%
  st_buffer(0.5)  %>%
  st_wrap_dateline()
ggplot() + geom_sf(data = ROI2)

which is the same as above, but without the ROI1 generation and plotting, I
get a stack overflow error upon plotting ROI2. All other messages are the
same, except when I run the ggplot() line, I get:

Error: node stack overflow
In addition: There were 50 or more warnings (use warnings() to see the
first 50)
Error during wrapup: node stack overflow

Warnings 1:50 are all

1: In CPL_crs_from_input(x) :
  GDAL Error 1: PROJ: proj_create_from_database: Cannot find proj.db

So, it seems like loading rgdal before doing anything sf:: related causes
the issue. Any ideas for troubleshooting? Session info can be found below.

Best,
Christian

> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.6

Matrix products: default
BLAS:
/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK:
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] rgdal_1.5-16sp_1.3-2ggplot2_3.3.0
rnaturalearth_0.1.0
[5] sf_0.9-5

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3 rstudioapi_0.10magrittr_1.5   units_0.6-5

 [5] munsell_0.5.0  tidyselect_0.2.5   colorspace_1.4-1
lattice_0.20-38
 [9] R6_2.4.1   rlang_0.4.2dplyr_0.8.3tools_3.6.1

[13] grid_3.6.1 gtable_0.3.0   KernSmooth_2.23-15 e1071_1.7-3

[17] DBI_1.0.0  withr_2.1.2rgeos_0.5-5class_7.3-15

[21] assertthat_0.2.1   lifecycle_0.1.0tibble_2.1.3   crayon_1.3.4

[25] purrr_0.3.3glue_1.3.1 compiler_3.6.1 pillar_1.4.3

[29] scales_1.1.0   classInt_0.4-2 pkgconfig_2.0.3

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Stack of several Raster

2020-09-14 Thread Bede-Fazekas Ákos
Dear Gaëtan,

"order of appearance of my different columns corresponding to my 366 
files (1 year) does not make any sense": do you mean that the order of 
the columns in TMAX60 is not what you want? The column order should 
match the order of the layers in your RasterStack. You can check it with:
names(s)
The order of the layers will correspond to the list of file names stored 
in fs. So you should arrange the file names in the appropriate order, 
and then you'll get columns in TMAX60 in the desired order. Maybe not 
list.files() is the best fuction to use. If the file names follow a 
regular pattern, then you can simply create the character vector of the 
file names with paste() or paste0().

HTH,
Ákos Bede-FAzekas
Hungarian Academy of Sciences


2020.09.14. 18:40 keltezéssel, Gaetan Martinelli írta:
> Good morning all,
>
>
> I would need some advice to move forward.
> I'm starting to use Rstudio to manipulate a climate data and intersect 
> with a differents points on my map (table of 1000 points with 6 
> attributes).
> Also, I have several raster. I have an ASCII file for each day of a 
> year. For 30 years.
>
>
> I tried to use the Stack function and then make the intersection with 
> my 1000 points for one year :
> fs <- list.files(path="N:/Climate-10km/Max_T/1960",
>                  pattern = "asc$", full.names = TRUE)
> s <- raster::stack(fs)
> TMAX60 <- extract(s, DataPoints)
> I'm stuck just at this part ...
> My intersection is good, but the order of appearance of my different 
> columns corresponding to my 366 files (1 year) does not make any 
> sense. They are out of order.
>
> My goal is to create a table with my 6 points attributes, and add a 
> "Year" column and a "Days" column and finally a "Pixel values" column. 
> For a year at first time and if possible doing this intersection for 
> all my years.
> I had the idea to do this for each year and then join my different 
> produced tables.
> In the end, I would have a huge table, but one that will allow me to 
> do my analysis. By calculating this, I will get:
> - 9 attributes (6 attributs points, Year, Day, TMax) and 10 980 000 
> lines (30 years (past) * 366 days * 1000 points).
> Does this seem like a good approach to you ?
> Do you have an idea that could allow me to do this task without going 
> through multiple table operations with "Dplyr" ?
>
> Do you have any advice for a better approach I could take?
>
> Sorry if my English is not always appropriate. I'm not very used to 
> talking in this language yet. I'm working on it. :)
>
> Thank you very much in advance to those who can help me.
>
> Have a good day.
>
> Gaëtan.
>
> ___
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo


[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


[R-sig-Geo] Stack of several Raster

2020-09-14 Thread Gaetan Martinelli
Good morning all,


I would need some advice to move forward.
I'm starting to use Rstudio to manipulate a climate data and intersect with a differents points on my map (table of 1000 points with 6 attributes).
Also, I have several raster. I have an ASCII file for each day of a year. For 30 years.


I tried to use the Stack function and then make the intersection with my 1000 points for one year :
 
fs <- list.files(path="N:/Climate-10km/Max_T/1960",
                 pattern = "asc$", full.names = TRUE)

s <- raster::stack(fs)
 

TMAX60 <- extract(s, DataPoints)

 

 

 

I'm stuck just at this part ...
My intersection is good, but the order of appearance of my different columns corresponding to my 366 files (1 year) does not make any sense. They are out of order.

My goal is to create a table with my 6 points attributes, and add a "Year" column and a "Days" column and finally a "Pixel values" column. For a year at first time and if possible doing this intersection for all my years.

 

I had the idea to do this for each year and then join my different produced tables.

In the end, I would have a huge table, but one that will allow me to do my analysis. By calculating this, I will get:

 

- 9 attributes (6 attributs points, Year, Day, TMax) and 10 980 000 lines (30 years (past) * 366 days * 1000 points).

 

Does this seem like a good approach to you ?

 

Do you have an idea that could allow me to do this task without going through multiple table operations with "Dplyr" ?

Do you have any advice for a better approach I could take?

Sorry if my English is not always appropriate. I'm not very used to talking in this language yet. I'm working on it. :) 

Thank you very much in advance to those who can help me.

Have a good day.

Gaëtan.


___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


[R-sig-Geo] Error image

2020-09-14 Thread Enoch Gyamfi Ampadu
Dear List,

Please I am undertaking land cover classification with the support vector
machine but output image have some portions appearing white. I have tried
both the *caret *and *e1071, *yet I got the same error image. Find below
the codes:

Caret package
modFit_svmR1999 <- train(as.factor(class) ~ B1 + B2 + B3 + B4 + B5 + B7,
data = TrainSet1999, method = "svmRadial")

e1071 package
modFit_svmR1999 <- svm(as.factor(class) ~ B1 + B2 + B3 + B4 + B5 + B7, data
= TrainSet1999)

Before running the above codes, I had done all the necessary image staking,
extracting of pixel values and data partitioning. I don't know what I am
not doing right and I will be glad to have some assistance.
Thank you

Best regards,
Enoch

-- 
*Enoch Gyamfi - Ampadu*

*Geography & Environmental Sciences*

*College of Agriculture, Engineering & Science*

*University of KwaZulu-Natal, Westville Campus*

*Private Bag X54001*
*Durban, South Africa **– 4000**.*
*Phone: +27 835 828255*

*email: egamp...@gmail.com *


*skype: enoch.ampadu*
*The highest evidence of nobility is self-control*.

*A simple act of kindness creates an endless ripple*.

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


[R-sig-Geo] stars objects and case_when

2020-09-14 Thread Julian M. Burgos
Dear list,

I am wondering if there is a way to use logical statements to replace values of 
a stars object, for example the case_when function or some other "tidyverse 
friendly" approach.  For example, I can do something like this:

st1 <- read_stars(system.file("tif/L7_ETMs.tif", package = "stars")) %>%
  slice(band, 1)

st1[st1 < 100] <- NA
st1[st1 > 100 & st1 < 150] <- 2

... and so for.  But I am wondering if there is a way to do this as part of a 
pipe, looking something like this:

st1 <- read_stars(system.file("tif/L7_ETMs.tif", package = "stars")) %>%
  slice(band, 1) %>%
  mutate(x <- case_when (x<100 ~ NA,
 x>100 & x<150 ~ 2))

Any ideas?

Takk,

Julian

--
Julian Mariano Burgos, PhD
Hafrannsóknastofnun, rannsókna- og ráðgjafarstofnun hafs og vatna/
Marine and Freshwater Research Institute
Botnsjávarsviðs / Demersal Division
  Fornubúðir 5, IS-220 Hafnarfjörður, Iceland
www.hafogvatn.is
Sími/Telephone : +354-5752037
Netfang/Email: julian.bur...@hafogvatn.is

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo