Description Usage Arguments Value Author(s) Examples
This routine use the GMRFLib implementation which compute parts of the inverse of a SPD sparse matrix. The diagonal and values for the neighbours in the inverse, are provided.
1 2 | inla.qinv(Q, constr, reordering = inla.reorderings())
|
Q |
A SPD matrix, either as a (dense) matrix, sparseMatrix, or
a (ascii-)filename with entries in the following format |
constr |
Optional linear constraints; see |
reordering |
The type of reordering algorithm to be used; either one of the names listed in |
inla.qinv
returns a sparseMatrix
of type dgTMatrix
with the
diagonal and values for the neigbours in the inverse. Note that the full inverse is NOT provided!
Havard Rue hrue@math.ntnu.no
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ## dense matrix example
n = 10
A = matrix(runif(n^2), n, n)
Q = A %*% t(A)
print(mean(abs(inla.qinv(Q) - solve(Q))))
## sparse matrix example
rho = 0.9
Q = toeplitz(c(1+rho^2, -rho, rep(0, n-3), -rho)) / (1-rho^2)
Q = inla.as.dgTMatrix(Q)
Q.inv = inla.qinv(Q)
## compute the marginal variances as a vector from a precision matrix
marginal.variances = diag(inla.qinv(Q))
## read the sparse matrix from a file in the 'i, j, value' format
filename = INLA:::inla.tempfile()
write(t(cbind(Q@i+1L, Q@j+1L, Q@x)), ncol=3, file=filename)
Qinv = inla.qinv(filename)
unlink(filename)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.