Learn R Programming

SpatioTemporal (version 0.9.2)

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

Description

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

Usage

loglike(x = NA, mesa.data.model, type = "p")

loglike.naive(x = NA, mesa.data.model, type = "p")

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=NA
mesa.data.model
Data structure holding observations, and information regarding which geographic and spatio-temporal covariates to use when fitting the model. See create.data.model and
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). Computation of the full log-likelihood req

Value

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

    If x = NA it returns reasonable parameter names, by calling loglike.var.names(mesa.data.model, all=(type=="f")).

encoding

latin1

Warning

loglike.naive may take long to run. However for some problems with many locations and short time series loglike.naive can be faster than loglike.

See Also

Expected names for x are given by loglike.var.names, with loglike.dim giving number of parameters.

Gradients and Hessian of the log-likelihood are computed by loglike.grad and loglike.hessian. For optimization functions see create.data.model, run.MCMC, fit.mesa.model, and cond.expectation.

Examples

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

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

##Find out in which order parameters should be given
loglike(NA,mesa.data.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
loglike(x.all, mesa.data.model, "f")
loglike(x, mesa.data.model, "p")
loglike(x, mesa.data.model, "r")
##check that profile and full give the same results
data(mesa.data.res)
x.all <- mesa.data.res$par.est$res.best$par.all
x <- mesa.data.res$par.est$res.best$par
if( abs(loglike(x.all, mesa.data.model, "f") -
        loglike(x, mesa.data.model, "p")) > 1e-8 ){
  stop("loglike: full and profile not equal")
}

Run the code above in your browser using DataLab