iprlma171
/opt/cluster/R/3.0.2/bin:/opt/cluster/openmpi/gcc/64/1.4.2/bin:/opt/cluster/gcc/4.6.0/bin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/opt/cluster/bin

R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-unknown-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.

  Natural language support but running in an English locale

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.

> ## load the package and the data
> library(copula)
> data(loss)
> 
> ## select uncensored claims
> myLoss <- subset(loss, censored==0, select=c("loss", "alae"))
> 
> ## there are many ties in the data
> nrow(myLoss)
[1] 1466
> sapply(myLoss, function(x) length(unique(x)))
loss alae 
 541 1401 
> 
> ## let us break the ties "at random"
> set.seed(123)
> pseudoLoss <- sapply(myLoss, rank, ties.method="random") / (nrow(myLoss) + 1)
> 
> ## extreme-value dependence tests
> evTestK(pseudoLoss)

	Test of bivariate extreme-value dependence based on Kendall's process
	with argument 'method' set to “fsample”

data:  pseudoLoss
statistic = -0.1453, p-value = 0.8845

> evTestC(pseudoLoss)

	Max-stability based test of extreme-value dependence for multivariate
	copulas

data:  pseudoLoss
statistic = 0.1469, p-value = 0.468

> evTestA(pseudoLoss, derivatives="Cn")

	Test of bivariate extreme-value dependence based on the CFG estimator
	with argument 'derivatives' set to 'Cn'

data:  pseudoLoss
statistic = 0.0186, p-value = 0.4231

> 
> ## exchangeability test
> exchEVTest(pseudoLoss)

	Test of exchangeability for bivariate extreme-value copulas with
	argument 'estimator' set to 'CFG', argument 'derivatives' set to 'Cn'
	and argument 'm' set to 100

data:  pseudoLoss
statistic = 0.0751, p-value = 0.1653

> 
> ## goodness-of-fit test
> gofEVCopula(gumbelCopula(), pseudoLoss, method="itau", verbose=FALSE)

	Parametric bootstrap based GOF test for EV copulas with argument
	'method' set to 'itau' and argument 'estimator' set to 'CFG'

data:  pseudoLoss
statistic = 0.0377, parameter = 1.44, p-value = 0.2592

> 
> ## fit the Gumbel-Hougaard family
> fitCopula(gumbelCopula(), pseudoLoss, method="itau")
fitCopula() estimation based on 'inversion of Kendall's tau'
and a sample of size 1466.
      Estimate Std. Error z value Pr(>|z|)    
param  1.44040    0.03327   43.29   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> 
> ## study the effect of the randomization
> randomize <- function()
+ {
+     pseudoLoss <- sapply(myLoss, rank, ties.method="random") / (nrow(myLoss) + 1)
+     evtK <- evTestK(pseudoLoss)$p.value
+     evtC <- evTestC(pseudoLoss)$p.value
+     evtA <- evTestA(pseudoLoss, derivatives="Cn")$p.value
+     exevt <- exchEVTest(pseudoLoss)$p.value
+     gofevGH <- gofEVCopula(gumbelCopula(), pseudoLoss, method="itau", verbose=FALSE)$p.value
+     fitGH <- fitCopula(gumbelCopula(), pseudoLoss, method="itau")
+     c(evtK=evtK, evtC=evtC, evtA=evtA, exevt=exevt, gofevGH=gofevGH,
+       est=fitGH@estimate, se=sqrt(fitGH@var.est))
+ }
> 
> ## replicate 100 times
> #reps <- t(replicate(100, randomize()))
> #round(apply(reps, 2, summary),3)
> 
> ## ignoring the ties can be bad
> pseudoLoss <- pobs(myLoss)
> evTestK(pseudoLoss)

	Test of bivariate extreme-value dependence based on Kendall's process
	with argument 'method' set to “fsample”

data:  pseudoLoss
statistic = 0.5219, p-value = 0.6017

> evTestC(pseudoLoss)

	Max-stability based test of extreme-value dependence for multivariate
	copulas

data:  pseudoLoss
statistic = 0.4005, p-value = 0.01648

> evTestA(pseudoLoss, derivatives = "Cn")

	Test of bivariate extreme-value dependence based on the CFG estimator
	with argument 'derivatives' set to 'Cn'

data:  pseudoLoss
statistic = 0.092, p-value = 0.0004995

> exchEVTest(pseudoLoss)

	Test of exchangeability for bivariate extreme-value copulas with
	argument 'estimator' set to 'CFG', argument 'derivatives' set to 'Cn'
	and argument 'm' set to 100

data:  pseudoLoss
statistic = 0.0814, p-value = 0.1174

> gofEVCopula(gumbelCopula(), pseudoLoss, method="itau", verbose=FALSE)

	Parametric bootstrap based GOF test for EV copulas with argument
	'method' set to 'itau' and argument 'estimator' set to 'CFG'

data:  pseudoLoss
statistic = 0.0476, parameter = 1.446, p-value = 0.1783

> fitCopula(gumbelCopula(), pseudoLoss, method="itau")
fitCopula() estimation based on 'inversion of Kendall's tau'
and a sample of size 1466.
      Estimate Std. Error z value Pr(>|z|)    
param  1.44645    0.03318   43.59   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> 
