samp_posts: Creates posterior mean sparse matrix from posteriors

View source: R/basic_functions.R

samp_postsR Documentation

Creates posterior mean sparse matrix from posteriors

Description

This function uses the posterior arguments to create a posterior mean estimate of the Cholesky of the precision matrix. This function creates the Bayesian version of get_mle or its variants. See the mathematical description for details of the methodology.

Usage

samp_posts(posts, NNarray, bayesian = FALSE, uhat = TRUE)

Arguments

posts

a List of the posteriors from get_posts (or get_posts_c); alternatively it can be custom values as long as the sizes match the output from get_posts.

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.

bayesian

a logical flag which defaults to FALSE. This controls if given the posteriors, it obtains the MAP estimate (when FALSE) or samples all non-zero entries of the U matrix (when TRUE).

uhat

a logical flag which defaults to TRUE. If FALSE and bayesian=TRUE, it will output a posterior sample of the data rather than the U matrix. If bayesian=FALSE, it is unused.

Value

Sparse triangular matrix that is the Cholesky of the precision matrix Ω such that

Ω = U U'

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
}
priors <- thetas_to_priors(c(1, 1, 1), 1e3)

posteriors <- get_posts(datum, priors, NNarray)

uhat <- samp_posts(posteriors, NNarray)


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