merge.inla {INLA} | R Documentation

## Merge a mixture of `inla`-objects

### Description

The function `merge.inla` implements method `merge` for `inla`-objects. `merge.inla` is a wrapper for the function `inla.merge`. The interface is slightly different, `merge.inla` is more tailored for interactive use, whereas `inla.merge` is better in general code.

`inla.merge` is intented for merging a mixture of `inla`-objects, each run with the same formula and settings, except for a set of hyperparameters, or other parameters in the model, that are fixed to different values. Using this function, we can then integrate over these hyperparameters using (unnormalized) integration weights `prob`. The main objects to be merged, are the summary statistics and marginal densities (like for hyperparameters, fixed, random, etc). Not all entries in the object can be merged, and by default these are inheritated from the first object in the list, while some are just set to `NULL`. Those objectes that are merged, will be listed if run with option `verbose=TRUE`.

Note that merging hyperparameter in the user-scale is prone to discretization error in general, so it is more stable to convert the marginal of the hyperparameter from the merged internal scale to the user-scale. (This is not done by this function.)

### Usage

    ## S3 method for class 'inla'
    merge(x, y, ..., prob = rep(1, length(list(x, y, ...))), verbose = FALSE)

    inla.merge(loo, prob = rep(1, length(loo)), mc.cores = NULL, verbose = FALSE)

### Arguments

`x` | An `inla`-object to be merged
`y` | An `inla`-object to be merged
`...` | Additional `inla`-objects to be merged
`prob` | The mixture of (possibly unnormalized) probabilities
`verbose` | Turn on verbose-output or not
`loo` | List of `inla`-objects to be merged
`mc.cores` | The number of cores to use in `parallel::mclapply`. If `is.null(mc.cores)`, then check `getOption("mc.cores")` and `inla.getOption("num.threads")` in that order.

### Value

A merged `inla`-object.

### Author(s)

Havard Rue hrue@r-inla.org

### Examples

     set.seed(123)
     n = 100
     y = rnorm(n)
     y[1:10] = NA
     x = rnorm(n)
     z1 = runif(n)
     z2 = runif(n)*n
     idx = 1:n
     idx2 = 1:n
     lc1 = inla.make.lincomb(idx = c(1, 2, 3))
     names(lc1) = "lc1"
     lc2 = inla.make.lincomb(idx = c(0, 1, 2, 3))
     names(lc2) = "lc2"
     lc3 = inla.make.lincomb(idx = c(0, 0, 1, 2, 3))
     names(lc3) = "lc3"
     lc = c(lc1, lc2, lc3)
     rr = list()
     for (logprec in c(0, 1, 2))
         rr[[length(rr)+1]] = inla(y ~ 1 + x + f(idx, z1) + f(idx2, z2),
                  lincomb = lc,
                  control.family = list(hyper = list(prec = list(initial = logprec))),
                  control.predictor = list(compute = TRUE, link = 1),
                  data = data.frame(y, x, idx, idx2, z1, z2))
     r = inla.merge(rr, prob = seq_along(rr), verbose=TRUE)
     summary(r)

[Package INLA version 26.02.05 Index]