File: runit.ExtremesData.R

package info (click to toggle)
fextremes 4032.84-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 744 kB
  • sloc: makefile: 14
file content (296 lines) | stat: -rw-r--r-- 8,483 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296

# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General 
# Public License along with this library; if not, write to the 
# Free Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
# MA  02111-1307  USA

# Copyrights (C)
# for this R-port: 
#   1999 - 2007, Diethelm Wuertz, GPL
#   Diethelm Wuertz <wuertz@itp.phys.ethz.ch>
#   info@rmetrics.org
#   www.rmetrics.org
# for the code accessed (or partly included) from other R-ports:
#   see R's copyright and license files
# for the code accessed (or partly included) from contributed R-ports
# and other sources
#   see Rmetrics's copyright file


################################################################################
# FUNCTION             EXPLORATIVE DATA ANALYSIS:
#  emdPlot              Creates an empirical distribution plot
#  qqparetoPlot         Creates exploratory QQ plot for EV analysis
#  mePlot               Creates a sample mean excess function plot
#   mxfPlot             Creates another view of a sample mean excess plot
#   mrlPlot             Returns a mean residual life plot with confidence levels
#  recordsPlot          Plots records development
#   ssrecordsPlot       Plots records development of data subsamples
#  msratioPlot          Plots ratio of maximums and sums
#  sllnPlot             Verifies Kolmogorov's Strong Law of large numbers
#  lilPlot              Verifies Hartman-Wintner's Law of the iterated logarithm
#  xacfPlot             Plots autocorrelations of exceedances
################################################################################


test.emd = 
function()
{
    # emdPlot - Creates an empirical distribution plot
    
    # Artificial Data Set:
    RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
    set.seed(4711, kind = "Marsaglia-Multicarry")
    x = rgpd(1000)
    # Empirical distribution plot:
    par(ask = FALSE)
    par(mfrow = c(2, 2))
    emdPlot(x, plottype = "xy")
    emdPlot(x, plottype = "x")
    emdPlot(x, plottype = "y")
    # emdPlot(x, plottype = " ")                # CHECK !!!
    
    # Artificial Data Set:
    x = rt(1000, df = 3) 
    # Empirical distribution plot:
    par(ask = FALSE)
    par(mfrow = c(2, 2))
    emdPlot(x, plottype = "xy")
    emdPlot(x, plottype = "x")
    emdPlot(x, plottype = "y")
    # emdPlot(x, plottype = " ")                # CHECK !!!
    
    # Artificial Data Set:
    x = rnorm(1000) 
    # Empirical distribution plot:
    par(ask = FALSE)
    par(mfrow = c(2, 2))
    emdPlot(x, plottype = "xy")
    emdPlot(x, plottype = "x")
    emdPlot(x, plottype = "y")
    # emdPlot(x, plottype = " ")                # CHECK !!!
      
    # Return Value:
    return()    
}


# ------------------------------------------------------------------------------


test.qqpareto = 
function()
{
    # qqparetoPlot - Creates exploratory QQ plot for EV analysis

    # Artificial Data Set - 
    RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
    set.seed(4711, kind = "Marsaglia-Multicarry")
    r0 = rgpd(n = 1000, xi = 0)
    r1 = rgpd(n = 1000, xi = 1)
    
    # Graph Frame:
    par(ask = FALSE)
    par(mfrow = c(2, 2))
       
    # Empirical Pareto Distribution Plot:
    qqparetoPlot(x = r0, xi = 0)
    qqparetoPlot(x = r1, xi = 1)
    
    # Empirical Normal Distribution Plot:
    qqnormPlot(x = r0)
    qqnormPlot(x = r1)
    
    # Return Value:
    return()    
}


# ------------------------------------------------------------------------------


test.me = 
function()
{
    # mePlot - Creates a sample mean excess function plot
    # mxfPlot - Creates another view of a sample mean excess plot
    # mrlPlot - Returns a mean residual life plot with confidence levels
    
    # Artificial Data Set - 
    RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
    set.seed(4711, kind = "Marsaglia-Multicarry")
    r = rgpd(n = 1000)
     
    # Mean Excess Function Plot:
    par(ask = FALSE)
    par(mfrow = c(2, 2))
    mePlot(x = r)           # Check, the largest point is missing ...
    mxfPlot(x = r)
    mrlPlot(x = r)
    
    # No Labels:
    par(mfrow = c(2, 2))
    par(ask = FALSE)
    mePlot(x = r, labels = FALSE)
    mxfPlot(x = r, labels = FALSE)
    mrlPlot(x = r, labels = FALSE)
      
    # Return Value:
    return()    
}


