Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPEI returns NA values for time periods < 5 years #77

Open
gingerlolipop opened this issue Sep 27, 2024 · 0 comments
Open

SPEI returns NA values for time periods < 5 years #77

gingerlolipop opened this issue Sep 27, 2024 · 0 comments

Comments

@gingerlolipop
Copy link

I encountered an issue while calculating SPEI for time periods of < 5 years. When I tried to debug with simulation datasets, I find that SPEI only returns correct values when the number of years is >= 5. Specifically:

For 1, 2, or 3 years, SPEI returns all NAs.
For 4 years, it seems mostly correct, but I still observe NA values for January and February in all years.
In my examples, the frequency is set to 12 (monthly data), and the scale is set to 3. Below is the original code used for calculation:

years <- 3 # Try 1, 2, 3, or 4 years
n_months <- years * 12
tave <- runif(n_months, -5, 25)  # Simulate temperature data
ppt <- runif(n_months, 0, 200)   # Simulate precipitation data
latitude <- 40                   # Set latitude

pet_thor <- thornthwaite(tave, latitude)
wb <- ppt - pet_thor
spei_values <- spei(wb, scale = 3)$fitted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant