The mbsi package provide tools to compute and visualize extreme hydro-climatic events using the standardized precipitation index (SPI) and the model-based standardized index (MBSI). The difference with between the MBSPI and the classical SPI index is that it consider the association between continuous times using cycle P-splines ‘pbc’. The package can also with work with precipitation series containing missing values (NA), 0 or only non-zero values.
This package is not still on CRAN, so installation is done using the devtools
package as shown below:
devtools::install_github("ErickChacon/mbsi")
library(mbsi)
data(simrain)
# Compute mbsi
spi_rain <- mbsi(y = simrain$rain, time = simrain$time, tscale = 1, period = 52)
## GAMLSS-RS iteration 1: Global Deviance = -2344.71
## GAMLSS-RS iteration 2: Global Deviance = -2344.712
## GAMLSS-RS iteration 3: Global Deviance = -2344.712
## new prediction
## new prediction
# Visualize model fitting
plot(spi_rain)
# Visualize distribution of empirical cumulative density function
plot(spi_rain, which = "ecdf", binwidth = 0.05)
# Visualize extreme events
plot_extremes(spi_rain, threshold = 2)
# Compute mbsi
spi_rain_8 <- mbsi(y = simrain$rain, time = simrain$time, tscale = 8, period = 52)
## GAMLSS-RS iteration 1: Global Deviance = -2344.71
## GAMLSS-RS iteration 2: Global Deviance = -2344.712
## GAMLSS-RS iteration 3: Global Deviance = -2344.712
## new prediction
## new prediction
# Visualize model fitting
plot(spi_rain_8)
# Visualize distribution of empirical cumulative density function
plot(spi_rain_8, which = "ecdf", binwidth = 0.05)
# Visualize extreme events
plot_extremes(spi_rain_8, threshold = 2)