Fail to get good enough initial values.

691 views
Skip to first unread message

Leon Zheng

unread,
Jul 18, 2022, 4:06:08 AM7/18/22
to R-inla discussion group
Hi,
I am running spatio-temporal model. However, i get the erreo message like this:*** Fail to get good enough initial values. Maybe it is due to something else.  When i use another response variable or if i use a very large cutoff, everything is fine. Can you give me some suggestions what can I do to tune the model, thanks so much!

coo <- data[ ,9:10]
mesh <- inla.mesh.2d(
  loc = coo,
  boundary = bnd,
  max.edge = c(1, 2),
  cutoff = 0.01
)

plot(mesh)
points(coo,col = "red", pch = 1)

# SPDE
spde <- inla.spde2.matern(
  mesh = mesh, alpha = 2, constr = TRUE,
  #prior.range = c(10000, 0.01), # P(range < 10000) = 0.01
  #prior.sigma = c(3, 0.01) # P(sigma > 3) = 0.01
)

# index of spatial field
timesn <- length(unique(data$date))
indexs <- inla.spde.make.index(
  "s",
  n.spde = spde$n.spde,
  n.group = timesn
)

# make A
group <-  rep(c(1:11), each=nrow(data)/11)
coo <- cbind(data$lon, data$lat)
A <- inla.spde.make.A(mesh = mesh, loc = coo, group=group) #, group=group

# stack
X <- data[, c(3, 8, 11:16)]
X$time <- group

stk <- inla.stack(
  tag = "data",
  data = list(
    Yreli = data$Yreli,
    Ereli=data$Ereli,
    Yprev = data$Yprev,
    Eprev=data$Eprev
  ),
  A = list(1, A),
  effects = list(X=X, s = indexs)
)

f.3.3_reli <- Yreli ~  perc_white + price_med + pm10 + board +
  dispensing + urban +december + f(s, model = spde, group = s.group,
                                   control.group = list(model = "ar1",
                                                        hyper = rprior))
poi_st_reli_ari <- inla(f.3.3_reli,
                        family = "poisson", E = Ereli,
                        data = inla.stack.data(stk),
                        control.compute = list(dic = TRUE, waic=TRUE),
                        control.predictor = list(compute = TRUE,
                                                 A = inla.stack.A(stk)
                        )) 

Sylvan Benaksas

unread,
Jul 21, 2022, 5:44:37 AM7/21/22
to R-inla discussion group
your spde range looks like it is in metres, you should construct the mesh in Km and then specify the spde range in Km also,

Sylvan

Leon Zheng

unread,
Jul 21, 2022, 11:51:40 AM7/21/22
to R-inla discussion group
Hi Sylvan,

Thank you for your reply. I use long and lat as coordinates and I directly use long and lat to calculate the distance.  Will these affect the mesh? I can use this mesh to run other models which are totally the same as the crashed model except the response variable.

Sylvan Benaksas

unread,
Jul 22, 2022, 1:07:26 PM7/22/22
to Leon Zheng, R-inla discussion group
Hi Leon,

I'm not sure how lat lon will affect the mesh, I am no expert. I convert lat lon to UTM and then from metres to Km when constructing the mesh and I think this is the recommended method, to avoid numerical issues. 

Cheers,
Sylvan

--
You received this message because you are subscribed to a topic in the Google Groups "R-inla discussion group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/r-inla-discussion-group/uIIsKZcA5H0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to r-inla-discussion...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/r-inla-discussion-group/9312143b-790f-4524-b2f3-e6431323a955n%40googlegroups.com.

Helpdesk

unread,
Jul 27, 2022, 3:39:57 PM7/27/22
to Leon Zheng, R-inla discussion group

I need data and full code so I can rerun it here to check

you can try with R-4.2 and the most recent testing version and adding

inla(..., inla.mode="experimental")
> --
> 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 on the web, visit
> https://groups.google.com/d/msgid/r-inla-discussion-group/ce2ac5bc-a794-47d0-8b2e-cb62cd2958d9n%40googlegroups.com
> .

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

Leon Zheng

unread,
Aug 3, 2022, 9:43:12 AM8/3/22
to R-inla discussion group
Hi  Håvard,

Here is the link for code and data, thanks.
在2022年7月27日星期三 UTC+1 20:39:57<he...@r-inla.org> 写道:

