##Define the coordinates of each location
n.site <- 30
locations <- matrix(rnorm(2*n.site, sd = sqrt(.2)), ncol = 2)
colnames(locations) <- c("lon", "lat")
##Simulate a max-stable process - with unit Frechet margins
sigma <- matrix(c(100, 25, 25, 220),ncol = 2)
sigma.inv <- solve(sigma)
sqrtCinv <- t(chol(sigma.inv))
model <- list(list(model = "gauss", var = 1, aniso = sqrtCinv / 2))
ms0 <- MaxStableRF(locations[,1], locations[,2], grid=FALSE, model=model,
maxstable = "Bool", n = 50)
ms0 <- t(ms0)
##Now define the spatial model for the GEV parameters
param.loc <- -10 + 2 * locations[,2]
param.scale <- 5 + 2 * locations[,1] + locations[,2]^2
param.shape <- rep(0.2, n.site)
##Transform the unit Frechet margins to GEV
for (i in 1:n.site)
ms0[,i] <- frech2gev(ms0[,i], param.loc[i], param.scale[i],
param.shape[i])
##Define three models for the GEV margins to be fitted
loc.form <- loc ~ lat
scale.form <- scale ~ lon + I(lat^2)
shape.form <- shape ~ lon
M0 <- fitspatgev(ms0, locations, loc.form, scale.form, shape.form)
M1 <- fitspatgev(ms0, locations, loc.form, scale.form, shape.form,
shapeCoeff2 = 0)
##Model selection
anova(M0, M1)
anova(M0, M1, method = "CB", square = "svd")Run the code above in your browser using DataLab