Linear regression in INLA

29 views
Skip to first unread message

NADIA LOPEZ

unread,
Sep 20, 2025, 4:17:26 PM (5 days ago) Sep 20
to R-inla discussion group

Hello. I am a beginner using INLA. I would greatly appreciate your help.

I am studying the relationship between "fish larvae count" and water temperature (°C). The larvae count in the samples was collected from various filtered volumes (m3). Instead of using relative abundance (larvae count/filtered volume), I am using the larvae count as the dependent variable to utilize known distributions like the Negative binomial or Poisson. The filtered volume was included as an "E".

 1.- Is it correct to utilize the argument "E" in this case? Additionally, does "E" function effectively in a negative binomial distribution?

 I am sharing with you the structure of my data and the model:

df <- data.frame(count_larvae = c(3,3,2,2,1,1,3,1,3,8,3,11,16,26,1,1,15),
                 filtrate_volume = c(237.0,256.0,259.2,232.3,262.2,189.6,210.3,
                                     245.9,145.3,260.6,158.2,148.3,258.0,266.8,
                                     237.5,192.8,116.0),
                 temperature = c(30.2,30.2,30.3,30.3,30.2,30.3,30.0,30.1,29.9,
                                 29.6,29.8,29.6,29.7,29.3,29.9,29.9,29.7))

model <- inla(data = df,
              E = filtrate_volume,
              formula = count_larvae ~ temperature,
              family = "nbinomial",
              control.predictor = list(compute = TRUE,
                                       link = 1),
              quantiles = c(0.025, 0.5, 0.975),
              control.compute = list(
                return.marginals.predictor = TRUE,
                mlik = TRUE,
                config = TRUE))

 

2.- What units does the model output employ? The output is not in the form of larvae count, as they are continuous quantities even though link=1 is utilized. Consequently, I am unable to incorporate the observations (larvae count, discrete quantities) in the plot.

names(model$summary.fitted.values) <- paste("fit_",
                                            names(model$summary.fitted.values),
                                            sep = "")
df_output <- cbind(df, model$summary.fitted.values)
str(df_output)

 'data.frame': 17 obs. of  9 variables:

 $ count_larvae   : num  3 3 2 2 1 1 3 1 3 8 ...
 $ filtrate_volume: num  237 256 259 232 262 ...
 $ temperature    : num  30.2 30.2 30.3 30.3 30.2 30.3 30 30.1 29.9 29.6 ...
 $ fit_mean       : num  0.00847 0.00847 0.00622 0.00622 0.00847 ...
 $ fit_sd         : num  0.00234 0.00234 0.00204 0.00204 0.00234 ...
 $ fit_0.025quant : num  0.00475 0.00475 0.00312 0.00312 0.00475 ...
 $ fit_0.5quant   : num  0.00818 0.00818 0.00593 0.00593 0.00818 ...
 $ fit_0.975quant : num  0.0139 0.0139 0.011 0.011 0.0139 ...
 $ fit_mode       : num  0.00765 0.00765 0.00541 0.00541 0.00765 ...

Thanks in advance for your support.

Best regards,

Nadia L.

Finn Lindgren

unread,
Sep 20, 2025, 5:57:07 PM (5 days ago) Sep 20
to R-inla discussion group
Hi,

you should take a look at the negative binomial model documentation via INLA::inla.doc("nbinomial") which, among other things, says that E is used as a scaling for the model for the expectation, so for both Poisson and binomial models, your use of E seems correct to me.

The fitted.values results is for the expectation parameter, i.e. the posterior predictive distribution of the _expectation value_ for each row of the input data.
As you noted, this is not a count, and that's because it is the the value of the expectation _parameter_ of the Negative Binomial distribution, and _not_ a value generated from that distribution.

To do data-level prediction, you need to post-process the results to incorporate the observation-level model variability.
Precisely how to do that depends on precisely what you wish to compute and/or estimate.
A common approach is to do posterior sampling of the predictor/expectation values, and combine that with a data-level simulation step.

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/ab81f445-4d57-4542-b49e-c6f49a07e0cdn%40googlegroups.com.


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

Helpdesk (Haavard Rue)

unread,
Sep 21, 2025, 2:44:34 PM (4 days ago) Sep 21
to Finn Lindgren, R-inla discussion group

also note that the 'E' in the Poisson and nbinomial, is _not_ part of the fitted
values. if you want it to be, use

formula= .. ~ .. + offset(log(E.values))

instead, where 'E.values' are the values of 'E' you would 'normally' use
Håvard Rue
he...@r-inla.org

NADIA LOPEZ

unread,
Sep 22, 2025, 8:04:31 PM (3 days ago) Sep 22
to R-inla discussion group
Hi,

Thank you both for your support!
All the best!

Nadia L.
Reply all
Reply to author
Forward
0 new messages