get_posts: Gets posteriors of Bayesian methodology

View source: R/basic_functions.R

get_postsR Documentation

Gets posteriors of Bayesian methodology

Description

Given the priors calculated using thetas_to_priors, this function calculates the posterior distributions of the regression errors and coefficients.

Usage

get_posts(datum, priors, NNarray)

Arguments

datum

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

priors

a list of length 3 containing the priors for the shape of the IG prior, the scale of the IG prior, and the prior variances of the coefficients (i.e. the output from thetas_to_priors)

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 > m, as it will be reduced to match the size of the matrix g, but never have m2 < 2.

Value

List of posterior arguments, where

the first element is a vector of length n containing the posterior of the IG shape parameters,

the second element is a vector of length n containing the posteriors of the IG scale parameters,

the third element is an n * m matrix, where each row contains the posterior mean of the regression coefficients (and if there are less than m, NAs fill the rest of the row),

the last element is an m * m \* n array, where each of the n slices contains the posterior variances of the regression coefficients (and if there are less than m, NAs fill the rest of the slice)

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)


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