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