Hi!
That would be great!
I have been testing this but been unable to get the observation approach to work in a survival model. It seems to interpret the censoring indicators as well as the observation matrix as observations and complain that the "the number of families 2 does not match number of response variables 6" where my y-variable has dim 2x(N+M) and cens has size 1 x (N + M).
But.
If I may ask a question about the masking implementation of the Dirichlet condition.
In the example code provided earlier (appended below) we make a call to inla.spde2.generic directly. It would be very useful to be able to fix the range and standard deviation to better understand the model behaviour.
In the newer implementation inla.spde.pcmatern this would be done by providing prior.range = c(prior.val, NA) and prior.sigma = c(prior.val, NA).
I have not managed to figure out how to achieve this in the implementation below, but would it be straight-forward?
Best regards,
Michael
```
library(INLA)
dirichlet.mask <- function(mesh)
{
mask <- rep(TRUE, mesh$n)
mask[unique(mesh$segm$bnd$idx)] <- FALSE
mask
}
dirichlet.fem <- function(mesh, order=2)
{
output <- c("c0", "c1",
paste("k", seq_len(order), sep = ""))
fem <- inla.fmesher.smorg(mesh$loc, mesh$graph$tv, fem = order,
output = output)
mask <- dirichlet.mask(mesh)
fem$c0 <- fem$c0[mask,mask,drop=FALSE]
fem$c1 <- fem$c1[mask,mask,drop=FALSE]
for (idx in seq_len(order)) {
fem[[paste("g", idx, sep = "")]] <-
fem[[paste("k", idx, sep = "")]][mask,mask,drop=FALSE]
}
fem
}
matern.dirichlet <- function(mesh, B.tau, B.kappa,
theta.mu=rep(0, ncol(B.tau)-1),
theta.Q=diag(ncol(B.tau)-1))
{
fem <- dirichlet.fem(mesh)
inla.spde2.generic(M0=fem$c0, M1=fem$g1, M2=fem$g2,
B0=B.tau, B1=2*B.kappa,
B2=cbind(1, B.tau[,-1,drop=FALSE]*0.0),
theta.mu=
theta.mu, theta.Q=theta.Q,
transform="identity")
}
dirichlet.A <- function(mesh, ...)
{
A <- inla.spde.make.A(mesh, ...)
A[, dirichlet.mask(mesh), drop=FALSE]
}
########################################################################
prior.sd <- 1 ## Change this to something reasonable for your problem
prior.range <- 5 ## Change this to something reasonable for your problem
## For parameterisation details, see Eq (4) and onwards in
## Lindgren & Rue, "Bayesian Spatial Modelling with R-INLA,
## Journal of Statistical Software, 2015
## (also as the "read this first" spde tutorial on
r-inla.org)
log.kappa0 <- log(8)/2 - log(prior.range)
log.tau0 <- -log(4*pi)/2 - log(
prior.sd) - log.kappa0
B.tau <- cbind(log.tau0, -1, 1)
B.kappa <- cbind(log.kappa0, 0, -1)
theta.mu <- c(0, 0)
theta.prec <- c(0.1, 1)
theta.Q <- diag(theta.prec, length(
theta.mu))
lattice <- inla.mesh.lattice(1:30, 1:20)
mesh <- inla.mesh.create(lattice=lattice, extend=FALSE)
## Create a Neumann model
spdeN <- inla.spde2.matern(mesh, B.tau=B.tau, B.kappa=B.kappa,
theta.prior.mean=
theta.mu,
theta.prior.prec=theta.prec)
## Create a Dirichlet model
spdeD <- matern.dirichlet(mesh, B.tau=B.tau, B.kappa=B.kappa,
theta.mu=
theta.mu,
theta.Q=theta.Q)
```