forked from danicuba-stats/ExtremalDependence_Unreplicated
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogCopula_nonspatial.R
46 lines (43 loc) · 1.89 KB
/
logCopula_nonspatial.R
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
### ========================================================================= ###
### Auxiliary function to compute log copula function for fully censored data ###
### Daniela Castro-Camilo ###
### Email: [email protected] ###
### ========================================================================= ###
### ========================================================================= ###
### This code has undergone changes for adaptation to a non-spatial setting ###
### and application to unreplicated-settings (non-spatial). ###
### Daniela Cuba ###
### ========================================================================= ###
# Parameters
# theta = c(lambda, rho (correlation))
# u.star: threshold (vector) in uniform scale
log.Cn = function(theta, u.star){
# Warning: works only for "sigma" such that diag(sigma) = 1
lbda = theta[1]
z = sapply(u.star, F1inv, lbda = lbda) # = z.star
sigma=matrix(c(1,theta[2],
theta[2],1),byrow=T,nrow=2,ncol=2)
n = ncol(sigma)
mean = rep(0, n)
probs = NULL
condVars = lapply(1:n, mi_condMVN, mean = mean, sigma = sigma)
unos = rep(1, (n - 1))
sigma0 = matrix(NA, nrow = n, ncol = n)
sigma0[n, n] = 1
for(i in 1 : n){
tmp = condVars[[i]]
condVar = tmp$condVar
C = tmp$C
D = (unos - C); Dt = t(D)
sigma0[1:(n - 1), 1:(n - 1)] = condVar + D %*% Dt
sigma0[1:(n - 1), n] = -D
sigma0[n, 1:(n - 1)] = -Dt
upper = c(z[-i] - z[i]*unos + D * lbda, z[i] - lbda)
set.seed(302)
# browser()
probs[i] = exp(lbda ^ 2/2 - lbda * z[i]) *pmvnorm(lower = -Inf, upper = upper, sigma = sigma0, algorithm = GenzBretz())[1]
}
set.seed(302)
value = as.numeric(pmvnorm(lower = -Inf, upper = z, corr = sigma)[1] - sum(probs))
log(value)
}