Predicted values and intervals based on a fitted model object.
Usage
# S3 method for ssn_lm
predict(
object,
newdata,
se.fit = FALSE,
interval = c("none", "confidence", "prediction"),
level = 0.95,
block = FALSE,
...
)
# S3 method for ssn_glm
predict(
object,
newdata,
type = c("link", "response"),
se.fit = FALSE,
interval = c("none", "confidence", "prediction"),
newdata_size,
level = 0.95,
var_correct = TRUE,
...
)
Arguments
- object
- newdata
A character vector that indicates the name of the prediction data set in the SSN object for which predictions are desired. If 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.- se.fit
A logical indicating if standard errors are returned. The default is
FALSE
.- interval
Type of interval calculation. The default is
"none"
. Other options are"confidence"
(for confidence intervals) and"prediction"
(for prediction intervals).- level
Tolerance/confidence level. The default is
0.95
.- block
A logical indicating whether a block prediction over the entire region in
newdata
should be returned. The default isFALSE
, which returns point predictions for each location innewdata
. Currently only available for model fit usingssn_lm()
or models fit usingssn_glm()
wherefamily
is"gaussian"
.- ...
Other arguments. Not used (needed for generic consistency).
- type
The scale (
response
orlink
) of predictions obtained usingssn_glm
objects.- newdata_size
The
size
value for each observation innewdata
used when predicting for the binomial family.- var_correct
A logical indicating whether to return the corrected prediction variances when predicting via models fit using
ssn_glm
. The default isTRUE
.
Value
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 abovese.fit:
standard error of each fit
Details
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.
Examples
# 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.6443346 15.0150979 14.7513549 14.9717229 15.1513874 15.1159790 15.1069520
#> 8 9 10 11 12 13 14
#> 14.9863186 14.9038332 14.8702627 14.7308979 14.6992062 14.7579446 14.8764063
#> 15 16 17 18 19 20 21
#> 14.3287719 14.4149823 14.0532325 13.9397314 10.9750633 13.1067606 13.6244111
#> 22 23 24 25 26 27 28
#> 10.0996588 5.6054226 8.1409677 12.9269053 13.5019980 11.3419554 11.9747664
#> 29 30 31 32 33 34 35
#> 11.2154309 10.2149138 10.4816809 10.7348106 9.7103402 11.3759625 12.2120558
#> 36 37 38 39 40 41 42
#> 12.9616826 12.5664805 12.3028149 13.8079249 13.5395082 12.9715817 13.2152150
#> 43 44 45 46 47 48 49
#> 12.3273384 12.5850380 10.7406072 10.9713095 11.2308341 8.6629974 9.3260313
#> 50 51 52 53 54 55 56
#> 10.2772878 12.1296929 11.7154947 11.1310275 11.5790357 11.7855844 12.0521877
#> 57 58 59 60 61 62 63
#> 11.2655590 9.7898915 8.0483307 8.7966695 9.1037886 8.5118636 11.4956913
#> 64 65 66 67 68 69 70
#> 11.9862160 11.6161901 12.6246359 12.4406987 10.6278901 11.1747555 11.6063313
#> 71 72 73 74 75 76 77
#> 13.9269581 14.4813989 14.5959969 10.1604842 12.4655751 13.8195311 10.1977736
#> 78 79 80 81 82 83 84
#> 14.5789082 15.4149064 15.5879931 13.6734603 14.5383442 15.1150059 15.3746230
#> 85 86 87 88 89 90 91
#> 10.0788306 7.9453413 8.7202052 7.5438136 11.1468478 9.4793850 10.2847461
#> 92 93 94 95 96 97 98
#> 1.5531965 5.4715321 7.2281978 8.6101730 5.0354923 11.3558953 11.7586313
#> 99 100 101 102 103 104 105
#> 12.2766556 12.5929234 9.8923651 9.3683314 6.6259182 12.7363403 4.3346894
#> 106 107 108 109 110 111 112
#> 3.8724173 3.5215224 7.0452774 8.3977344 7.1561650 -1.1426926 1.4202968
#> 113 114 115 116 117 118 119
#> 4.0985733 6.4886255 7.8698972 7.5852381 9.9485049 3.7673801 5.5245583
#> 120 121 122 123 124 125 126
#> 8.5264446 15.2798374 14.2197123 9.2990140 11.5461684 15.5970950 14.1134907
#> 127 128 129 130 131 132 133
#> 15.2664073 6.0647130 8.3993355 10.3304465 8.0105836 10.6329256 12.2753107
#> 134 135 136 137 138 139 140
#> 12.3778096 14.7132922 16.0976413 14.2078071 9.4203169 12.1022897 5.5831669
#> 141 142 143 144 145 146 147
#> 8.6941805 11.3728589 9.3402885 11.3857715 15.1158602 15.2888149 11.5265537
#> 148 149 150 151 152 153 154
#> 12.5079422 10.3691975 -0.6748125 2.9279685 6.7325051 9.3265074 12.2087322
#> 155 156 157 158 159 160 161
#> 14.2262895 7.5221930 10.5192746 12.5652217 6.8460851 12.3513293 1.0470183
#> 162 163 164 165 166 167 168
#> 12.9732758 8.9524078 11.7760066 11.4752712 7.9069483 11.0199167 11.3624102
#> 169 170 171 172 173 174 175
#> 11.8228944 11.9951556 12.2250606 8.7431663 9.2898993 2.3113801 6.7492847