inla.sample {INLA} | R Documentation

## Generate samples from an approximated posterior of a fitted model

### Description

This function generate samples from an approximated posterior of a fitted model (an inla-object

### Usage

         inla.posterior.sample(n = 1L, result, intern = FALSE, use.improved.mean = TRUE,
                               add.names = TRUE, seed = 0L, num.threads = 1L)

### Arguments

`n` | Number of samples.
`result` | The inla-object, ie the output from an `inla`-call. The `inla`-object must be created with `control.compute=list(config=TRUE)`.
`use.improved.mean` | Logical. If `TRUE` then use the marginal mean values when constructing samples. If `FALSE` then use the mean in the Gaussian approximations.
`intern` | Logical. If `TRUE` then produce samples in the internal scale for the hyperparmater, if `FALSE` then produce samples in the user-scale. (For example log-precision (intern) and precision (user-scale))
`add.names` | Logical. If `TRUE` then add name for each elements of each sample. If `FALSE`, only add name for the first sample. (This save space.)
`seed` | Control the RNG of `inla.qsample`, see `?inla.qsample` for further information. If `seed=0L` then GMRFLib will set the seed intelligently/at 'random'. If `seed < 0L` then the saved state of the RNG will be reused if possible, otherwise, GMRFLib will set the seed intelligently/at 'random'. If `seed > 0L` then this value is used as the seed for the RNG. If you want reproducible results, you ALSO need to control the seed for the RNG in R by controlling the variable `.Random.seed` or using the function `set.seed`, the example for how this can be done.
`num.threads` | The number of threads that can be used. `num.threads>1L` requires `seed = 0L`. Only use `num.threads > 1L` for large problems/number of samples. This option does currently NOT use the default one set by `inla.setOption()`.

### Details

The hyperparameters are sampled from the configurations used to do the numerical integration, hence if you want a higher resolution, you need to to change the `int.stratey` variable and friends. The latent field is sampled from the Gaussian approximation conditioned on the hyperparameters, but with a correction for the mean (default).

### Value

A list of the samples, where each sample is a list with names `hyperpar` and `latent`, and with their marginal densities in `logdens$hyperpar` and `logdens$latent` and the joint density is in `logdens$joint`.

### Author(s)

Havard Rue hrue@r-inla.org

### Examples

      r = inla(y ~ 1 ,data = data.frame(y=rnorm(1)), control.compute = list(config=TRUE))
      samples = inla.posterior.sample(2,r)

      ## reproducible results:
      set.seed(1234)
      inla.seed = as.integer(runif(1)*.Machine$integer.max)
      x = inla.posterior.sample(100, r, seed = inla.seed)
      set.seed(1234)
      xx = inla.posterior.sample(100, r, seed = inla.seed)
      all.equal(x, xx)

[Package INLA version 18.07.12 Index]