unable to fit the shared multiscale model for the count data using two datas sets(one is of district level and another state level)

92 views
Skip to first unread message

Pooja B S

unread,
Mar 16, 2023, 1:56:15 PM3/16/23
to R-inla discussion group
Dear all,
I am trying to fit the shared convolution model for the count data (Poisson likelihood) using INLA. Model I am using is described in the attached research article as a 4th model with heading shared multiscale model.

Model is given in the image.

here is the code

#joint modelling
#importing district level data on crime and corresponding shape file of the district
NE <- read_excel("D:/New_Research/NE_data.xlsx")
crime.shapeNE <- readOGR(dsn="D:/New_research", layer="NE")
merged <- merge(crime.shapeNE, NE, by='censuscode')
nb=poly2nb(crime.shapeNE)# neighbourhood matrix
head(nb)
nb2INLA("map.adj", nb)
g <- inla.read.graph(filename = "map.adj")
merged$re_u <- 1:nrow(merged@data)

#preparing state level data on crime and importing the shape file of the state

k=crime.shapeNE_states <- readOGR(dsn="D:/New_research", layer="NE_State")
ST_CD=c(18,12,13,14,15,16,17)
FemPop=c(17011147, 736799, 1049838, 1560229, 595855, 1979496, 1623063)
crime1.num=c(26352, 281, 39, 247, 172, 874, 568)
NE_state=data.frame(ST_CD, FemPop, crime1.num)
R1=sum(NE_state$crime1.num)/sum(NE_state$FemPop)
NE_state$Ecrime1=R1*NE_state$FemPop

merged1 <- merge(k, NE_state, by='ST_CD')

#preparing data for joint modelling
m=nrow(merged1@data)
s=nrow(merged@data)
l=m+s
Y=Matrix(NA, ncol = 2, nrow = l)
Y1=merged1$crime1.num
Y2=merged$crime.num.y
Y[1:m,1]=Y1
Y[8:l,2]=Y2
#intercept
Inter=matrix(NA, nrow = l, ncol = 2)
Inter[1:m,1]=1
Inter[8:l,2]=1

#offset
E1=merged1$Ecrime1
E2=merged$Ecrime

E=c(E1, E2)

ID.shared1=c(as.numeric(merged1$ST_CD),rep(NA, s))
ID.shared2=c(rep(NA, m),as.numeric(merged$ST_CEN_CD.x))
ID2=c(rep(NA,7), merged$re_u)
# model
form1=Y~0+Inter+ f(ID.shared1, model="bym", graph=g1) + f(ID.shared2, copy= 'ID.shared1', model="bym",graph=g1) + f(ID2, model="bym", graph=g)
fit=inla(form1, family = c("poisson", "poisson"), data = list(Y=Y, Inter=Inter, E=E, ID.shared1=ID.shared1, ID.shared2=ID.shared2, ID2=ID2), E=E, control.compute = list(waic=T), control.predictor = list(compute = TRUE))

what is the mistake I have done here.

I am getting the following error:

Error in inla.core(formula = formula, family = family, contrasts = contrasts,  :

  f(ID.shared1). Covariate does not match 'values' 7 times. Indexes for mismatch:1 2 3 4 5 6 7. This is not what you want. Use NA values in the covariate!

 

 *** inla.core.safe:  inla.program has crashed: rerun to get better initial values. try=1/2

Error in inla.core(formula = formula, family = family, contrasts = contrasts,  :

  f(ID.shared1). Covariate does not match 'values' 7 times. Indexes for mismatch:1 2 3 4 5 6 7. This is not what you want. Use NA values in the covariate!

 

 *** inla.core.safe:  inla.program has crashed: rerun to get better initial values. try=2/2

Error in inla.core(formula = formula, family = family, contrasts = contrasts,  :

  f(ID.shared1). Covariate does not match 'values' 7 times. Indexes for mismatch:1 2 3 4 5 6 7. This is not what you want. Use NA values in the covariate!

Error in inla.core.safe(formula = formula, family = family, contrasts = contrasts,  :

  *** Fail to get good enough initial values. Maybe it is due to something else.

1-s2.0-S1877584516301095-main.pdf

Helpdesk (Haavard Rue)

unread,
Mar 17, 2023, 3:28:27 PM3/17/23
to Pooja B S, R-inla discussion group

This seems straight forward. and its look like its something minor only.

btw, you use 'g1' but I don't see it.

In

f(ID.shared2, copy= 'ID.shared1', model="bym",graph=g1)

then only this is needed

f(ID.shared2, copy= 'ID.shared1')

as it take all other infor from 'ID.shared1'

make sure 'ID.shared1' are integers in the range 1...7

If you cannot make it work, send me data/ complete code

H
> --
> 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/a362949a-f649-4227-9c5b-a5f2a98837a6n%40googlegroups.com
> .

--
Håvard Rue
he...@r-inla.org
Reply all
Reply to author
Forward
0 new messages