R: Calculation of Standardized Precipitation Index, using the...
Drought Index
R Documentation
Calculation of Standardized Precipitation Index, using the Genetic Algorithm Method (SPIGA) and Maximum Likelihood (SPIML)
Description
Calculate the standardized precipitation index (SPI) for monitoring drought using the technique of Genetic Algorithm (SPIGA) and Maximum Likelihood (SPIML) of a series of monthly rainfall for different time scales.
monthly precipitation series ordered according to time. It is a data frame with columns: year, month, station 1, station 2, etc.
scale
an integer value representing the time scale of analysis. The most common are 1, 3, 6, 9, 12, 48, etc.
population
an integer value that sets the number of population for the use of the technique of Genetic Algorithm.
maxIter
an integer value that sets the maximum number of iterations also called cycles within the concept of Genetic Algorithm.
plotGA
optional, value Boolean default false. Shows the performance versus the number of cycles in the Genetic Algorithm.
plotCDF
optional, value Boolean default false. Shows the cumulative distribution function of each station. The graphics are monthly.
Details
The SPIGA and SPIML, are functions to calculate the SPI using Artificial Intelligence techniques - Genetic Algorithms (GA) and numerical method - Maximum Likelihood (ML) and both provide quantitative results for monitoring DROUGHT. The GA optimize the parameters alpha and beta of the probability function Gamma given by McKee.
The population parameter must be an integer and balanced value, large values can generate higher time run, ie, high computational effort and small values can influence the accuracy of the results. By plotGA option and its corresponding graph, you can see the number of cycles to obtain a proper balance of the accuracy of the results and the computational effort.
Input data
similar to Pm_Pisco.
Year
Mon
st_1
st_2
st_3
st_4
1981
1
120.25
125.25
90.55
150.25
1981
2
145.25
140.25
120.70
145.50
1981
3
120.80
150.28
90.50
130.40
1981
4
90.25
80.25
70.52
120.40
1981
5
50.25
58.25
60.50
80.50
1981
6
40.25
38.45
80.25
50.40
1981
7
20.25
30.69
50.40
40.40
1981
8
1.25
8.85
10.40
25.80
1981
9
25.25
14.25
5.80
20.80
1981
10
13.25
10.23
10.50
30.45
1981
11
50.25
40.25
30.50
80.50
1981
12
80.25
90.52
80.70
90.40
1982
1
145.80
110.25
105.40
120.25
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Value
Functions SPIGA and SPIML return values saved in .txt formats (Tabular) and .pdf (graphics). They are located in the working folder of R [getwd()].
Note
Dependencies: the SPIGA function, depend on the library GA.
McKee, Thomas B. and Doesken, Nolan J. and Kleist, John. 1993. The relationship of Drought Frequency and Duration to Time Scales. Eighth Conference on Applied Climatology
A. Belauneh and J. Adamowski. Standard Precipitation Index Drought Forecasting Using Neural Networks, Wavelet Neural Networks, and Support Vector Regression. Applied Computational Intelligence and Soft Computing, http://dx.doi.org/10.1155/2012/794061
See Also
SPIFromParameters to calculate the standardized precipitation index, from alpha and beta parameter of the Gamma function.
Examples
#### Load data
data(Pm_Pisco)
Pmon<-Pm_Pisco # dataframe Precipitation
summary(Pm_Pisco) # view summary
Pmon<-Pm_Pisco[,]
#### Computing SPI with Genetic Algorithms
pob <-50 # Define population number
iMax <-10 # Define Max iteration
# Total stations calculation. It may take some time.
#SPIGA(Pmon, scale=3, population=pob, maxIter = iMax, plotGA=TRUE, plotCDF=TRUE)
# station 1 computing
Pmon1<-data.frame(Pmon[,1:2], Pmon$Pm_St1)
SPIGA(Pmon1, scale=3, population=pob, maxIter = iMax)
# station 2 computing
Pmon2<-data.frame(Pmon[,1:2], Pmon$Pm_St2)
SPIGA(Pmon2, scale=3, population=pob, maxIter = iMax)
#### Computing SPI with Maximun Likelihood
SPIML(Pmon, scale=3)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(SPIGA)
Loading required package: GA
Loading required package: foreach
Loading required package: iterators
Package 'GA' version 3.0.2
Type 'citation("GA")' for citing this R package in publications.
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/SPIGA/SPIGA.Rd_%03d_medium.png", width=480, height=480)
> ### Name: Drought Index
> ### Title: Calculation of Standardized Precipitation Index, using the
> ### Genetic Algorithm Method (SPIGA) and Maximum Likelihood (SPIML)
> ### Aliases: SPIGA SPIML
>
> ### ** Examples
>
> #### Load data
> data(Pm_Pisco)
> Pmon<-Pm_Pisco # dataframe Precipitation
> summary(Pm_Pisco) # view summary
year month Pm_St1 Pm_St2
Min. :1981 Min. : 1.000 Min. : 0.5866 Min. : 0.5362
1st Qu.:1989 1st Qu.: 3.250 1st Qu.: 16.5649 1st Qu.: 14.0321
Median :1998 Median : 6.000 Median : 46.8745 Median : 47.4559
Mean :1998 Mean : 6.476 Mean : 62.0483 Mean : 59.3716
3rd Qu.:2007 3rd Qu.: 9.000 3rd Qu.: 98.8216 3rd Qu.: 96.8824
Max. :2015 Max. :12.000 Max. :236.0222 Max. :239.9725
Pm_St3 Pm_St4
Min. : 0.4474 Min. : 0.5104
1st Qu.: 13.4251 1st Qu.: 18.5945
Median : 43.8687 Median : 48.0113
Mean : 57.3330 Mean : 65.4650
3rd Qu.: 90.9596 3rd Qu.:100.2296
Max. :236.6156 Max. :244.5666
> Pmon<-Pm_Pisco[,]
>
> #### Computing SPI with Genetic Algorithms
> pob <-50 # Define population number
> iMax <-10 # Define Max iteration
>
> # Total stations calculation. It may take some time.
> #SPIGA(Pmon, scale=3, population=pob, maxIter = iMax, plotGA=TRUE, plotCDF=TRUE)
>
> # station 1 computing
> Pmon1<-data.frame(Pmon[,1:2], Pmon$Pm_St1)
> SPIGA(Pmon1, scale=3, population=pob, maxIter = iMax)
********** Calculation Station Pmon.Pm_St1
SPIGA: Successful Analysis
See the results: /home/ddbj/DataUpdator-rgm3/target
>
> # station 2 computing
> Pmon2<-data.frame(Pmon[,1:2], Pmon$Pm_St2)
> SPIGA(Pmon2, scale=3, population=pob, maxIter = iMax)
********** Calculation Station Pmon.Pm_St2
SPIGA: Successful Analysis
See the results: /home/ddbj/DataUpdator-rgm3/target
>
> #### Computing SPI with Maximun Likelihood
> SPIML(Pmon, scale=3)
********** Calculation Station Pm_St1
********** Calculation Station Pm_St2
********** Calculation Station Pm_St3
********** Calculation Station Pm_St4
SPIML: Successful Analysis
See the results: /home/ddbj/DataUpdator-rgm3/target
>
>
>
>
>
> dev.off()
null device
1
>