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,
...
)
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 2000. 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 = 2000, 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.
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
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")
#> 1 2 3 4 5 6 7
#> 14.6563815 14.6963559 14.8045294 14.0808258 14.1858577 14.5667842 15.0145065
#> 8 9 10 11 12 13 14
#> 14.6297345 14.9009338 15.2402931 15.1355108 15.1875988 15.1627073 14.9902752
#> 15 16 17 18 19 20 21
#> 14.7615680 14.6655120 14.2122319 14.0809766 10.5777507 13.0996798 13.7106117
#> 22 23 24 25 26 27 28
#> 9.1798694 3.8625882 6.8631036 13.1910592 13.8704178 11.4421093 12.1914869
#> 29 30 31 32 33 34 35
#> 11.9059944 10.2075486 10.4876498 10.7563715 9.7136328 9.2602313 10.2477095
#> 36 37 38 39 40 41 42
#> 11.1327979 12.4559124 12.4129502 13.7980889 13.5323743 12.9587195 13.2053219
#> 43 44 45 46 47 48 49
#> 12.2647206 12.5451214 10.5334812 10.8185903 11.1379170 7.7356815 8.5300384
#> 50 51 52 53 54 55 56
#> 9.6657132 12.1276515 11.7448118 11.0619591 11.5867648 11.8614135 12.1651404
#> 57 58 59 60 61 62 63
#> 11.1660976 9.7461962 7.6051681 8.4940758 9.5695913 7.4720775 10.3052974
#> 64 65 66 67 68 69 70
#> 10.8934126 10.2716308 11.4632367 11.6943370 9.5595283 10.2041277 10.7122002
#> 71 72 73 74 75 76 77
#> 14.4973491 14.0748939 14.2079722 8.9680246 11.6946555 13.2951523 8.5007739
#> 78 79 80 81 82 83 84
#> 13.6894328 14.6807917 14.8873005 12.2498400 13.2731761 13.9552643 14.2619799
#> 85 86 87 88 89 90 91
#> 8.7029556 7.8742831 8.7757780 8.4003990 11.0899999 9.1269008 10.0760823
#> 92 93 94 95 96 97 98
#> -0.3864082 4.2490631 6.3251551 7.9575862 2.5376779 0.9631321 6.9393960
#> 99 100 101 102 103 104 105
#> 8.5366536 6.4191929 -3.3142339 -0.2880692 2.8745096 5.6957589 7.3225656
#> 106 107 108 109 110 111 112
#> 5.7764329 8.5758955 1.5118142 3.5878501 8.6968251 14.4646670 13.3400039
#> 113 114 115 116 117 118 119
#> 8.0509565 10.7070108 14.8419069 12.8760912 14.2394533 4.4802227 7.2513351
#> 120 121 122 123 124 125 126
#> 9.5447586 5.8262213 8.9258430 10.8651879 10.5039605 13.2731116 14.9161932
#> 127 128 129 130 131 132 133
#> 12.8312424 6.3336288 9.5137927 4.3386584 8.0150939 11.1795926 8.1475599
#> 134 135 136 137 138 139 140
#> 10.5660098 14.1260092 14.3295653 8.9033099 10.0699457 8.1529409 -4.3851596
#> 141 142 143 144 145 146 147
#> -0.1195973 4.3848365 7.4560414 10.8684912 13.2572061 5.5645821 9.1107947
#> 148 149 150 151 152 153 154
#> 11.5308779 3.9613491 10.4769224 -2.9452086 12.1802353 7.5331144 10.8708259
#> 155 156 157 158 159 160 161
#> 10.4096884 5.1723903 8.8549716 10.0791094 10.6195587 10.8187203 11.0860880
#> 162 163 164 165 166 167 168
#> 3.2295281 10.2763951 10.7490625 11.3581890 11.7284046 7.7797240 7.9294044
#> 169 170 171 172 173 174 175
#> 3.9415182 11.1746028 0.6856936 5.8826486 6.5147241 -0.1986592 5.0538075