marginal.RdDensity, distribution function, quantile function, random
generation, hpd-interval, interpolation, expectations, mode and transformations of
marginals obtained by inla or inla.hyperpar().
These functions computes the density (inla.dmarginal),
the distribution function (inla.pmarginal),
the quantile function (inla.qmarginal),
random generation (inla.rmarginal),
spline smoothing (inla.smarginal),
computes expected values (inla.emarginal),
computes the mode (inla.mmarginal),
transforms the marginal (inla.tmarginal), and provide summary statistics (inla.zmarginal).
inla.dmarginal(x, marginal, log = FALSE)
inla.pmarginal(q, marginal, normalize = TRUE, len = 2048L)
inla.qmarginal(p, marginal, len = 2048L)
inla.rmarginal(n, marginal)
inla.hpdmarginal(p, marginal, len = 2048L)
inla.smarginal(marginal, log = FALSE, extrapolate = 0.0, keep.type = FALSE, factor=15L)
inla.emarginal(fun, marginal, ...)
inla.mmarginal(marginal)
inla.tmarginal(fun, marginal, n=2048L, h.diff = .Machine$double.eps^(1/3),
method = c("quantile", "linear"))
inla.zmarginal(marginal, silent = FALSE)A marginal object from either inla or
inla.hyperpar(), which is either list(x=c(), y=c())
with density values y at locations x, or a
matrix(,n,2) for which the density values are the second
column and the locations in the first column.
Theinla.hpdmarginal()-function
assumes a unimodal density.
A (vectorised) function like function(x) exp(x) to
compute the expectation against, or which define the transformation
new = fun(old)
Evaluation points
Quantiles
Probabilities
The number of observations. If length(n) > 1, the
length is taken to be the number required.
The step-length for the numerical differeniation inside inla.tmarginal
Further arguments to be passed to function which expectation is to be computed.
Return density or interpolated density in log-scale?
Renormalise the density after interpolation?
Number of locations used to interpolate the distribution function.
If FALSE then return a list(x=, y=), otherwise if TRUE,
then return a matrix if the input is a matrix
How much to extrapolate on each side when computing the interpolation. In fraction of the range.
The number of points after interpolation is factor times the original number of points;
which is argument n in spline
Which method should be used to layout points for where the transformation is computed.
Output the result visually (TRUE) or just through the call.
inla.smarginal returns list=c(x=c(), y=c()) of
interpolated values do extrapolation using the factor given,
and the remaining function returns what they say they should do.
inla, inla.hyperpar
## a simple linear regression example
n = 10
x = rnorm(n)
sd = 0.1
y = 1+x + rnorm(n,sd=sd)
res = inla(y ~ 1 + x, data = data.frame(x,y),
control.family=list(initial = log(1/sd^2),fixed=TRUE))
#> Warning: error in running command
#> Error in inla.inlaprogram.has.crashed(): The inla-program exited with an error. Unless you interupted it yourself, please rerun with verbose=TRUE and check the output carefully.
#> If this does not help, please contact the developers at <help@r-inla.org>.
## chose a marginal and compare the with the results computed by the
## inla-program
r = res$summary.fixed["x",]
#> Error: object 'res' not found
m = res$marginals.fixed$x
#> Error: object 'res' not found
## compute the 95% HPD interval
inla.hpdmarginal(0.95, m)
#> Error: object 'm' not found
x = seq(-6, 6, len = 1000)
y = dnorm(x)
inla.hpdmarginal(0.95, list(x=x, y=y))
#> low high
#> level:0.95 -1.962892 1.95703
## compute the the density for exp(r), version 1
r.exp = inla.tmarginal(exp, m)
#> Error: object 'm' not found
## or version 2
r.exp = inla.tmarginal(function(x) exp(x), m)
#> Error: object 'm' not found
## to plot the marginal, we use the inla.smarginal, which interpolates (in
## log-scale). Compare with some samples.
plot(inla.smarginal(m), type="l")
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'plot': object 'm' not found
s = inla.rmarginal(1000, m)
#> Error: object 'm' not found
hist(inla.rmarginal(1000, m), add=TRUE, prob=TRUE)
#> Error: object 'm' not found
lines(density(s), lty=2)
#> Error: object 's' not found
m1 = inla.emarginal(function(x) x^1, m)
#> Error: object 'm' not found
m2 = inla.emarginal(function(x) x^2, m)
#> Error: object 'm' not found
stdev = sqrt(m2 - m1^2)
#> Error: object 'm2' not found
q = inla.qmarginal(c(0.025,0.975), m)
#> Error: object 'm' not found
## inla-program results
print(r)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'print': object 'r' not found
## inla.marginal-results (they shouldn't be perfect!)
print(c(mean=m1, sd=stdev, "0.025quant" = q[1], "0.975quant" = q[2]))
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'print': object 'm1' not found
## using the buildt-in function
inla.zmarginal(m)
#> Error: object 'm' not found