pkern_cmean: Compute ordinary kriging predictor (or variance) for data on...

View source: R/pkern_estim.R

pkern_cmeanR Documentation

Compute ordinary kriging predictor (or variance) for data on a grid

Description

Evaluates the ordinary kriging equations in section 3 of Cressie (1993) over the grid defined in g_obs. These are the predicted values minimizing mean squared prediction error under the covariance model specified by pars.

Usage

pkern_cmean(
  g_obs,
  pars,
  X = NA,
  fac = NULL,
  out = "p",
  fac_method = "chol",
  quiet = FALSE
)

Arguments

g_obs

list of form returned by pkern_grid (with entries 'gdim', 'gres', 'gval')

pars

list of form returned by pkern_pars (with entries 'y', 'x', 'eps', 'psill')

X

numeric, vector, matrix, or NA: the mean, or its linear predictors

fac

(optional) pre-computed factorization of covariance matrix scaled by partial sill

out

character, the return value, one of 'predictor', 'variance', or 'm'

quiet

logical indicating to suppress console output

Details

Set makev=TRUE to return the pointwise kriging variance. This takes approximately n_obs times longer to evaluate than makev=FALSE. A progress bar will be printed to console unless quiet=TRUE.

The covariance factorization fac can be pre-computed using pkern_var(..., scaled=TRUE) to speed up repeated calls where only the observed data values change (ie same covariance structure pars, and same NA structure in the data). Note that the kriging variance does not change in this case and only needs to be computed once.

Value

numeric matrix, the predicted values (or their variance)

Examples

# make example grid and data
n = 25^2
n_obs = 10
g_obs = pkern_grid(sqrt(n))
idx_obs = sample.int(n, n_obs)
g_obs$gval[idx_obs] = rnorm(n_obs)
pars = pkern_pars('gau', g_obs)
g_pred = pkern_cmean(g_obs, pars)
g_var = pkern_cmean(g_obs, pars, makev=TRUE, quiet=TRUE)
#g_obs |> pkern_plot()
#g_obs |> modifyList(list(gval=g_pred)) |> pkern_plot()
#g_obs |> modifyList(list(gval=g_var)) |> pkern_plot()


deankoch/pkern documentation built on Oct. 26, 2023, 8:54 p.m.