An example of SPEI calculation:
library(SPEI)
library(lmomco)
library(zoo)
library(ggplot2)
library(lubridate)
years <- 1961:1965
months <- 1:12
time <- seq(as.Date("1961/1/1"), as.Date("1965/12/31"), by = "month")
n <- length(time)
# Simulated monthly precipitation (mm), potential evapotranspiration (PET) (mm)
precip <- runif(n, min = 0, max = 200)
pet <- runif(n, min = 50, max = 150)
# Water Balance
wb_ts <- ts(precip - pet, start = c(1961, 1), frequency = 12)
# Calculate SPEI for a 3-month timescale
spei_3 <- spei(wb_ts, scale = 3, na.rm = TRUE)
When I calculate Standardized Precipitation Evapotranspiration Index (SPEI), it has a message below:
“Calculating the Standardized Precipitation Evapotranspiration Index (SPEI) at a time scale of 3. Using kernel type ‘rectangular’, with 0 shift. Fitting the data to a log-Logistic distribution. Using the ub-pwm parameter fitting method. Missing values (NA
) will not be considered in the calculation. Using the whole time series as reference period. Input type is vector. No time information provided, assuming a monthly time series.”
It is annoying when I try to calculate a lot of SPEIs using a loop. I already used the suppressMessages funtion below but it did not work:
fit <- suppressMessages(spei(wb, scale = scale, na.rm = TRUE))
spei_values <- as.numeric(fit$fitted)
1