[R-sig-Geo] calculate CRPS on rasters
Lorenzo Alfieri
alfios17 at hotmail.com
Fri Nov 30 09:49:00 CET 2012
Robert,
you're right, it works.
I must have done something wrong yesterday
I'm trying to optimize the computation time
I've tested the two alternatives on a predictor of 51 layers of 680x810 pixels
CRPS[] <- crps(obs[],pred[])$crps took 0.98 second
CRPS <- overlay(obs, pred, fun=function(x,y) crps(x,y)$crps) took 1.45 seconds
anyway, thank you all!
Lorenzo
________________________________
> Date: Thu, 29 Nov 2012 10:34:36 -0800
> Subject: Re: [R-sig-Geo] calculate CRPS on rasters
> From: r.hijmans at gmail.com
> To: alfios17 at hotmail.com
> CC: r-sig-geo at r-project.org
>
> Lorenzo,
>
> The below (your example) works for me, using the overlay as I suggested.
> Perhaps you did not load the verification package?
>
> Robert
>
> library(verification) #includes function crps
> library(raster)
> set.seed(1)
> r <- raster(ncol=10, nrow=10)
> pred1 <- init(r, fun=runif)
> pred2 <- init(r, fun=runif)
> pred3 <- init(r, fun=runif)
> pred <- stack(pred1, pred2, pred3)
> obs <- init(r, fun=runif)
>
> CRPS <- overlay(obs, pred, fun=function(x,y) crps(x,y)$crps)
>
>
> > CRPS
> class : RasterLayer
> dimensions : 10, 10, 100 (nrow, ncol, ncell)
> resolution : 36, 18 (x, y)
> extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84
> data source : in memory
> names : layer
> values : 0.003277372, 0.7726679 (min, max)
>
>
> # More fancy, to get all the crps output:
>
> x <- overlay(obs, pred, fun=function(x,y) as.matrix(data.frame(crps(x,y))))
>
>
>
> On Thu, Nov 29, 2012 at 1:15 AM, Lorenzo Alfieri
> <alfios17 at hotmail.com<mailto:alfios17 at hotmail.com>> wrote:
>
> Hi Robert,
> I was hoping to use the overlay function too, but it seems it doesn't
> work in this case. See the result:
>
> CRPS <- overlay(obs, pred, fun=function(x,y) crps(x,y)$crps)
>
> Error in function (x, fun, filename = "", recycle = TRUE, ...) :
> cannot use this formula, probably because it is not vectorized
>
> Lorenzo
>
>
>
> Date: Wed, 28 Nov 2012 11:25:36 -0800
> Subject: Re: [R-sig-Geo] calculate CRPS on rasters
> From: r.hijmans at gmail.com<mailto:r.hijmans at gmail.com>
> To: alfios17 at hotmail.com<mailto:alfios17 at hotmail.com>
> CC: etiennebr at gmail.com<mailto:etiennebr at gmail.com>;
> r-sig-geo at r-project.org<mailto:r-sig-geo at r-project.org>
>
> Lorenzo,
> Given that solution, I think you can also express this (in a
> memory-safe fashion) like this :
> CRPS <- overlay(obs, pred, fun=function(x,y) crps(x, y)$crps)
>
> Robert
>
> On Tue, Nov 27, 2012 at 3:11 AM, Lorenzo Alfieri
> <alfios17 at hotmail.com<mailto:alfios17 at hotmail.com>> wrote:
>
>
>
>
> Etienne,
>
> thank you for the tip
>
> Now it runs trough, by using
>
>
>
> CRPS <- raster(ncol=10, nrow=10)
>
> CRPS[] <- crps(obs[],pred[])$crps
>
>
>
> Lorenzo
>
>
>
>
>
> Date: Mon, 26 Nov 2012 21:37:13 -0500
>
> Subject: Re: [R-sig-Geo] calculate CRPS on rasters
>
> From: etiennebr at gmail.com<mailto:etiennebr at gmail.com>
>
> To: alfios17 at hotmail.com<mailto:alfios17 at hotmail.com>
>
> CC: r-sig-geo at r-project.org<mailto:r-sig-geo at r-project.org>
>
>
>
> Lorenzo,
>
>
>
> I don't know about your specific function, but you can access matrix
> using the []'s. So maybe something like :
>
> CRPS <- raster(ncol=10, nrow=10)
>
> CRPS[] <- crps(obs[],pred[])
>
>
>
>
>
> Etienne
>
>
>
> 2012/11/26 Lorenzo Alfieri
> <alfios17 at hotmail.com<mailto:alfios17 at hotmail.com>>
>
>
>
> CRPS <- raster(ncol=10, nrow=10)
>
>
>
> for (i in 1:length(obs)){
>
>
>
> CRPS[i] <- crps(obs[i],pred[i])$CRPS
>
>
>
> [[alternative HTML version deleted]]
>
>
>
> _______________________________________________
>
> R-sig-Geo mailing list
>
> R-sig-Geo at r-project.org<mailto:R-sig-Geo at r-project.org>
>
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
>
>
More information about the R-sig-Geo
mailing list