qinv.RdThis 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.
inla.qinv(Q, constr, reordering = INLA::inla.reorderings())A SPD matrix, either as a (dense) matrix or sparseMatrix.
Optional linear constraints;
see ?INLA::f and argument extraconstr
The type of reordering algorithm to be used for TAUCS;
either one of the names listed in inla.reorderings()
or the output from inla.qreordering(Q).
The default is "auto" which try several reordering algorithm and use the best one for this particular matrix.
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!
## dense matrix example
n = 10
A = matrix(runif(n^2), n, n)
Q = A %*% t(A)
print(mean(abs(inla.qinv(Q) - solve(Q))))
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'print': error in evaluating the argument 'x' in selecting a method for function 'mean': error in running command
## 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)
#> Error in system(paste(shQuote(inla.call.no.remote()), "-s -m qinv", "-r", reordering, "-t", num.threads, "-S", smtp, qinv.file, constr.file, out.file), intern = TRUE): error in running command
## compute the marginal variances as a vector from a precision matrix
marginal.variances = diag(inla.qinv(Q))
#> Error in (function (cond) .Internal(C_tryCatchHelper(addr, 1L, cond)))(structure(list(message = "error in running command", call = system(paste(shQuote(inla.call.no.remote()), "-s -m qinv", "-r", reordering, "-t", num.threads, "-S", smtp, qinv.file, constr.file, out.file), intern = TRUE), cmd = "'/home/abdulfe/Documents/sites/inlasite/r-inla/rinla/inst/bin/linux/64bit/inla.run' -s -m qinv -r auto -t 2 -S default /tmp/RtmpB7Z7ym/file9c6e703ebb66/file9c6e24a90160 /tmp/RtmpB7Z7ym/file9c6e703ebb66/file9c6efdcfeeb /tmp/RtmpB7Z7ym/file9c6e703ebb66/file9c6e54230c54"), class = c("cmdError", "error", "condition"))): error in evaluating the argument 'x' in selecting a method for function 'diag': error in running command
## 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)
#> Error in system(paste(shQuote(inla.call.no.remote()), "-s -m qinv", "-r", reordering, "-t", num.threads, "-S", smtp, qinv.file, constr.file, out.file), intern = TRUE): error in running command
unlink(filename)