Calculate MLE's of model parameters and perform spatial prediction.
# S4 method for missing,ANY,ANY,ANY
lgm(
formula, data, grid, covariates,
buffer=0, shape=1, boxcox=1, nugget = 0,
expPred=FALSE, nuggetInPrediction=TRUE,
reml=TRUE,mc.cores=1,
aniso=FALSE,
fixShape=TRUE,
fixBoxcox=TRUE,
fixNugget = FALSE,
...)
# S4 method for numeric,ANY,ANY,ANY
lgm(
formula, data, grid, covariates,
buffer=0, shape=1, boxcox=1, nugget = 0,
expPred=FALSE, nuggetInPrediction=TRUE,
reml=TRUE,mc.cores=1,
aniso=FALSE,
fixShape=TRUE,
fixBoxcox=TRUE,
fixNugget = FALSE,
...)
# S4 method for character,ANY,ANY,ANY
lgm(
formula, data, grid, covariates,
buffer=0, shape=1, boxcox=1, nugget = 0,
expPred=FALSE, nuggetInPrediction=TRUE,
reml=TRUE,mc.cores=1,
aniso=FALSE,
fixShape=TRUE,
fixBoxcox=TRUE,
fixNugget = FALSE,
...)
# S4 method for formula,SpatVector,numeric,ANY
lgm(
formula, data, grid, covariates,
buffer=0, shape=1, boxcox=1, nugget = 0,
expPred=FALSE, nuggetInPrediction=TRUE,
reml=TRUE,mc.cores=1,
aniso=FALSE,
fixShape=TRUE,
fixBoxcox=TRUE,
fixNugget = FALSE,
...)
# S4 method for formula,SpatVector,SpatRaster,missing
lgm(
formula, data, grid, covariates,
buffer=0, shape=1, boxcox=1, nugget = 0,
expPred=FALSE, nuggetInPrediction=TRUE,
reml=TRUE,mc.cores=1,
aniso=FALSE,
fixShape=TRUE,
fixBoxcox=TRUE,
fixNugget = FALSE,
...)
# S4 method for formula,SpatVector,SpatRaster,list
lgm(
formula, data, grid, covariates,
buffer=0, shape=1, boxcox=1, nugget = 0,
expPred=FALSE, nuggetInPrediction=TRUE,
reml=TRUE,mc.cores=1,
aniso=FALSE,
fixShape=TRUE,
fixBoxcox=TRUE,
fixNugget = FALSE,
...)
# S4 method for formula,SpatVector,SpatRaster,SpatRaster
lgm(
formula, data, grid, covariates,
buffer=0, shape=1, boxcox=1, nugget = 0,
expPred=FALSE, nuggetInPrediction=TRUE,
reml=TRUE,mc.cores=1,
aniso=FALSE,
fixShape=TRUE,
fixBoxcox=TRUE,
fixNugget = FALSE,
...)
# S4 method for formula,SpatVector,SpatRaster,data.frame
lgm(
formula, data, grid, covariates,
buffer=0, shape=1, boxcox=1, nugget = 0,
expPred=FALSE, nuggetInPrediction=TRUE,
reml=TRUE,mc.cores=1,
aniso=FALSE,
fixShape=TRUE,
fixBoxcox=TRUE,
fixNugget = FALSE,
...)
# S4 method for formula,SpatRaster,ANY,ANY
lgm(
formula, data, grid, covariates,
buffer=0, shape=1, boxcox=1, nugget = 0,
expPred=FALSE, nuggetInPrediction=TRUE,
reml=TRUE,mc.cores=1,
aniso=FALSE,
fixShape=TRUE,
fixBoxcox=TRUE,
fixNugget = FALSE,
...)
# S4 method for formula,data.frame,SpatRaster,data.frame
lgm(
formula, data, grid, covariates,
buffer=0, shape=1, boxcox=1, nugget = 0,
expPred=FALSE, nuggetInPrediction=TRUE,
reml=TRUE,mc.cores=1,
aniso=FALSE,
fixShape=TRUE,
fixBoxcox=TRUE,
fixNugget = FALSE,
...)
A list is returned which includes a SpatRaster
named predict
having layers:
Estimated means from the fixed effects portion of the model
Predicted random effect
Conditional standard deviation of predicted random effect (on the transformed scale if applicable)
Prediction of the response, sum of predicted fixed and random effects. For Box-Cox or log-transformed data on the natural (untransformed) scale.
If exp.pred=TRUE
, the prediction of the logged process.
If a box cox transformation was used, the prediction of the process on the transformed scale.
In addition, the element summery
contains a table of parameter estimates and confidence intervals. optim
contains the
output from the call to the optim
function.
A model formula for the fixed effects, or a character string specifying the response variable.
A SpatVector
or SpatRaster
layer, brick or stack containing the locations and observations, and possibly covariates.
Either a SpatRaster
, or a single integer giving the
number of cells in the X direction which predictions will be made on. If the later
the predictions will be a raster of square cells covering the bounding box of data
.
The spatial covariates used in prediction, either a SpatRaster
stack or list of rasters.
Covariates in formula
but not in data
will be extracted from covariates
.
Order of the Matern correlation
Box-Cox transformation parameter (or vector of parameters), set to 1 for no transformation.
Value for the nugget effect (observation error) variance, or vector of such values.
Should the predictions be exponentiated, defaults to FALSE
.
If TRUE
, predict new observations by adding the
nugget effect. The prediction variances will be adjusted accordingly, and the predictions
on the natural scale for logged or Box Cox transformed data will be affected.
Otherwise predict fitted values.
If TRUE
(the default), use restricted maximum likelihood.
If mc.cores>1
, this argument is passed to mclapply
and computations are
done in parallel where possible.
Set to TRUE
to use geometric anisotropy.
Set to FALSE
to estimate the Matern order
Set to FALSE
to estimate the Box-Cox parameter.
Set to FALSE
to estimate the nugget effect parameter.
Extra distance to add around grid
.
Additional arguments passed to likfitLgm
. Starting values can be
specified with a vector param
of named elements
When data
is a SpatVector
, parameters are estimated using optim
to maximize
the
log-likelihood function computed by likfitLgm
and spatial prediction accomplished with krigeLgm
.
With data
being a Raster
object, a Markov Random Field approximation to the Matern is used (experimental). Parameters to
be estimated should be provided as vectors of possible values, with optimization only considering the parameter values supplied.
likfitLgm
, krigeLgm
data("swissRain")
swissRain = unwrap(swissRain)
swissAltitude = unwrap(swissAltitude)
swissBorder = unwrap(swissBorder)
swissRes = lgm( formula="rain",
data=swissRain[1:60,], grid=20,
covariates=swissAltitude, boxcox=0.5, fixBoxcox=TRUE,
shape=1, fixShape=TRUE,
aniso=FALSE, nugget=0, fixNugget=FALSE,
nuggetInPrediction=FALSE
)
swissRes$summary
plot(swissRes$predict[["predict"]], main="predicted rain")
plot(swissBorder, add=TRUE)
Run the code above in your browser using DataLab