minus_loglikeli: Calculates the integrated log likelihood

View source: R/basic_functions.R

minus_loglikeliR Documentation

Calculates the integrated log likelihood

Description

Given the three hyperparameters, this calculates the negative of the integrated log-likelihood. See the mathematical description for further explanation as needed. It is advised to use the C++ version minus_loglikeli_c to improve speed considerably. This function is often used with an optimizer or MCMC method to find the optimal hyperparameters.

Usage

minus_loglikeli(thetas, datum, NNarray, threshh = 0.001, negativ = TRUE)

Arguments

thetas

3 real numbers representing the three hyperparameters; as it is on the log scale, it should generally be between -6 and 4 to avoid numerical issues (overflow or underflow)

datum

an N * n matrix of the data (N replications of n locations/variables)

NNarray

an n * m2 integer matrix giving the m nearest neighbors previous in the ordering (or outputting NAs if not available [i.e. there are not m previous points]) that are ordered from closest to furthest away. It is OK to have m2 large, as it will be reduced to match the size of the posterior means (i.e. number of columns in the third element of the posteriors), but never have m2 < 2.

threshh

threshold for number of neighbors (for thetas_to_priors); defaults to 1e-3

negativ

logical defaulting to true; if false, the positive log-likelihood is returned

Value

a numeric value (the negative log likelihood)

Examples


#create fake data and fake neighbor matrix
datum <- matrix(rnorm(1e4), nrow = 10)
NNarray <- matrix(NA, nrow = 1e3, ncol = 100)
#can only use previous points in ordering (this is actually 
#impossible in low dimensional space like this is designed for)
for(i in 1:100){
  NNarray[(i + 1):1e3, i] <- i
}

#calculates log likelihood
minus_loglikeli(c(1, 1, 1), datum, NNarray)



katzfuss-group/NPvecchia documentation built on April 15, 2022, 2:23 a.m.