# ------------------------------------------------------------------------------


test.records = 
function()
{
    #  recordsPlot - Plots records development
    #  ssrecordsPlot - Plots records development of data subsamples

    # Artificial Data Set - 
    RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
    set.seed(4711, kind = "Marsaglia-Multicarry")
    r = rgpd(n = 1000)
    
    # Records Plot:
    par(mfrow = c(2, 2))
    par(ask = FALSE)
    recordsPlot(x = r)
    recordsPlot(x = r, ci = 0.99)
    ans = recordsPlot(x = r, labels = FALSE)
    print(ans)
    
    # Subrecords Plot:
    set.seed(1985)
    r = rgpd(n = 10000)
    par(mfrow = c(2, 2))
    par(ask = FALSE)
    recordsPlot(r)
    ssrecordsPlot(r, subsamples = 1)
    ssrecordsPlot(r, subsamples = 1, plottype = "log")
    ans = ssrecordsPlot(r, subsamples = 1, plottype = "lin")
    print(ans)
    
    # Subrecords Plot:
    set.seed(1985)
    r = rgpd(n = 10000)
    par(mfrow = c(2, 2))
    par(ask = FALSE)
    ssrecordsPlot(r, subsamples = 10)
    ssrecordsPlot(r, subsamples = 50)
    ssrecordsPlot(r, subsamples = 10, plottype = "log")
    ans = ssrecordsPlot(r, subsamples = 50, plottype = "log", labels = FALSE)
    print(ans)
    
    # Return Value:
    return()    
}


# ------------------------------------------------------------------------------


test.msratio = 
function()
{
    # msratioPlot - Plots ratio of maximums and sums
    
    # Artificial Data Set - 
    RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
    set.seed(4711, kind = "Marsaglia-Multicarry") 
    r = rgpd(n = 1000)
    
    # Mean Excess Function Plot:
    par(ask = FALSE)
    par(mfrow = c(2, 2))
    msratioPlot(x = r, p = 1:4)
    ans = msratioPlot(x = r, p = 1:4, labels = FALSE)
    print(head(ans))
     
    # Return Value:
    return()    
}


# ------------------------------------------------------------------------------


test.laws = 
function()
{
    # sllnPlot - Verifies Kolmogorov's Strong Law of large numbers
    # lilPlot - Verifies Hartman-Wintner's Law of the iterated logarithm

    # Artificial Data Set - 
    RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
    set.seed(4711, kind = "Marsaglia-Multicarry")
    r = rgpd(n = 1000)
    
    # Strong Law of Large Numbers:
    par(ask = FALSE)
    par(mfrow = c(2, 2))
    sllnPlot(x = r)
    ans = sllnPlot(x = r, labels = FALSE)
    print(ans)
    
    # Law of the Iterated Logarithm:
    lilPlot(x = r)
    ans = lilPlot(x = r, labels = FALSE)
    print(ans)
    
    # Return Value:
    return()    
}


# ------------------------------------------------------------------------------


test.xacf = 
function()
{
    # xacfPlot - Plots autocorrelations of exceedances
    
    # Create an Artificial Data Set: 
    RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
    set.seed(4711, kind = "Marsaglia-Multicarry")
    r = rgpd(n = 1000)
    
    # ACF of Exceedances Plot:
    par(ask = FALSE)
    par(mfrow = c(2, 2))
    ans = xacfPlot(x = r)
    print(ans)
    
    # ACF of Exceedances Plot:
    par(ask = FALSE)
    par(mfrow = c(2, 2))
    xacfPlot(x = r, labels = FALSE)
    
    # ACF of Exceedances Plot:
    par(ask = FALSE)
    par(mfrow = c(2, 2))
    xacfPlot(x = r, labels = FALSE, which = 1); title(main = "1")
    xacfPlot(x = r, labels = FALSE, which = 2); title(main = "2")
    xacfPlot(x = r, labels = FALSE, which = "3"); title(main = "3")
    xacfPlot(x = r, labels = FALSE, which = "4"); title(main = "4")
      
    # Return Value:
    return()    
}


################################################################################