library(GeoModels)
################################################################
######### Example of predictive score computation #############
################################################################
model <- "Gaussian"
set.seed(79)
N <- 1000
x <- runif(N, 0, 1)
y <- runif(N, 0, 1)
coords <- cbind(x, y)
# Set covariance parameters
corrmodel <- "GenWend"
mean <- 0
sill <- 5
nugget <- 0
scale <- 0.2
smooth <- 0
power2 <- 4
param <- list(mean = mean, sill = sill, nugget = nugget,
scale = scale, smooth = smooth, power2 = power2)
# Simulation of the spatial Gaussian random field
data <- GeoSim(coordx = coords, corrmodel = corrmodel,
param = param)$data
# Training and validation split
sel <- sample(1:N, N * 0.8)
coords_est <- coords[sel, ]
coords_to_pred <- coords[-sel, ]
data_est <- data[sel]
data_to_pred <- data[-sel]
# Pairwise likelihood fitting
fixed <- list(nugget = nugget, smooth = smooth, power2 = power2)
start <- list(mean = 0, scale = scale, sill = 1)
I <- Inf
lower <- list(mean = -I, scale = 0, sill = 0)
upper <- list(mean = I, scale = I, sill = I)
fit <- GeoFit(data_est, coordx = coords_est,
corrmodel = corrmodel, model = model,
likelihood = "Marginal", type = "Pairwise",
neighb = 3, optimizer = "nlminb",
lower = lower, upper = upper,
start = start, fixed = fixed)
# Prediction at validation locations
pr <- GeoKrig(fit,loc = coords_to_pred, data = data_est, mse = TRUE)
# Predictive scores from pred and mse
Pr_scores <- GeoScores(data_to_pred, pred = pr$pred, mse = pr$mse,
score = c("pe", "brie", "crps", "lscore",
"pit", "intscore", "coverage"),
threshold = 0)
Pr_scores$MAE
Pr_scores$RMSPE
Pr_scores$Brier
Pr_scores$CRPS
Pr_scores$LogScore
Pr_scores$IS95
Pr_scores$Cvg95
Run the code above in your browser using DataLab