Está en la página 1de 4

Paquetes necesarios: stats, graphics, methods, stats4, Matrix, lattice, gsl, ADGofTest, stabledist (>= 0.

6-4),
mvtnorm, pspline, MASS, KernSmooth, sfsmisc, scatterplot3d, Rmpfr, bbmle, partitions, polynom, rugarch,
colorspace, mvnormtest, tseries, zoo
## Calculo de parmetros por mxima verosimilitud a partir del tau emprico (inversin de tau)
## Codigo en R
## Se determina el parmetro alfa por el mtodo de Genest y Rivest (mtodo no paramtrico)
tau <- cor(x, method="kendall")
tau<- tau[1,2]
thetaGU <- copGumbel@iTau(tau)
thetaF <- copFrank@iTau(tau)
thetaC <- copClayton@iTau(tau)
rhoN <- normalCopula(tau)
rhoT <- tCopula(tau)
## Parametro de copula mediante mxima verosimilitud (mtodo paramtrico)
gumbel.cop <- gumbelCopula(thetaGU, dim=2)
(Xtras <- copula:::doExtras())
n <- if(Xtras) 220 else 64
set.seed(7) # for reproducibility
x <- rCopula(n, gumbel.cop)## observacion verdadera
u <- pobs(x) ## pseudo-observaciones
## maxima verosimilitud
fit.ml <- fitCopula(gumbel.cop, x, method="ml")
fit.ml # print()ing works via summary() ...
## and of that, what's the log likelihood (in two different ways):
(ll. <- logLik(fit.ml))
stopifnot(all.equal(as.numeric(ll.),
loglikCopula(coef(fit.ml), x=x, copula=gumbel.cop)))
frank.cop <- frankCopula(thetaF, dim=2)
(Xtras <- copula:::doExtras())
n <- if(Xtras) 220 else 64
set.seed(7) # for reproducibility
x <- rCopula(n, frank.cop)## observacion verdadera

u <- pobs(x) ## pseudo-observaciones


## maxima verosimilitud
fit.ml <- fitCopula(frank.cop, x, method="ml")
fit.ml # print()ing works via summary() ...
## and of that, what's the log likelihood (in two different ways):
(ll. <- logLik(fit.ml))
stopifnot(all.equal(as.numeric(ll.),
loglikCopula(coef(fit.ml), x=x, copula=frank.cop)))
clayton.cop <- claytonCopula(thetaC, dim=2)
(Xtras <- copula:::doExtras())
n <- if(Xtras) 220 else 64
set.seed(7) # for reproducibility
x <- rCopula(n, clayton.cop)## observacion verdadera
u <- pobs(x) ## pseudo-observaciones
## maxima verosimilitud
fit.ml <- fitCopula(clayton.cop, x, method="ml")
fit.ml # print()ing works via summary() ...
## and of that, what's the log likelihood (in two different ways):
(ll. <- logLik(fit.ml))
stopifnot(all.equal(as.numeric(ll.),
loglikCopula(coef(fit.ml), x=x, copula=clayton.cop)))
set.seed(6)
normal.cop <- normalCopula(c(0.958),dim=2,dispstr="un")
x <- rCopula(n, normal.cop) ## "true" observations
u <- pobs(x) ## pseudo-observations
## maximum likelihood
fit.ml <- fitCopula(normal.cop, x, method="ml")
fit.ml
t.cop <- tCopula(c(0.958),dim=2,dispstr="un")
x <- rCopula(n, t.cop) ## "true" observations
u <- pobs(x) ## pseudo-observations
## maximum likelihood
fit.ml <- fitCopula(t.cop, x, method="ml")
fit.ml
d<-2
(copGU <- onacopulaL("Gumbel", list(thetaGU,1:d)))
set.seed(1)
n <- 220
UGU <- rnacopula(n,copGU)
## Estimation
system.time(efmGU <- emle(UGU, copGU))
summary(efmGU) # using bblme's 'mle2' method
(copF <- onacopulaL("Frank", list(thetaF,1:d)))
UF <- rnacopula(n,copF)
## Estimation
system.time(efmF <- emle(UF, copF))
summary(efmF) # using bblme's 'mle2' method
(copC <- onacopulaL("Clayton", list(thetaC,1:d)))
UC <- rnacopula(n,copC)
## Estimation
system.time(efmC <- emle(UC, copC))
summary(efmC) # using bblme's 'mle2' method

