coords<-cbind(mydata$longitude, mydata$latitude)
mesh<-inla.mesh.2d(loc=coords, max.edge = c(0.1, 5), cutoff = 0.002)
A.est<-inla.spde.make.A(mesh=mesh, loc=coords)
spde<-inla.spde2.matern(mesh=mesh, loc=coords)
s.index<-inla.spde.make.index(name="spatial.field", n.spde =spde$n.spde)
stack.est <- inla.stack(data=list(y=mydata$outcome),
A=list(A.est, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
effects=list(c(s.index, list(Intercept=1)),
list(emp= mydata$empstatus),
list(marital= mydata$maritstatus),
list(income=mydata$recevincome),
list(educ=mydata$educstatus),
list(TB=mydata$testdTB),
list(lengthtstd=mydata$lengthTestedHIV),
list(rdyARV=mydata$redy2strtARV),
list=(age=mydata$age_q),
List=(sx=mydata$sx),
list(acohl=mydata$freqalcoluse)),
tag="est")
formula <- y ~ -1 + Intercept + emp+ marital+ income+ educ+ TB+ lengthtstd+ rdyARV+ acohl+age+sx+ f(spatial.field, model=spde)
output <- inla(formula,
data=inla.stack.data(stack.est, spde=spde),
family="binomial",Ntrials=1,
control.predictor=list(A=inla.stack.A(stack.est),
compute=TRUE),
control.compute=list(dic=TRUE))
*** inla.core.safe: The inla program failed, but will rerun in case better initial values may help. try=1/1
Error in inla.core.safe(formula = formula, family = family, contrasts = contrasts, :
variable lengths differ (found for 'age')
The inla program failed and the maximum number of tries has been reached.