updateGMRF | R Documentation |
Computes the posterior Gaussian distribution given the (mixed) design and precision matrices.
updateGMRF(y, Qe, A, Qx)
y |
the outcome |
Qe |
the error precision matrix |
A |
the design matrix |
Qx |
the prior precision matrix for the latent random (Markov) random field |
## Consider the Orange dataset
## intercept plus linear trend over age with
## additional trend for each tree j
## y_ij = a0 + b0*age_ij + b_j age_ij + e_ij
y <- Orange$circumference
z0 <- model.matrix(~Tree-1, Orange)
A <- cbind(1, Orange$age, z0*Orange$age)
Qx <- Diagonal(7, c(0,0.001, rep(2843.56, 5)))
Qe <- Diagonal(nrow(Orange), 0.010493)
up <- updateGMRF(y, Qe, A, Qx)
cbind(x=up$mu, sd=sqrt(diag(solve(up$Q))))
## Not run:
## compare with INLA
library(INLA)
ff <- circumference ~ age +
f(Tree, age, model='iid')
res <- inla(ff, data=Orange,
control.inla=list(int.strategy='eb'))
res$summary.fixed[, 1:2]
res$summary.random$Tree[, 1:3]
round(exp(res$mode$theta), 6)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.