Learn R Programming

varycoef (version 0.2.9)

SVC_mle: MLE of SVC model

Description

Calls MLE of the SVC model defined as:

$$y(s) = X \mu + W \eta (s) + \epsilon(s)$$

where:

  • y is the response (vector of length n)

  • X is the data matrix for the fixed effects covariates

  • \(\mu\) is the vetor containing the fixed effects

  • W is the data matrix for the SVCs represented by zero mean GRF

  • \(\eta\) are the SVCs represented by zero mean GRF

  • \(\epsilon\) is the nugget effect

The MLE is done by calling the function optim.

Usage

SVC_mle(...)

# S3 method for default SVC_mle(y, X, locs, W = NULL, control = NULL, optim.control = list(), ...)

# S3 method for formula SVC_mle(formula, data, RE_formula = NULL, locs, control, optim.control = list(), ...)

Arguments

...

further arguments

y

numeric response vector of dimension n.

X

matrix of covariates of dimension n x pX. Intercept has to be added manually.

locs

matrix of locations of dimension n X 2. May contain multiple observations at single location which (may) cause a permutation of y, X, W and locs.

W

Optional matrix of covariates with fixed effects, i.e. non-SVC, of dimension n x pW

control

list of control paramaters, usually given by SVC_mle_control

optim.control

list of control arguments for optimization function, see Details in optim

formula

Formula describing the fixed effects in SVC model. The response, i.e. LHS of the formula, is not allowed to have functions such as sqrt() or log().

data

data frame containing the observations

RE_formula

Formula describing the random effects in SVC model. Only RHS is considered. If NULL, the same RHS of argument formula for fixed effects is used.

Value

Object of class SVC_mle

See Also

predict.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)

# }
# NOT RUN {
## ---- real data example ----
require(sp)
## get data set
data("meuse", package = "sp")

# construct data matrix and response, scale locations
y <- log(meuse$cadmium)
X <- model.matrix(~1+dist+lime+elev, data = meuse)
locs <- as.matrix(meuse[, 1:2])/1000


## starting MLE
# the next call takes a couple of seconds
fit <- SVC_mle(y = y, X = X, locs = locs,
               # has 4 fixed effects, but only 3 random effects (SVC)
               # elev is missing in SVC
               W = X[, 1:3],
               control = SVC_mle_control(
                 # inital values for 3 SVC
                 # 7 = (3 * 2 covariance parameters + nugget)
                 init = c(rep(c(0.4, 0.2), 3), 0.2),
                 profileLik = TRUE
               ))

## summary and residual output
summary(fit)
plot(fit)

## predict
# new locations
newlocs <- expand.grid(
  x = seq(min(locs[, 1]), max(locs[, 1]), length.out = 30),
  y = seq(min(locs[, 2]), max(locs[, 2]), length.out = 30))
# predict SVC for new locations
SVC <- predict(fit, newlocs = as.matrix(newlocs))
# visualization
sp.SVC <- SVC
coordinates(sp.SVC) <- ~loc_x+loc_y
spplot(sp.SVC, colorkey = TRUE)
# }

Run the code above in your browser using DataLab