R: 计算 CRPS 的 'times' 参数无效

R: invalid 'times' argument calculating CRPS

我正在尝试使用 R 中的验证包计算 crps。数据似乎可以正常读取,但在尝试计算 CRPS 本身时出现错误:"invalid 'times' argument",但是所有值都是真实的,没有负值,我正在测试 nan/na 值并忽略它们。四处搜索后,我找不到任何解决方案来解释为什么我会收到此错误。我正在将 netcdf 文件中的数据读入更大的数组,然后为这些数组中的每个网格单元计算 CRPS。

如有任何帮助,我们将不胜感激!

从我使用的代码中截取的相关内容是:

##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 在较早的循环中指定)

我得到的输出:

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

如果您在 R 命令提示符下键入 crpsDecomposition,您将获得该函数的源代码。前几行显示:

function (obs, eps) 
{
    nMember = dim(eps)[2]
    nObs <- length(obs)

由于您的 eps 数据对象 看起来 是(从您的输出中)一个一维向量,其维度的第二个元素将是 NULL,它将 nMember 设置为 NULL。因此 nObs*(nMember + 1) 被评估为 0。我想你只需要重新检查 eps 应该采用什么形式,因为看起来它需要是一个矩阵,其中每一列对应不同的 "member"(无论在这种情况下是什么意思)。