nllHT | R Documentation |
Calculates the negative log-likelihood for Y|X=x. This is a profile log-likelihood with free parameters α and β. We use the same normalising functions as in the original paper.
nllHT(X, Y, par)
X |
Vector of Laplace variables. This is the conditioning variable i.e. X=x. |
Y |
Vector of Laplace variables, Y. |
par |
Vector (α,β). |
Negative log-likelihood for Heffernan and Tawn model fit to Y|X=x.
Heffernan and Tawn (2004), Journal of the Royal Statistical Society: Series B, 66:497-546, (doi)
#For a N by d matrix of data "Z" and d by 2 matrix of coordinates "Gcoords". # We use data(Aus_Heat) as an example. library(rmutil) library(fields) data(Aus_Heat) Z<-Aus_Heat$Temp. Gcoords<-Aus_Heat$coords unif<-function(x) rank(x)/(length(x)+1) Z_U<-Z for(i in 1:dim(Z_U)[2]) Z_U[,i]<-unif(Z[,i]) # Transform to uniform margins Z_LP<-qlaplace(Z_U) # Transform to Laplace margins p<-dim(Gcoords)[1] ConExp<-matrix(0,nrow=p,ncol=p) u<-quantile(Z_LP,0.98) #Quantile for estimating conditional expectation #Calculate conditional expectation for each pair for(i in 1:p){ for(j in 1:i){ Exceedances<-cbind(Z_LP[,i],Z_LP[,j])[which(Z_LP[,i]>=u),] opt<-optim(nllHT,X=Exceedances[,1],Y=Exceedances[,2],par=c(0.3,0.8)) #print(opt) alpha<-opt$par[1] beta<-opt$par[2] mu<-mean((Exceedances[,2]-alpha*Exceedances[,1])/Exceedances[,1]^beta) ConExp[i,j]<-alpha*u+u^beta*mu } } ConExp<-ConExp+t(ConExp) ##Symmetry assumed diag(ConExp)<-diag(ConExp)/2 plot(rdist.earth(Gcoords,miles=F),ConExp, ylab="Conditional Expectation", xlab="Distance (Km)", main="")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.