predict.krige {krige} | R Documentation |
Predictions by Kriging
Description
This function uses the results of a model estimated by metropolis.krige
to make kriging-based predictions.
Usage
## S3 method for class 'krige'
predict(object, newdata, credible = FALSE, new.X, new.east, new.north, ...)
Arguments
object |
An |
newdata |
An optional data frame in which to look for variables with which
to predict. If omitted, the fitted values are produced. Alternatively, the new
data can be specified using |
credible |
If a credible interval on predictions is desired, a user may
specify a proportion between 0 and 1 to indicate the interval probability.
For example, a value of 0.9 would create a 90% credible interval. If |
new.X |
The matrix of independent variables for observations to be predicted. |
new.east |
Vector of eastings for observations to be predicted. |
new.north |
Vector of northings for observations to be predicted. |
... |
Additional arguments passed to |
Details
Analysts should use this function if they want to make kriged predictions
for observations at new locations or predict fitted values at original locations.
To do this, researchers first must estimate a model using the metropolis.krige
function.
After estimating the model, a krige
object can provide information from
the model fitted with metropolis.krige
, including the original imput
data, coordinates, and the model results themselves. The prediction will also
use the same powered.exp
. new.data
can be specified for predicting
the observations at new location. Otherwise, the fitted values for the original
data and locations will be produced.
By default, the function uses median values of parameters to make a single point
prediction for every kriged data point. However, if the uses specifies a probability
with the credible
option, then the function will determine the predictions
for all iterations of the MCMC sample. The point estimates will then be a median
of these predictions, and a credible interval will be returned based on percentiles.
Note that estimating a credible interval is substantially more intensive computationally,
but has the benefit of reporting uncertainty in predictions.
Value
An object of class matrix
with one prediction per row. By default
the matrix has one column, as only point predictions are returned. If the credible
option is specified, there are three columns respectively indicating a point
estimate (median prediction from MCMC), lower bound of the credible interval,
and upper bound of the credible interval.
References
Jeff Gill. 2020. Measuring Constituency Ideology Using Bayesian Universal Kriging.
State Politics & Policy Quarterly. doi:10.1177/1532440020930197
Examples
## Not run:
# Summarize Data
summary(ContrivedData)
# Initial OLS model
contrived.ols<-lm(y~x.1+x.2,data=ContrivedData)
# summary(contrived.ols)
# Set seed
set.seed(1241060320)
M <- 100
#M<-10000
contrived.run <- metropolis.krige(y ~ x.1 + x.2, coords = c("s.1","s.2"),
data = ContrivedData, n.iter = M, range.tol = 0.05)
# Predict fitted values
predict(contrived.run)
# Predict new data
euler<-c(0.2,0.7)
archimedes<-c(0.3,0.1)
pythagoras<-c(0.1,0.4)
mathematicians<-rbind(euler,archimedes,pythagoras)
basel<-c(0.1,0.8)
sicily<-c(0.4,0.1)
samos<-c(0.1,0.4)
new.locations<-rbind(basel,sicily,samos)
newDf <- as.data.frame(cbind(mathematicians, new.locations))
colnames(newDf) <- c("x.1", "x.2", "s.1", "s.2")
# Make predictions from median parameter values:
(median.pred <- predict(contrived.run, newdata = newDf))
# Make predictions with 90\
(cred.pred <- predict(contrived.run, newdata = newDf, credible=0.9))
## End(Not run)