Getting NA for only one specific month in all years when calculating SPEI using the SPEI package on R

Viewed 84

I am trying to calculate the Standard Precipitation-Evaporation Index (SPEI) for two of my datasets. I am following exactly as shown in this link: https://www.youtube.com/watch?v=dLpmUVDRFbM

For the first dataset, I am able develop the code easily and obtain the SPEI. However, when I run the same code (replacing only the file name) on my second dataset to obtain the 1-month SPEI, I get NAs for February in all years as shown below:

library(readxl)
> projected_data <- read_excel("C:/Users/user/Desktop/data/projected_data.xlsx")
> View(projected_data)

library(SPEI)
Loading required package: lmomco
# Package lmomco (2.3.6) loaded [try lmomcoNews()].
Loading required package: parallel
Loading required package: ggplot2
# Package SPEI (1.7) loaded [try SPEINews()].

projected_data$PET <- hargreaves(Tmin = projected_data$Tmin, Tmax = projected_data$Tmax, lat = 5.25)

CWBAL <- projected_data$Prcp - projected_data$PET
CWBAL

           Jan          Feb          Mar          Apr          May
1   75.4386641  444.4417824   -8.5541712   69.9909037  109.9528125
2    5.9298247  -41.3430547    1.4042706  302.5044746  -36.6315834
3  311.0488624  -85.3718236  -91.1744377 -113.3596839   26.0719854
4   29.1115591  -78.4703712   51.5933212 -100.3705079  120.9438707
5  508.9136359  196.0422348  146.0821914   54.9264503  157.1560481
6  163.2864159  -76.6473220  -90.3838261   58.8558214  143.6379329
7  -74.6881865  -91.0439172  -16.3432910 -107.0560987   84.6188159
8   50.2870964  -32.3971291  -74.0620514  -10.3565089   62.9861451
9  600.1100806  377.0716584   91.1615313  -42.0647868  180.6766760
           Jun          Jul          Aug          Sep          Oct
1   11.4701246  -14.6552498   -7.4392610  -29.2493228  254.3991631
2   19.4581336  -11.1440166  112.4642317  156.4665713  361.9735545
3   69.6550692  109.7987920   36.1300596   65.2624332  213.6855367
4    3.3581064  -23.8064163   30.7464641  -23.1661235  258.9628908
5  117.0659863  -81.0829457   -7.6439177   88.1314627  177.8909923
6    0.5778707  -41.9787329   52.7999676  227.7360382  256.2451631
7  -56.7258322  -38.6391338   31.7851671  116.6783525   10.2833123
8  -15.4928697   28.5641950  240.5354793  203.9828837  259.2584972
9   86.5673327   32.9232411  131.6934692  -56.3272465  150.5631115
           Nov          Dec
1  209.0835493  435.0050254
2  367.5924900  374.7203333
3  368.6638444 1078.9750242
4  564.0036194  587.9484422
5  212.6347562  850.0957753
6  484.3855597  172.6600715
7  525.0380781  790.2432053
8  944.3866442  782.1267794
9  353.8151306  462.1942637

spei1<-spei(CWBAL,1)
spei1

           Jan          Feb          Mar          Apr          May
1 -0.257855061           NA  0.055765260  0.739254269  0.042754674
2 -0.720257246           NA  0.185093090  1.735033174 -1.590072302
3  0.811741938           NA -1.175821699 -1.142433163 -1.063330924
4 -0.557042280           NA  0.756135752 -0.953362529  0.231612777
5  1.338768773           NA  1.519572148  0.637476637  0.916520165
6  0.219773608           NA -1.163146837  0.664702119  0.650909785
7 -1.367501802           NA -0.048951929 -1.049372089 -0.352847024
8 -0.415941889           NA -0.904015394  0.103346782 -0.646421074
9  1.519314072           NA  1.117970676 -0.221773488  1.401124006
           Jun          Jul          Aug          Sep          Oct
1 -0.167100348  0.014821053 -1.230170874 -1.073729460  0.237070293
2 -0.004566021  0.088831629  0.888778346  0.721661340  2.101180787
3  0.881626941  1.687751598 -0.147232326 -0.174253890 -0.279117433
4 -0.336424671 -0.187185952 -0.254525154 -1.019959043  0.301483773
5  1.496865853 -1.706035307 -1.236703004  0.055293014 -0.650479738
6 -0.395262154 -0.625220277  0.149035605  1.338076649  0.262966758
7 -1.629950920 -0.541282584 -0.233343562  0.339611741 -1.721001307
8 -0.740647903  0.793956152  1.689811144  1.143380875  0.305701305
9  1.123324366  0.857875211  1.056471376 -1.304792915 -0.889447215
           Nov          Dec
1 -1.340313211 -0.641007175
2 -0.147727331 -0.854329309
3 -0.141109103  1.532589892
4  0.799354105 -0.078149361
5 -1.308487786  0.853468636
6  0.473969367 -1.510356156
7  0.648596403  0.652660512
8  1.742313434  0.624743194
9 -0.234464737 -0.542706824

This only happens when I try to calculate the 1-month SPEI.

Why does this happen? And is there anything I can do to fix it?

0 Answers
Related