-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasicfunctions-GEV
More file actions
37 lines (32 loc) · 1003 Bytes
/
Copy pathbasicfunctions-GEV
File metadata and controls
37 lines (32 loc) · 1003 Bytes
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
#################################
### Package
#################################
require(compiler) # speed up R
enableJIT(3)
##################
### Euler Constant
##################
J <- -digamma(1)
########################
### GEV Density function
########################
f <- function(x, mu, sig, xi) {
z = 1 + xi*(x-mu)/sig
ifelse(z > 0, z^(-1/xi-1)/sig * exp(-z^(-1/xi)), 0)
}
#############################
### GEV Distribution Function
#############################
# F <- function(x, mu, sig, xi) {
# z = 1 + xi*(x-mu)/sig
# ifelse(z > 0, exp(-z^(-1/xi)), 0)
# }
#######################################################################
### Generating GEV random sample by inversion transform sampling method
#######################################################################
rgev <- function(n, mu, sig, xi) {
u <- runif(n)
x <- ( mu - (sig/xi) * (1-(-log(u))^(-xi)) ); x
}
# y <- rgev(25, 2, .5, -.5); hist(y, prob = T)
# n <- length(y)