I need data and full code so I can rerun it here to check

you can try with R-4.2 and the most recent testing version and adding

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

Helpdesk

unread,
Aug 4, 2022, 1:08:57 PM8/4/22
to Leon Zheng, R-inla discussion group

it seems to me that the correlation in time tends to 1- and that this
cause numerical issues. the answer seems to be to remove the time
dependency, and just let the spde be constant in time.

does this make sense?

Leon Zheng

unread,
Aug 4, 2022, 2:53:48 PM8/4/22
to R-inla discussion group
Hi  Håvard,
Yes, you are absolutely right. If I use RW1 instead of AR1, it works out. 

As you can see, the dataset has  another variables called Yprev and Eprev. If I change the outcome variable from Yreli to Yprev and use Eprev as offset and still use AR1, INLA gives me the result that time correlation is acound 1. 

I am wondering why INLA crashes when I use Yreli as outcome variable?

INLA help

unread,
Aug 4, 2022, 3:14:42 PM8/4/22
to Leon Zheng, R-inla discussion group
Numerical issues as the correlation goes to 1

From: r-inla-disc...@googlegroups.com <r-inla-disc...@googlegroups.com> on behalf of Leon Zheng <ct358...@gmail.com>
Sent: Thursday, August 4, 2022 8:53:47 PM
To: R-inla discussion group <r-inla-disc...@googlegroups.com>
Subject: Re: [r-inla] Fail to get good enough initial values.
 
--
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.

Leon Zheng

unread,
Aug 4, 2022, 3:29:28 PM8/4/22
to R-inla discussion group
when time correlation goes to 1, AR1 can't estimate the correlation, i should use RW1 instead. Do I  have the right understanding?

Leon Zheng

unread,
Aug 4, 2022, 5:05:29 PM8/4/22
to R-inla discussion group
Hi Håvard,

Actually rw1 is a special case of ar1.  I use inla.doc("ar1) and it says that |rho| < 1. Does this mean that by using ar1 in R-INLA, it only gives answer approaching 1 but never equal to 1?

在2022年8月4日星期四 UTC+1 20:14:42<he...@r-inla.org> 写道:

INLA help

unread,
Aug 4, 2022, 5:17:58 PM8/4/22
to Leon Zheng, R-inla discussion group

Leon Zheng

unread,
Aug 5, 2022, 9:47:37 AM8/5/22
to R-inla discussion group
By the way, how do you find the time correlation tends to 1. I use a sparse mesh and find the time correlation is close to 1. Is there any way under the situation to prove the numerical issue is caused by the time correlation being 1? Would it be possible even the time correlation tends to 1, INLA still can find a number by using AR1?

Helpdesk

unread,
Aug 7, 2022, 10:42:25 AM8/7/22
to Leon Zheng, R-inla discussion group

run with option

inla(..., verbose=TRUE)

and check the output in the optimization

On Fri, 2022-08-05 at 06:47 -0700, Leon Zheng wrote:
> By the way, how do you find the time correlation tends to 1. I use a
> sparse mesh and find the time correlation is close to 1. Is there any
> way under the situation to prove the numerical issue is caused by the
> time correlation being 1? Would it be possible even the time
> correlation tends to 1, INLA still can find a number by using AR1?
>
> 在2022年8月4日星期四 UTC+1 22:17:58<he...@r-inla.org> 写道:
> > Yes
> >
> > Get Outlook for iOS
> > From: r-inla-disc...@googlegroups.com
> > <r-inla-disc...@googlegroups.com> on behalf of Leon Zheng
> > <ct358...@gmail.com>
> > Sent: Thursday, August 4, 2022 11:05:29 PM
> >
> > To: R-inla discussion group <r-inla-disc...@googlegroups.com>
> > Subject: Re: [r-inla] Fail to get good enough initial values.
> > Hi Håvard,
> >
> > Actually rw1 is a special case of ar1.  I use inla.doc("ar1) and it
> > says that |rho| < 1. Does this mean that by using ar1 in R-INLA, it
> > only gives answer approaching 1 but never equal to 1?
> >
> > 在2022年8月4日星期四 UTC+1 20:14:42<he...@r-inla.org> 写道:
> > > Numerical issues as the correlation goes to 1
> > >
> > > Get Outlook for iOS
Reply all
Reply to author
Forward
0 new messages