Predicted values and intervals based on a fitted model object.
# S3 method for ssn_lm
predict(
object,
newdata,
se.fit = FALSE,
scale = NULL,
df = Inf,
interval = c("none", "confidence", "prediction"),
level = 0.95,
type = c("response", "terms"),
block = FALSE,
local,
terms = NULL,
na.action = na.fail,
...
)# S3 method for ssn_glm
predict(
object,
newdata,
type = c("link", "response", "terms"),
se.fit = FALSE,
interval = c("none", "confidence", "prediction"),
level = 0.95,
dispersion = NULL,
terms = NULL,
local,
var_correct = TRUE,
newdata_size,
na.action = na.fail,
...
)
If se.fit is FALSE, predict.ssn() returns
a vector of predictions or a matrix of predictions with column names
fit, lwr, and upr if interval is "confidence"
or "prediction". If se.fit is TRUE, a list with the following components is returned:
fit: vector or matrix as above
se.fit: standard error of each fit
A fitted model object from ssn_lm() or ssn_glm().
A character vector that indicates the name of the prediction data set
for which predictions are desired (accessible via object$ssn.object$preds).
Note that the prediction data must be in the original SSN object used to fit the model.
If newdata is omitted, predictions
for all prediction data sets are returned. Note that the name ".missing"
indicates the prediction data set that contains the missing observations in the data used
to fit the model.
A logical indicating if standard errors are returned.
The default is FALSE.
A numeric constant by which to scale the regular standard errors and intervals.
Similar to but slightly different than scale for stats::predict.lm(), because
predictions form a spatial model may have different residual variances for each
observation in newdata. The default is NULL, which returns
the regular standard errors and intervals.
Degrees of freedom to use for confidence or prediction intervals
(ignored if scale is not specified). The default is Inf.
Type of interval calculation. The default is "none".
Other options are "confidence" (for confidence intervals) and
"prediction" (for prediction intervals).
Tolerance/confidence level. The default is 0.95.
The scale (response or link) of predictions obtained
using ssn_glm objects.
A logical indicating whether a block prediction over the entire
region in newdata should be returned. The default is FALSE, which returns point
predictions for each location in newdata. Currently only available for
model fit using ssn_lm() or models fit using ssn_glm() where
family is "gaussian".
A optional logical or list controlling the big data approximation. If omitted, local
is set to TRUE or FALSE based on the observed data sample size (i.e., sample size of the fitted
model object) -- if the sample size exceeds 10,000, local is
set to TRUE, otherwise it is set to FALSE. This default behavior
occurs because main computational
burden of the big data approximation depends almost exclusively on the
observed data sample size, not the number of predictions desired
(which we feel is not intuitive at first glance).
If local is FALSE, no big data approximation
is implemented. If a list is provided, the following arguments detail the big
data approximation:
method: The big data approximation method. If method = "all",
all observations are used and size is ignored.
If method = "covariance", the size data observations
having the average highest covariance with the prediction locations are used.
The default
is "covariance". Only used with models fit using ssn_lm().
size: The number of data observations to use when method
is "distance" or "covariance". The default is 4000. Only used
with models fit using ssn_lm().
parallel: If TRUE, parallel processing via the
parallel package is automatically used. This can significantly speed
up computations even when method = "all" (i.e., no big data
approximation is used), as predictions
are spread out over multiple cores. The default is FALSE.
ncores: If parallel = TRUE, the number of cores to
parallelize over. The default is the number of available cores on your machine.
When local is a list, at least one list element must be provided to
initialize default arguments for the other list elements.
If local is TRUE, defaults for local are chosen such
that local is transformed into
list(size = 4000, method = "covariance", parallel = FALSE).
If type is "terms", the type of terms to be returned,
specified via either numeric position or name. The default is all terms are included.
Missing (NA) values in newdata will return an error and should
be removed before proceeding.
Other arguments. Not used (needed for generic consistency).
The dispersion of assumed when computing the prediction standard errors
for ssn_glm() model objects when family
is "nbinomial", "beta", "Gamma", or "inverse.gaussian".
If omitted, the model object dispersion parameter is used.
A logical indicating whether to return the corrected prediction
variances when predicting via models fit using ssn_glm. The default is
TRUE.
The size value for each observation in newdata
used when predicting for the binomial family.
The (empirical) best linear unbiased predictions (i.e., Kriging
predictions) at each site are returned when interval is "none"
or "prediction" alongside standard errors. Prediction intervals
are also returned if interval is "prediction". When
interval is "confidence", the estimated mean is returned
alongside standard errors and confidence intervals for the mean.
# Copy the mf04p .ssn data to a local directory and read it into R
# When modeling with your .ssn object, you will load it using the relevant
# path to the .ssn data on your machine
copy_lsn_to_temp()
temp_path <- paste0(tempdir(), "/MiddleFork04.ssn")
mf04p <- ssn_import(temp_path, predpts = "pred1km", overwrite = TRUE)
ssn_mod <- ssn_lm(
formula = Summer_mn ~ ELEV_DEM,
ssn.object = mf04p,
tailup_type = "exponential",
additive = "afvArea"
)
predict(ssn_mod, "pred1km")
Run the code above in your browser using DataLab