I am trying to apply a bias-correction function on some gridded climate data (observed and modelled projections).
The qmap
package has functions to perform bias correction on climate data,
I am trying to run the following
library(raster)
library(qmap)
#Create a rasterStack with observed and modelled data
r <- raster(ncol=20, nrow=20)
obs <- stack(lapply(1:100, function(x) setValues(r, runif(ncell(r))))) #observed data
mod <- stack(lapply(1:100, function(x) setValues(r, runif(ncell(r)))))*2 #modelled data (i want this unbiased)
#bias-correction function
f <- function(obs, mod, ...) {
obs <- t(obs)
qm.fit <- fitQmap(obs, t(mod), method="QUANT",qstep=0.01)
t(doQmap(mod, qm.fit, type="linear") )
}
x <- overlay(obs, mod, fun=f)
I got the following error
Error in (function (x, fun, filename = "", recycle = TRUE, forcefun = FALSE, : cannot use this formula, probably because it is not vectorized
Can anybody help?
Thanks a million