I'm trying to calculate crps using the verification package in R. The data appears to read in ok, but I get an error when trying to compute the CRPS itself: "invalid 'times' argument", however all values are real, no negative values and I'm testing for nan/na values and ignoring those. Having searched around I can't find any solution which explains why I'm getting this error. I'm reading the data in from netcdf files into larger arrays, and then computing CRPS for each grid cell in those arrays.
Any help would be greatly appreciated!
The relevant snipped from the code I'm using is:
##for each grid cell, get obs (wbarray) and 25 ensemble members of forecast eps (fcstarray)
for(x in 1:3600){
for(y in 1:1500){
obs=wbarray[x,y]
eps=fcstarray[x,y,1:25]
if(!is.na(obs)){
print(obs)
print(eps)
print("calculating CRPS - real value found")
crpsfcst=(crpsDecomposition(obs,eps)$CRPS)
CRPSfcst[x,y,w]=crpsfcst}}}
(w is specified in an earlier loop)
And the output I get:
obs: 0.3850737 eps: 0.3382506 0.3466184 0.3508921 0.3428135 0.3416993 0.3423528 0.3307764 0.3372431 0.3394377 0.3398165 0.3414395 0.3531360 0.3319155 0.3453161 0.3362813 0.3449474 0.3340050 0.3278898 0.3380596 0.3379150 0.3429202 0.3467927 0.3419354 0.3472489 0.3550797 "calculating CRPS - real value found" Error in rep(0, nObs * (nMember +1)) : invalid 'times' argument Calls: crpsDecomposition Execution halted
If you type crpsDecomposition
on your R command prompt you'll get the source code for the function. The first few lines show:
function (obs, eps)
{
nMember = dim(eps)[2]
nObs <- length(obs)
Since your eps
data object appears to be (from your output) a one-dimensional vector, the second element of its dimension is going to be NULL
, which sets nMember
to NULL
. Thus nObs*(nMember + 1)
gets evaluated to 0. I imagine you simply need to re-examine what form eps
should take because it would appear that it needs to be a matrix where each column corresponds to a different "member" (whatever that means in this context).