Learn R Programming

varycoef (version 0.2.9)

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

Description

Prediction of SVC (and response variable)

Usage

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

Arguments

object

output of SVC_mle

newlocs

matrix of dimension n' x 2. These are the new locations the SVCs are predicted for. If NULL, the locations from the SVC_mle (i.e. locs) are considered.

newX

optional matrix of dimension n' x pX. If provided, besides the predicted SVC, the function also returns the predicted response variable.

newW

optional matrix of dimension n' x pW.

compute.y.var

logical. If y will be estimated and TRUE, the standard deviation of each estimate will be computed.

...

further arguments

Value

returns a data frame of n' rows and with columns

  • SVC_1, ..., SVC_p, i.e. 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

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),
  # 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 = 1)

# new data
X.new <- matrix(rnorm(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