joint.marginal {INLA}R Documentation

Sample, transform and evaluate from a joint marginal approximation

Description

Sample, transform and evalue from from a joint marginal approximation as returned using argument selection in inla.

Usage

 inla.rjmarginal(n, jmarginal, constr)
 inla.rjmarginal.eval(fun, samples, ...)
 inla.tjmarginal(jmarginal, A)
 inla.1djmarginal(jmarginal)
 

Arguments

n

The number of samples

jmarginal

A marginal object given either by a inla object or result$selection

constr

Optional linear constraints; see ?INLA::f and argument extraconstr

fun

A function which is evaluated for each sample, similar to inla.posterior.sample.eval: please see the documentation for this functions for details.

samples

The samples, as in the form of the output from inla.rjmarginal

A

A matrix used for the linear combination

Value

THESE FUNCTIONS ARE EXPERIMENTAL FOR THE MOMENT (JULY 2020)

inla.rjmarginal returns a list with the samples in samples (matrix) and the corresponding log-densities in log.density (vector). Each column in samples contains one sample.

inla.rjmarginal.eval returns a matrix, where each row is the (vector) function evaluated at each sample.

inla.tjmarginal returns a inla.jmarginal-object of the linear combination defined by the matrix A.

inla.1djmarginal return the marginal densities from a joint approximation.

Author(s)

Cristian Chiuchiolo and Havard Rue hrue@r-inla.org

See Also

inla

Examples

 n = 10
 x = 1+rnorm(n)
 xx = 3 + rnorm(n)
 y = 1 + x + xx + rnorm(n)
 selection = list(xx=1, Predictor = 3:4, x=1)
 r = inla(y ~ 1 + x + xx,
          data = data.frame(y, x, xx),
          selection = selection)
 ns = 100
 xx = inla.rjmarginal(ns, r)

 print(cbind(mean = r$selection$mean, sample.mean = rowMeans(xx$samples)))
 print("cov matrix")
 print(round(r$selection$cov.matrix, dig=3))
 print("sample cov matrix")
 print(round(cov(t(xx$samples)), dig=3))

 skew = function(z) mean((z-mean(z))^3)/var(z)^1.5
 print(round(cbind(skew = r$selection$skewness,
                   sample.skew = apply(xx$sample, 1, skew)), dig=3))

 ## illustrating the eval function
 n = 10
 x = rnorm(n)
 eta = 1 + x
 y = eta + rnorm(n, sd=0.1)
 selection = list(x = 1, Predictor = c(1, 2, 4, 5),  '(Intercept)' = 1)
 r = inla(y ~ 1 + x,
          data = data.frame(y, x),
          selection = selection)
 xx = inla.rjmarginal(100,  r)
 xx.eval = inla.rjmarginal.eval(function() c(x, Predictor, Intercept),  xx)
 print(cbind(xx$samples[, 1]))
 print(cbind(xx.eval[, 1]))

 constr <- list(A = matrix(1, ncol = n, nrow = 1), e = 1)
 x <- inla.rjmarginal(10, r, constr = constr)

 A <- matrix(rnorm(n^2), n, n)
 b <- inla.tjmarginal(r, A)
 b.marg <- inla.1djmarginal(b)

[Package INLA version 21.11.22 Index]