the only failsafe option is to use the marginals in the internal representation,
> r=inla(y~1,data=data.frame(y=0))
> head(str(r$internal.marginals.hyperpar[[1]]))
num [1:43, 1:2] 4.75 4.95 5.13 5.81 6.44 ...
- attr(*, "hyperid")= chr "65001|INLA.Data1"
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:2] "x" "y"
NULL
the `internal.' prefix gives the marginals in the internal scale, which is
log(precision) in your example. for other models it is given in the
documentation.
sampling is done this way
> m = r$internal.marginals.hyperpar[[1]]
> log.prec = inla.rmarginal(1000, m)
> stdev = 1/sqrt(exp(log.prec))
> summary(stdev)
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.002589641 0.006071897 0.008338903 0.011762855 0.013853448 0.089429718
just transform the sample, no need to transform the density as this just gives
further approximation errors.
the deeper reason why you might get negative values in your example, is that the
internal representation for the density does not have constraints, like knowing
that x > 0. the internal representation does not have these contraints, so
you're fine. if your density has mass close to zero this might happen
best
H
> --
> You received this message because you are subscribed to the Google Groups "R-
> inla discussion group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
r-inla-discussion...@googlegroups.com.
> To view this discussion, visit
>
https://groups.google.com/d/msgid/r-inla-discussion-group/23b85d7a-e22e-448e-99f7-c2e4ad351391n%40googlegroups.com
> .
--
Håvard Rue
he...@r-inla.org