Learn R Programming

cocons (version 0.1.3)

cocoPredict: Prediction Routines for Nonstationary Spatial Models

Description

Computes point predictions and standard errors based on conditional Gaussian distributions for nonstationary spatial models.

Usage

cocoPredict(coco.object, newdataset, newlocs, type = 'mean', ...)

Value

A list containing:

  • trend: The systematic large-scale variability.

  • mean: The stochastic mean.

  • sd.pred: The standard errors, when type = 'pred' is specified.

Arguments

coco.object

(S4) A fitted coco object.

newdataset

(data.frame) A data.frame containing the covariates present in model.list at the prediction locations.

newlocs

(matrix) A matrix specifying the prediction locations, matching newdataset index.

type

(character) Specifies whether to return only the point prediction ('mean') or both the point prediction and prediction standard errors ('pred').

...

Additional arguments. If coco.object contains multiple realizations, the argument index.pred can be used to specify which realization of coco.object@z should be used for the predictions.

Author

Federico Blasi

Examples

Run this code
if (FALSE) {

# Stationary model

model.list_stat <- list('mean' = 0,
'std.dev' = formula( ~ 1),
'scale' = formula( ~ 1),
'aniso' = 0,
'tilt' = 0,
'smooth' = 3/2,
'nugget' = -Inf)

 
model.list_ns <- list('mean' = 0,
'std.dev' = formula( ~ 1 + cov_x + cov_y),
'scale' = formula( ~ 1 + cov_x + cov_y),
'aniso' = 0,
'tilt' = 0,
'smooth' = 3/2,
'nugget' = -Inf)

coco_object <- coco(type = 'dense',
data = holes[[1]][1:100, ],
locs = as.matrix(holes[[1]][1:100, 1:2]),
z = holes[[1]][1:100, ]$z,
model.list = model.list_stat)

optim_coco_stat <- cocoOptim(coco_object,
boundaries = getBoundaries(coco_object,
lower.value = -3, 3))

coco_preds_stat <- cocoPredict(optim_coco_stat, newdataset = holes[[2]],
newlocs = as.matrix(holes[[2]][, 1:2]),
type = "pred")

# Update model
coco_object@model.list <- model.list_ns

optim_coco_ns <- cocoOptim(coco_object,
boundaries = getBoundaries(coco_object,
lower.value = -3, 3))

coco_preds_ns <- cocoPredict(optim_coco_ns, newdataset = holes[[2]],
newlocs = as.matrix(holes[[2]][, 1:2]),
type = "pred")

par(mfrow = c(1, 3))

fields::quilt.plot(main = "full data", holes[[1]][, 1:2], 
holes[[1]]$z, xlim = c(-1, 1), ylim = c(-1, 1))

fields::quilt.plot(main = "stationary se", holes[[2]][, 1:2], 
coco_preds_stat$sd.pred, xlim = c(-1, 1), ylim = c(-1, 1))
fields::quilt.plot(main = "nonstationary se", holes[[2]][, 1:2], 
coco_preds_ns$sd.pred, xlim = c(-1, 1), ylim = c(-1, 1))


}

Run the code above in your browser using DataLab