Description Usage Arguments Details Value See Also Examples
View source: R/standardized.index.R
Function to calculate a Standardized Index (SPI, SPEI, SSI,...) for a time series.
1 2 3 4 5 6 7 | standardized.index(data, index.out, agg.length, agg.fun = "sum",
ref.data = data, distr = c("gamma", "gamma3", "weibull", "weibull3",
"gev", "glogis"), method = c("mle", "lmom"), params = NULL,
ks.thres = NULL, ad.thres = NULL, ref.years = NULL,
ref.length = 30, ref.na.thres = 10, agg.na.thres = ref.na.thres,
agg.interpolation = c("none", "linear", "mean", "zeros"), digits = 2,
output.attrs = c("some", "all"))
|
data |
an xts object containing observed daily data |
index.out |
vector of dates for which the standardized index is to be calculated |
agg.length |
length of the aggregation period in days |
agg.fun |
function on x to apply to the aggregation data, default is 'sum' |
ref.data |
an xts object containing daily reference data, default is data itself |
distr |
name of the distribution to be fitted, see details |
method |
distribution fitting method, 'mle' (default) for maximum likelihood estimation, 'lmom' for L-moments |
params |
xts containing the reference distribution parameters for each index.out, if not specified (NULL) or missing for specific dates, they are calculated, in which case ref.data should be specified |
ks.thres |
threshold p-value for the Kolmogrov-Smirnov test, if rejected, the value is set to NA, default= NULL (test not applied) |
ad.thres |
threshold p-value for the Anderson-Darling test, if rejected, the value is set to NA, default= NULL (test not applied) |
ref.years |
years to be used as reference period, default is to use all years in ref.data. If NULL, ref.length is used |
ref.length |
if ref.years is null, the ref.length number of years (default = 30) preceding (but not including) the index.out timestamp are used as reference period |
ref.na.thres |
threshold for the percentage of NA values allowed in reference period data, default = 10% |
agg.na.thres |
threshold for the percentage of na values allowed in the aggregation period data, default = ref.na.thres |
agg.interpolation |
interpolation type for missing values in aggregation data for an individual reference period element: 'none' (default, NA's are removed), 'linear', 'mean', or 'zeros' |
digits |
number of digits for rounding the resulting standardized index values, default = 2 |
output.attrs |
determines what is attached as xtsAttributes: 'some' (default) adds function settings, and 'all' adds function settings, data and ref.data attributes and the reference values for index.out, aggregation values for index.out, and an xts object containing the fitted parameters |
The argument distr can be either: 'gamma' for the gamma distribution, 'gamma3' for the 3-parameter gamma distribution, 'weibull' for the 'weibull distribution, 'weibull3' for the 'weibull distribution, 'gev' for the Generalized Extreme Value distribution, or 'glo' for the shifted log-logistic distribution. The fit.distribution function is used internally to calculate distribution fits, alternatively the parameters for the reference distribution can be supplied via the params argument.
An xts object containing the standardized index values.
fit.distribution
, get.reference.values
, fprint
1 2 3 4 5 6 7 8 | data(Ukkel_RR)
# since this is rainfall data, we are calculating the SPI
# calculate SPI-1 for July 2011, which is approximated by setting agg.length to 30 days
SPI_1 <- standardized.index(data=Ukkel_RR,agg.length=30,index.out=index(Ukkel_RR['2011-07']))
fprint(SPI_1)
# calculate SPI-3 for July 2011, which is approximated by setting agg.length to 90 days
SPI_3 <- standardized.index(data=Ukkel_RR,agg.length=90,index.out=index(Ukkel_RR['2011-07']))
fprint(SPI_3)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.