Simulacin copula normal, marginales gamma y clculo del estimador de maxima verosimilitud.
## Calculo de parmetros por mxima verosimilitud a partir del tau emprico (inversin de tau)
## Codigo en R
## Se determina el parmetro alfa por el mtodo de Genest y Rivest (mtodo no paramtrico)
tau <- cor(x, method="kendall")
tau<- tau[1,2]
thetaGU <- copGumbel@iTau(tau)
thetaF <- copFrank@iTau(tau)
thetaC <- copClayton@iTau(tau)
rhoN <- normalCopula(tau)
rhoT <- tCopula(tau)

n.cop <- mvdc(normalCopula(0.958), c("gamma", "gamma"), list(list(shape = 0.4513, scale =


59.31), list(shape = 0.4426, scale = 60.4863)))
simulacion <- rMvdc(220, n.cop)
loglikMvdc(c(0.4513, 59.31, 0.4426, 60.4863, 0.958), simulacion, n.cop)
start <- c(0.4513, 59.31, 0.4426, 60.4863, 0.958)
mv.normal <- fitMvdc(simulacion, n.cop, start = start, optim.control = list(trace = TRUE, maxit = 2000))
tcop <- tCopula(c(0.95), dim = 2, dispstr = "un", df.fixed=TRUE)

t.cop <- mvdc(tcop, c("gamma", "gamma"), list(list(shape = 0.4513, scale = 59.31), list(shape =
0.4426, scale = 60.4863)))
simulaciont <- rMvdc(220, t.cop)
loglikMvdc(c(0.4513, 59.31, 0.4426, 60.4863, 0.95), simulaciont, t.cop)
start<- c(0.45,59.13, 0.4426, 60.48, 0.95)
mv.t <- fitMvdc(simulaciont, t.cop, start = start, optim.control = list(trace = TRUE, maxit = 2000))
g.cop <- mvdc(gumbelCopula(24.29), c("gamma", "gamma"), list(list(shape = 0.4513, scale =
59.31), list(shape = 0.4426, scale = 60.4863)))
simulaciong <- rMvdc(220, g.cop)
loglikMvdc(c(0.4513, 59.31, 0.4426, 60.4863, 24.29), simulaciong, g.cop)
mv.g<- fitMvdc(simulaciong, g.cop, start = start, optim.control = list(trace = TRUE, maxit = 2000))
f.cop <- mvdc(frankCopula(95.51), c("gamma", "gamma"), list(list(shape = 0.4513, scale =
59.31), list(shape = 0.4426, scale = 60.4863)))
simulacionf <- rMvdc(220, f.cop)
loglikMvdc(c(0.4513, 59.31, 0.4426, 60.4863, 95.51), simulacionf, f.cop)
mv.f<- fitMvdc(simulacionf, f.cop, start = start, optim.control = list(trace = TRUE, maxit = 2000))
c.cop <- mvdc(claytonCopula(46.59), c("gamma", "gamma"), list(list(shape = 0.4513, scale =
59.31), list(shape = 0.4426, scale = 60.4863)))
simulacionc <- rMvdc(220, c.cop)
loglikMvdc(c(0.4513, 59.31, 0.4426, 60.4863, 46.59), simulacionc, c.cop)
mv.c<- fitMvdc(simulacionc, c.cop, start = start, optim.control = list(trace = TRUE, maxit =
2000))
gofCopula(frankCopula(95.51), simulacionf)
gofCopula(claytonCopula(46.59), simulacionc)
gofCopula(gumbelCopula(24.29), simulaciong)
gofCopula(normalCopula(0.95), simulacion)
tcop <- tCopula(c(0.95), dim = 2, dispstr = "un", df.fixed=TRUE)
gofCopula(tcop, simulaciont)

Parmetro estimado por inversin de tau (mtodo de Genest y Rivest), mxima pseudoverosimilitud y mxima verosimilitud
Copula
No
ml
-2 log L (AIC)
parametrico
Normal
0.958
0.951 (0.004),
-548
248
t
0.958 (df=4)
0.94 (0.006),
-504
251
Gumbel
24.29
24.55(1.38),
-1185
592.5
Clayton
46.59
50.13 (2.4),
-1248
624.8
Frank
95.51
102 (5.7), 585
-1110
Clayton : statistic = 0.0079, parameter = 35.158, p-value = 0.1523
Frank :
statistic = 0.0063, parameter = 81.767, p-value = 0.1034
Gumbel: statistic = 0.0051, parameter = 21.263, p-value = 0.6199
Normal: statistic = 0.0123, parameter = 0.952, p-value = 0.3272
T student: statistic = 0.0122, parameter = 0.948, p-value = 0.3781
Normal -1458.188
T
-1624.291
Gumbel -1221.688
Frank
-1115.354
Clayton -1117.722

También podría gustarte