library(GeoModels)
##########################################
#### Example: spatial neighborhood ######
##########################################
set.seed(75)
coords=cbind(runif(500),runif(500))
param=list(nugget=0,mean=0,scale=0.2,sill=1,
power2=4,smooth=1)
data_all = GeoSim(coordx=coords, corrmodel="GenWend",
param=param)$data
plot(coords)
##two locations
loc_to_pred=matrix(c(0.3,0.5,0.7,0.2),2,2)
points(loc_to_pred,pch=20)
neigh=GeoNeighborhood(data_all, coordx=coords,
loc=loc_to_pred,neighb=8)
# two Neighborhoods
neigh$coordx
points(neigh$coordx[[1]],pch=20,col="red")
points(neigh$coordx[[2]],pch=20,col="blue")
# associated data
neigh$data
###################################################
#### Example: spatio temporal spatial neighborhood#
###################################################
set.seed(78)
coords=matrix(runif(80),40,2)
coordt=seq(0,6,0.25)
param=list(nugget=0,mean=0,scale_s=0.2/3,scale_t=0.25/3,sill=2)
data_all = GeoSim(coordx=coords, coordt=coordt,corrmodel="Exp_Exp",
param=param)$data
## two location to predict
loc_to_pred=matrix(runif(4),2,2)
## three temporal instants to predict
time=c(1,2)
plot(coords,xlim=c(0,1),ylim=c(0,1))
points(loc_to_pred,pch=20)
neigh=GeoNeighborhood(data_all, coordx=coords, coordt=coordt,
loc=loc_to_pred,time=time,neighb=3,maxtime=0.5)
# first spatio-temporal neighborhoods
# with associated data
neigh$coordx[[1]]
neigh$coordt[[1]]
neigh$data[[1]]
plot(coords)
points(loc_to_pred,pch=20)
points(neigh$coordx[[1]],col="red",pch=20)
###################################################
#### Example: bivariate spatial neighborhood #####
###################################################
set.seed(79)
coords=matrix(runif(100),50,2)
param=list(mean_1=0,mean_2=0,scale=0.12,smooth=0.5,
sill_1=1,sill_2=1,nugget_1=0,nugget_2=0,pcol=0.5)
data_all = GeoSim(coordx=coords,corrmodel="Bi_matern_sep",
param=param)$data
## two location to predict
loc_to_pred=matrix(runif(4),2,2)
neigh=GeoNeighborhood(data_all, coordx=coords,bivariate=TRUE,
loc=loc_to_pred,neighb=5)
plot(coords)
points(loc_to_pred,pch=20)
points(neigh$coordx[[1]],col="red",pch=20)
points(neigh$coordx[[2]],col="red",pch=20)
Run the code above in your browser using DataLab