Constraining a linear effect to be strictly negative using model = "clinear"

16 views
Skip to first unread message

Brian

unread,
Apr 3, 2026, 7:46:21 AM (3 days ago) Apr 3
to R-inla discussion group
Hi,

I would like to constrain a covariate effect to be strictly negative using model = "clinear". My understanding is that range = c(0, Inf) constrains the coefficient to be positive, but range = c(-Inf, 0) does not appear to work for the negative direction. My current workaround is to negate the covariate values before passing them to the model, then use range = c(0, Inf)

```
set.seed(42)
n <- 100
x <- runif(n, 0, 5)        

true_beta <- -0.5
eta <- 1.2 + true_beta * x
prob <- plogis(eta)
y <- rbinom(n, size = 20, prob = prob)
N <- rep(20, n)

df <- data.frame(y = y, x = x, N = N)
df$x_neg <- -df$x

mod1 <-  bru(
  y ~ 1 + x_neg(
    x_neg, model = "clinear",
    range = c(0, Inf),
    hyper = list(beta = list(
      prior = "normal",
      param = c(log(0.5), 10),
      initial = log(0.5)
    ))
  ),
  family = "binomial",
  Ntrials = df$N,
  data = df,
  options = list(
    control.fixed = list(mean = 0, prec = 1),
    control.compute = list(dic = TRUE, waic = TRUE)
  )
)

```
> mod1$summary.fixed
              mean         sd 0.025quant 0.5quant 0.975quant     mode          kld
Intercept 1.240562 0.09790531    1.04952 1.240448   1.434125 1.241046 3.090623e-08
> mod1$summary.hyperpar
                    mean         sd 0.025quant  0.5quant 0.975quant      mode
Beta for x_neg 0.4996882 0.03284004  0.4359643 0.4995001  0.5646765 0.4991043


This recovers a positive coefficient on x_neg, which I then negate to obtain the implied negative effect on the original x. It seems to work, but I am not confident it is the intended approach

Håvard Rue

unread,
Apr 3, 2026, 11:28:00 AM (3 days ago) Apr 3
to Brian, R-inla discussion group
yes, just switch the sign of the covariate. its all these cases to write and
check and I might have taken a short-cut as we can just use '-x' to negate the
sign.
> --
> 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/d8d12cb4-ac03-420d-aead-b7d1d93f6f90n%40googlegroups.com
> .

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

Brian

unread,
Apr 3, 2026, 1:38:32 PM (3 days ago) Apr 3
to R-inla discussion group
Alright.Thank you for the response. 
Reply all
Reply to author
Forward
0 new messages