inla-objectsmerge.RdThe 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.)
An inla-object to be merged
An inla-object to be merged
Additional inla-objects to be merged
The mixture of (possibly unnormalized) probabilities
Turn on verbose-output or not
List of inla-objects to be merged
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.
A merged inla-object.
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)
#> Warning: This function is experimental.
#> inla.merge: Enter with prob = [ 0.167 0.333 0.5 ], and 3 models
#> inla.merge: Merge '$marginals.hyperpar'
#> inla.merge: Merge '$marginals.fixed'
#> inla.merge: Merge '$marginals.lincomb'
#> inla.merge: Merge '$marginals.lincomb.derived'
#> inla.merge: Merge '$marginals.linear.predictor'
#> inla.merge: Merge '$internal.marginals.hyperpar'
#> inla.merge: Merge '$marginals.random'
#> inla.merge: '$marginals.random$idx'
#> inla.merge: '$index.1index.2index.3index.4index.5index.6index.7index.8index.9index.10index.11index.12index.13index.14index.15index.16index.17index.18index.19index.20index.21index.22index.23index.24index.25index.26index.27index.28index.29index.30index.31index.32index.33index.34index.35index.36index.37index.38index.39index.40index.41index.42index.43index.44index.45index.46index.47index.48index.49index.50index.51index.52index.53index.54index.55index.56index.57index.58index.59index.60index.61index.62index.63index.64index.65index.66index.67index.68index.69index.70index.71index.72index.73index.74index.75index.76index.77index.78index.79index.80index.81index.82index.83index.84index.85index.86index.87index.88index.89index.90index.91index.92index.93index.94index.95index.96index.97index.98index.99index.100$idx2'
#> inla.merge: Merge '$marginals.spde2.blc'
#> inla.merge: Merge '$marginals.spde3.blc'
#> inla.merge: Merge '$summary.hyperpar'
#> inla.merge: Merge '$summary.fixed'
#> inla.merge: Merge '$summary.lincomb'
#> inla.merge: Merge '$summary.lincomb.derived'
#> inla.merge: Merge '$summary.linear.predictor'
#> inla.merge: Merge '$internal.summary.hyperpar'
#> inla.merge: Merge '$cpo'
#> Warning: Merging 'cpo' and 'pit'-results are/can be, approximate only
#> inla.merge: Merge '$po'
#> inla.merge: '$summary.random$idx'
#> inla.merge: '$summary.random$idx2'
#> inla.merge: Merge '$misc$nfunc
#> inla.merge: Merge '$cpu.used
#> inla.merge: Merge '$logfile
#> inla.merge: Merge '$joint.hyper
#> inla.merge: Remove '$marginals.fitted.values'
#> inla.merge: Remove '$summary.fitted.values'
#> inla.merge: Remove '$dic'
#> inla.merge: Remove '$waic'
#> inla.merge: Remove '$neffp'
#> inla.merge: Remove '$mode'
#> inla.merge: Remove '$.args'
#> inla.merge: Remove '$model.matrix'
#> inla.merge: Remove '$misc$cov.intern'
#> inla.merge: Remove '$misc$cov.intern.eigenvalues'
#> inla.merge: Remove '$misc$cov.intern.eigenvectors'
#> inla.merge: Remove '$misc$lincomb.derived.correlation.matrix'
#> inla.merge: Remove '$misc$lincomb.derived.covariance.matrix'
#> inla.merge: Remove '$misc$log.posterior.mode'
#> inla.merge: Remove '$misc$stdev.corr.negative'
#> inla.merge: Remove '$misc$stdev.corr.negative'
#> inla.merge: Remove '$misc$stdev.corr.positive'
#> inla.merge: Remove '$misc$theta.mode'
summary(r)
#> Time used:
#> Pre = 0.45, Running = 0.55, Post = 0.0621, Total = 1.06
#> Fixed effects:
#> mean sd
#> (Intercept) 0.112 0.097
#> x -0.096 0.097
#>
#> Linear combinations (derived):
#> mean sd ID
#> lc1 0 0.04 1
#> lc2 0 0.04 2
#> lc3 0 0.04 3
#>
#> Random effects:
#> Name Model
#> idx IID model
#> idx2 IID model
#>
#> Model hyperparameters:
#> mean sd
#> Precision for the Gaussian observations 1.55 0.35
#> Precision for idx 22041.24 24167.65
#> Precision for idx2 29630.03 24075.00
#>
#> Marginal log-Likelihood: -136.52
#> is computed
#> Posterior summaries for the linear predictor and the fitted values are computed
#> (Posterior marginals needs also 'control.compute=list(return.marginals.predictor=TRUE)')
#>