Model Matrix Issue "no slot of name "i""

12 views
Skip to first unread message

Eric Weine

unread,
Dec 12, 2025, 10:39:38 AM (4 days ago) Dec 12
to R-inla discussion group
Hello,

I have a relatively large spatial transcriptomics dataset for which I am trying to fit an INLA model. I can't share the data but I was able to create a simulation to reproduce the bug below:

library(Matrix)
library(INLA)
library(fmesher)

set.seed(1)

N <- 15000
coords_std <- cbind(runif(N), runif(N))
colnames(coords_std) <- c("x","y")

bnd <- fm_nonconvex_hull(x = coords_std,
                         convex = -0.03,   # negative => non-convex
                         concave = 0.03,
                         resolution = 100)

mesh <- fm_mesh_2d_inla(
  boundary = bnd,
  max.edge = c(0.05, 0.12),  # inner, outer target edges (in [0,1] units)
  cutoff   = 0.005,          # de-duplicate near-coincident data points
  offset   = c(0.03, 0.08)  
)

plot(mesh)

spde <- inla.spde2.pcmatern(
  mesh = mesh,
  alpha = 2,                     # smoothness ν = 1
  prior.range = c(0.15, 0.5),    # median-ish range ~0.15
  prior.sigma = c(1.0, 0.01)     # fairly weak; tighten if needed
)

A <- inla.spde.make.A(mesh = mesh, loc = coords_std)

y_counts <- rpois(N, lambda=1)

stk.e <- inla.stack(
  tag='est', ## tag id
  data=list(y=y_counts), ## response
  A=list(1, A), ## two projection matrices
  effects=list(## intercept:
    data.frame(b0=rep(1, N)), ## covariate
    idx.u=1:spde$n.spde)
) ## RF index

mf <- y ~ 0 + b0 + f(idx.u, model=spde)
res <- inla(mf, family  = "poisson",
            data=inla.stack.data(stk.e), ## data
            control.predictor=list(compute=TRUE,
                                   A=inla.stack.A(stk.e)))# full projector

When I run this code, I get an error when calling "inla". The error message says

Error in inla.core.safe(formula = formula, family = family, contrasts = contrasts,  :
  no slot of name "i" for this object of class "dsparseModelMatrix"

I can't figure this issue out, and when I look at inla.stack.A(stk.e)@i I do get values, so I'm not really sure what's going on.

Here is my sessionInfo in case there is a version issue perhaps?

R version 4.5.2 (2025-10-31)
Platform: aarch64-apple-darwin20
Running under: macOS Ventura 13.5

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.1

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base    

other attached packages:
[1] fmesher_0.6.1.9000 ggplot2_4.0.1      dplyr_1.1.4        INLA_25.10.19    
[5] Matrix_1.7-4   

Any help would be greatly appreciated! I am new to INLA so I'm sorry if the solution to this is obvious but I haven't been able to find much help via googling.

Eric.

Finn Lindgren

unread,
Dec 12, 2025, 10:42:45 AM (4 days ago) Dec 12
to Eric Weine, R-inla discussion group
What's the
  traceback()
output after the error message?
THat can reveal more precisely what part of the code and/or which variable is actually triggering the error.

Finn

--
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/fc1f1d31-51e8-4587-93f5-601dd3d76d1en%40googlegroups.com.


--
Finn Lindgren
email: finn.l...@gmail.com

Helpdesk (Haavard Rue)

unread,
Dec 12, 2025, 10:44:22 AM (4 days ago) Dec 12
to Eric Weine, R-inla discussion group

It runs fine with me.

It might be that not all external packages are up to date? Like the 'Matrix'
one, which triggers the error.

I presume you have R-4.5 and the most recent testing version

can you try with update.packages() ?
> --
> 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/fc1f1d31-51e8-4587-93f5-601dd3d76d1en%40googlegroups.com
> .

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

Finn Lindgren

unread,
Dec 12, 2025, 10:44:37 AM (4 days ago) Dec 12
to Eric Weine, R-inla discussion group
Also, can you try it after upgrading to the latest INLA (testing) version?
(You have the fmesher version from last night, so at least that's very recent. ;) )
Finn

Finn Lindgren

unread,
Dec 12, 2025, 10:46:21 AM (4 days ago) Dec 12
to Helpdesk, Eric Weine, R-inla discussion group
The Matrix version is recent, but I don't see your MatrixModels version (which is where the object class involved comes from):
> packageVersion("Matrix")
[1] ‘1.7.4’
> packageVersion("MatrixModels")
[1] ‘0.5.4’

Eric Weine

unread,
Dec 12, 2025, 11:25:40 AM (4 days ago) Dec 12
to R-inla discussion group
Ok, I think what may have been happening is that the MatrixExtra package may have been doing something very strange...

I have the most up to date versions of all the packages described above, and updated INLA to the testing version.

I ran the simulation I shared, and everything worked.

Then, I ran my actual code (which had one call to MatrixExtra::mapSparse), and neither my simulation nor my actual code worked anymore before starting a new R session.

Removing the MatrixExtra call from my code resolved the issue.

Thanks for your quick replies!
Reply all
Reply to author
Forward
0 new messages