Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Hyperparameters for f(spde, control.group(rw1))

37 views
Skip to first unread message

Ruby Ji

unread,
Dec 7, 2024, 6:50:20 AM12/7/24
to R-inla discussion group
Dear INLA experts,

I recently noticed that there are only two hyperparamters (range and std) for this part:

f(s, model=spde, group=s.group, control.group=list(model="rw1", scale.model=TRUE))

Could you please explain why the precision parameter of the RW1 model is not treated as a separate hyperparameter?

Thanks,
Ruby

Helpdesk (Haavard Rue)

unread,
Dec 7, 2024, 6:52:54 AM12/7/24
to Ruby Ji, R-inla discussion group
because its perfectly confounded with the one is the spde. its a product hence
we set the group one to 1 (or log.prec=0)
> --
> 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/ae25ed30-742c-4bfc-a953-795329094c73n%40googlegroups.com
> .

--
Håvard Rue
he...@r-inla.org

Ruby Ji

unread,
Dec 7, 2024, 7:07:11 AM12/7/24
to R-inla discussion group

Hi Haavard,


Thank you for your clarification! I have two additional questions regarding this topic:


First, regarding the scale.model = TRUE option in control.group: Does INLA first scale the precision matrix of the RW1 model (Q_rw1) and then compute the Kronecker product of the SPDE precision matrix (Q_spde) and the scaled Q_rw1?


Second, concerning the addition of a diagonal term: If I specify the model as follows:
f(s, model = spde, group = s.group, diagonal = 1e-06, control.group = list(model = "rw1", scale.model = TRUE))
Is the diagonal term added to the Kronecker product of Q_spde and Q_rw1_scaled? After adding the diagonal term, does INLA rescale the combined precision matrix to make the generalized variance = 1?

Thanks,
Ruby

Helpdesk (Haavard Rue)

unread,
Dec 7, 2024, 7:19:22 AM12/7/24
to Ruby Ji, R-inla discussion group
On Sat, 2024-12-07 at 04:07 -0800, Ruby Ji wrote:
> First, regarding the scale.model = TRUE option in control.group: Does INLA
> first scale the precision matrix of the RW1 model (Q_rw1) and then compute the
> Kronecker product of the SPDE precision matrix (Q_spde) and the scaled Q_rw1?

the group models are always scaled no matter what scale.model= says

>
> Second, concerning the addition of a diagonal term: If I specify the model as
> follows:
> f(s, model = spde, group = s.group, diagonal = 1e-06, control.group =
> list(model = "rw1", scale.model = TRUE))
> Is the diagonal term added to the Kronecker product of Q_spde and
> Q_rw1_scaled? After adding the diagonal term, does INLA rescale the combined
> precision matrix to make the generalized variance = 1?

diagonal term is added after scaling and kronecker product

Helpdesk (Haavard Rue)

unread,
Dec 7, 2024, 7:22:38 AM12/7/24
to Ruby Ji, R-inla discussion group
let me be more clear

Q_spde is already scaled, so not effect of 'scale.model'

Q_rw1 is scaled using and epsilon diagonal term. I *think* this not done using
the 'diagonal' argument, but then you need to check the code

then the kronecker product is formed and epsilon is added to its diagonal

On Sat, 2024-12-07 at 04:07 -0800, Ruby Ji wrote:

Ruby Ji

unread,
Dec 7, 2024, 7:58:57 AM12/7/24
to R-inla discussion group
Thank you! Your clarification is really helpful!

Ruby Ji

unread,
Dec 7, 2024, 8:19:19 PM12/7/24
to R-inla discussion group

Hi Haavard,


I came across a new question related to the RW1 model. The precision is a hyperparameter in the model: f(year, model="rw1", scale.model=TRUE).

The precision matrix, Q, is defined as precision * R, where R is the structure matrix reflecting the neighborhood structure of the model.

I scaled Q using inla.scale.model(Q, constr = list(A = matrix(1, 1, n), e = 0)) and noticed that, regardless of the precision value, the scaled Q (Q.scaled) remains the same. If this is the case, how is the precision estimated?


Thanks,

Ruby

Ruby Ji

unread,
Dec 8, 2024, 1:47:54 AM12/8/24
to R-inla discussion group
I think I got the answer. Does the final Q equal prec*Q.scaled?

>library(INLA)
>df <- data.frame(x = 1, y = NA)
> Q <- 100 * (t(diff(diag(4))) %*% diff(diag(4)))
> (Q.scaled <- inla.scale.model(Q, constr = list(A = matrix(1, 1, n), e = 0)))
4 x 4 sparse Matrix of class "dgTMatrix"
                                           
[1,]  0.572822 -0.572822  .         .      
[2,] -0.572822  1.145644 -0.572822  .      
[3,]  .        -0.572822  1.145644 -0.572822
[4,]  .         .        -0.572822  0.572822
> fit_scaled <- inla(y ~ 0 + f(x, model = "rw1", scale.model= TRUE, values = 1:4, diagonal=0,
+                              hyper = list(prec = list(initial = log(100), fixed = TRUE))),
+                    data = df,
+                    control.inla = list(int.strategy = "eb"),
+                    control.compute = list(config = TRUE))
> (fit_scaled$misc$configs$config[[1]]$Q)
4 x 4 sparse Matrix of class "dgCMatrix"
                                           
[1,] 57.28219 -57.28219   .         .      
[2,]  .       114.56438 -57.28219   .      
[3,]  .         .       114.56438 -57.28219
[4,]  .         .         .        57.28219

Helpdesk (Haavard Rue)

unread,
Dec 9, 2024, 3:30:20 AM12/9/24
to Ruby Ji, R-inla discussion group
yes

with

demo(Bym)

then

inla(Y ~ f(region.struct,model="besag",graph=g, scale.model=TRUE),
data=Germany,E=E,verbose=T,family="poisson")

you'll see in the output

inla_parse_ffield...
section=[region.struct]
dir=[random.effect0000000001]
scale.model[1]
connected component[0] size[544] scale[0.561134]
scale.model: prec_scale[0.561134]

so the constant which is used to scale is '0.56...'

Ruby Ji

unread,
Dec 10, 2024, 8:31:38 PM12/10/24
to R-inla discussion group
This makes sense. Thank you for your clarification!
Reply all
Reply to author
Forward
0 new messages