Learn R Programming

SpatioTemporal (version 1.1.2)

loglikeST: Compute the Log-likelihood for the Spatio-Temporal Model

Description

Computes the log-likelihood for the spatio-temporal model. loglikeST uses an optimised version of the log-likelihood, while loglikeSTnaive uses the naive (slow) version and is included mainly for testing and speed checks.

Usage

loglikeST(x = NULL, STmodel, type = "p", x.fixed = NULL)

loglikeSTnaive(x = NULL, STmodel, type = "p", x.fixed = NULL)

Arguments

x
Point at which to compute the log-likelihood, should be only log-covariance parameters if type=c("p","r") and regression parameters followed by log-covariance parameters if type="f". If x=NULL
STmodel
STmodel object with the model for which to compute the log-likelihood.
type
A single character indicating the type of log-likelihood to compute. Valid options are "f", "p", and "r", for full, profile or restricted maximum likelihood (REML).
x.fixed
Parameters to keep fixed, NA values in this vector is replaced by values from x and the result is used as x, ie. x.fixed[ is.na(x.fixed) ] <- x x <- x.fixed.

Value

  • Returns the log-likelihood of the spatio temporal model.

Warning

loglikeSTnaive may take long to run. However for some problems with many locations and short time series loglikeSTnaive could be faster than loglikeST.

See Also

Other likelihood functions: loglikeSTGrad, loglikeSTHessian, loglikeSTnaiveGrad, loglikeSTnaiveHessian

Other STmodel functions: createCV, createDataMatrix, createSTmodel, dropObservations, loglikeSTdim, predictNaive, processLocation, processLUR, processST, updateCovf

Examples

Run this code
##load the data
data(mesa.model)

##Compute dimensions for the data structure
dim <- loglikeSTdim(mesa.model)

##Find out in which order parameters should be given
loglikeST(NULL, mesa.model)

##Let's create random vectors of values
x <- runif( dim$nparam.cov )
x.all <- runif( dim$nparam )

##Evaluate the log-likelihood for these values
loglikeST(x.all, mesa.model, "f")
loglikeST(x, mesa.model, "p")
loglikeST(x, mesa.model, "r")

##check that profile and full give the same results
  data(est.mesa.model)
  x.all <- coef(est.mesa.model)$par
  x <- coef(est.mesa.model, "cov")$par
  if( abs(loglikeST(x.all, mesa.model, "f") -
          loglikeST(x, mesa.model, "p")) > 1e-8 ){
    stop("loglike: full and profile not equal")
  }

Run the code above in your browser using DataLab