kern is used internally by spei and spifor computing drought indices at different time scales.kern(scale, type = 'rectangular', shift = 0)kern.plot(scale = 12, shift = 0)
scale with weights used for computing the drought index.The most common kernel function is rectangular, i.e. all the data of the previous n time steps are given equal weight. This was the way the Standardized Precipitation Index (SPI) was defined, and it is also the way the SPEI is computed. This would be the default option for the kern function. However, data from the past can be thought of as having a decreasing influence in the current state of the system as the temporal lag between them increases. The function kern allows weighting the past data as a function of the time lapse, according to a series of pre-defined shapes. Available options are 'rectangular' (default), 'triangular', 'circular' and 'gaussian'.
By default the highest weight will be given to the observation of the current month. However, it is possible to modify this by setting the shift parameter to a value higher than zero. This will cause the highest weight be given to the n antecedent observation.
kern.plot produces plots of the weighting factor against the time lag for the four different kernel shapes so they can be compared.
# A rectangular kernel with a time scale of 12 and no shift
kern(12)
# A gaussian kernel with a time scale of 12 and no shift
kern(12,'gaussian')
# Comparison of the four kernels, with and without shift
kern.plot(12)
kern.plot(12,2)Run the code above in your browser using DataLab