## Not run:
# ## Load data
# data(COSha30)
# data(COSha30map)
# data(lalib)
#
# ## Calculate the sample variogram for data, generate the variogram model and
# ## fit ranges and/or sills from the variogram model to the sample variogram
# ve <- variogram(CorT~ 1, loc=~x+y, data=COSha30, width = 236.0536)
# PSI <- 0.0001531892; RAN <- 1031.8884; NUG <- 0.0001471817
# m.esf <- vgm(PSI, "Sph", RAN, NUG)
# (m.f.esf <- fit.variogram(ve, m.esf))
#
# ## Number of additional points to be added to the network
# npoints <- 5
#
# ## Optimize the location of the additional points
# ## Only 20 generations are evaluated in this example (using ordinary kriging)
# ## Users can visualize how the location of the additional points is optimized
# ## if plotMap is set to TRUE
# old.par <- par(no.readonly = TRUE)
# par(ask=FALSE)
# optnets <- simPtsOptNet(CorT~ 1, loc=~x+y, COSha30, m.f.esf, n=npoints,
# popSize=30, generations=20, xmin=bbox(lalib)[1], ymin=bbox(lalib)[2],
# xmax=bbox(lalib)[3], ymax=bbox(lalib)[4], plotMap=TRUE, spMap=lalib)
# par(old.par)
#
# ## Summary of the genetic algorithm results
# summary(optnets, echo=TRUE)
#
# ## Graph of best and mean evaluation value of the objective function
# ## (average standard error) along generations
# plot(optnets)
#
# ## Find and plot the best set of additional points (best chromosome) in
# ## the population in the last generation
# (bnet <- bestnet(optnets))
# l1 = list("sp.polygons", lalib)
# l2 = list("sp.points", bnet, col="green", pch="*", cex=5)
# spplot(COSha30map, "var1.pred", main="Location of the optimized points",
# col.regions=bpy.colors(100), scales = list(draw =TRUE), xlab ="East (m)",
# ylab = "North (m)", sp.layout=list(l1,l2))
#
# ## Average standard error of the optimized additional points
# min(optnets$evaluations)
# ## End(Not run)
## Multivariate prediction is also enabled:
## Not run:
# ve <- variogram(CorT~ DA30, loc=~x+y, data=COSha30, width = 236.0536)
# (m.f.esf <- fit.variogram(ve, m.esf))
#
# optnetsMP <- simPtsOptNet(CorT~ DA30, loc=~x+y, COSha30, m.f.esf, n=npoints,
# popSize=30, generations=25, xmin=bbox(lalib)[1], ymin=bbox(lalib)[2],
# xmax=bbox(lalib)[3], ymax=bbox(lalib)[4], plotMap=TRUE, spMap=lalib)
# ## End(Not run)
Run the code above in your browser using DataLab