library(GeoModels)
################################################################
######### Examples of predictive score computation ############
################################################################
library(GeoModels)
model="Gaussian"
set.seed(79)
N=1000
x = runif(N, 0, 1)
y = runif(N, 0, 1)
coords=cbind(x,y)
# Set the exponential cov 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
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]
## estimation with pairwise likelihood
fixed=list(nugget=nugget,smooth=0,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)
# Maximum pairwise likelihood fitting :
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)
# locations to predict
xx=seq(0,1,0.03)
loc_to_pred=as.matrix(expand.grid(xx,xx))
pr=GeoKrig(loc=coords_to_pred,coordx=coords_est,corrmodel=corrmodel,
model=model,param= param, data=data_est,mse=TRUE)
Pr_scores =GeoScores(data_to_pred,pred=pr$pred,mse=pr$mse)
Pr_scores$rmse;Pr_scores$brie
hist(Pr_scores$pit,freq=FALSE)
Run the code above in your browser using DataLab