Learn R Programming

varycoef (version 0.3.0)

predict.SVC_mle: Prediction of SVCs (and response variable)

Description

Prediction of SVCs (and response variable)

Usage

# S3 method for SVC_mle
predict(
  object,
  newlocs = NULL,
  newX = NULL,
  newW = NULL,
  compute.y.var = FALSE,
  ...
)

Arguments

object

(SVC_mle) Model obtained from SVC_mle function call.

newlocs

(NULL or matrix(n.new, 2)) If NULL, then function uses observed locations of model to estimate SVCs. Otherwise, these are the new locations the SVCs are predicted for.

newX

(NULL or matrix(n.new, q)) If provided (together with newW), the function also returns the predicted response variable.

newW

(NULL or matrix(n.new, p)) If provided (together with newX), the function also returns the predicted response variable.

compute.y.var

(logical(1)) If TRUE and the response is being estimated, the predictive variance of each estimate will be computed.

...

further arguments

Value

The function returns a data frame of n.new rows and with columns

  • SVC_1, ..., SVC_p: the predicted SVC at locations newlocs.

  • y.pred, if newX and newW are provided

  • y.var, if newX and newW are provided and compute.y.var is set to TRUE.

  • loc_x, loc_y, the locations of the predictions

References

Dambon, J. A., Sigrist, F., Furrer, R. (2021) Maximum likelihood estimation of spatially varying coefficient models for large data with an application to real estate price prediction, Spatial Statistics 10.1016/j.spasta.2020.100470

See Also

SVC_mle

Examples

Run this code
# NOT RUN {
## ---- toy example ----
## sample data
# setting seed for reproducibility
set.seed(123)
m <- 7
# number of observations
n <- m*m
# number of SVC
p <- 3
# sample data
y <- rnorm(n)
X <- matrix(rnorm(n*p), ncol = p)
# locations on a regular m-by-m-grid
locs <- expand.grid(seq(0, 1, length.out = m),
                    seq(0, 1, length.out = m))

## preparing for maximum likelihood estimation (MLE)
# controls specific to MLE
control <- SVC_mle_control(
  # initial values of optimization
  init = rep(0.1, 2*p+1),
  # lower bound
  lower = rep(1e-6, 2*p+1),
  # using profile likelihood
  profileLik = TRUE
)

# controls specific to optimization procedure, see help(optim)
opt.control <- list(
  # number of iterations (set to one for demonstration sake)
  maxit = 1,
  # tracing information
  trace = 6
)

## starting MLE
fit <- SVC_mle(y = y, X = X, locs = locs,
               control = control,
               optim.control = opt.control)

## output: convergence code equal to 1, since maxit was only 1
summary(fit)

## prediction
# new location
newlocs <- matrix(0.5, ncol = 2, nrow = 2)

# new data
X.new <- matrix(rnorm(2*p), ncol = p)

# predicting SVCs
predict(fit, newlocs = newlocs)

# predicting SVCs and calculating response
predict(fit, newlocs = newlocs,
        newX = X.new, newW = X.new)

# predicting SVCs, calculating response and predictive variance
predict(fit, newlocs = newlocs,
        newX = X.new, newW = X.new,
        compute.y.var = TRUE)

# }

Run the code above in your browser using DataLab