# Load data
data(wichita)
attach(wichita)
# One and tvelwe-months SPI
spi_1 <- spi(PRCP,1)
spi_12 <- spi(PRCP,12)
plot(cbind(spi_1,spi_12))
# Notice that the first eleven values of spei_12 are NA
# One and tvelwe-months SPEI
wichita$PET <- thornthwaite(TMED,37.6475)
spei1 <- spei(PRCP-wichita$PET,1)
spei12 <- spei(PRCP-wichita$PET,12)
plot(cbind(spei1,spei12))
# Data series not starting in January: define the properties
# of the time series with ts()
plot(spei(ts(PRCP-wichita$PET,freq=12,start=c(1900,6)),12))
# Different kernels
spei24 <- spei(PRCP-wichita$PET,24)
spei24_gau <- spei(PRCP-wichita$PET,24,kernel=list(type='gaussian',shift=0))
plot(ts(cbind(spei24,spei24_gau),start=c(1900,1),freq=12))
# Several time series at a time
data(balance)
names(balance)
bal_spei12 <- spei(balance,12)
colnames(bal_spei12) <- names(balance)
plot(ts(bal_spei12[,1:6],start=c(1900,1),freq=12),main='12-month SPEI')
plot(ts(bal_spei12[,7:11],start=c(1900,1),freq=12),main='12-month SPEI')Run the code above in your browser using DataLab