Main equation and hm() blocks: Using
fix()
Use the fix() helper inside vars() to hold
a coefficient at a specified value rather than estimating it. This works
both in the main equation and in hm() blocks.
Main equation:
# Fix the coefficient of 'exposure' to 1 (i.e., use as an offset)
m <- bml(
y ~ 1 + fix(exposure, 1) + x1 + x2,
data = dat,
family = gaussian()
)This is equivalent to adding exposure as a predictor but
constraining its coefficient to 1 instead of estimating it. This is
useful for offsets or when prior theory dictates a specific coefficient
value.
Unit-level covariates: with the
re()/fe() grammar, hm() carries
only the effect structure; unit-level covariates (and fix()
offsets of them) go in the main formula:
m <- bml(
y ~ 1 + x1 + fix(investiture, 0.5) + gdp +
mm(id = id(pid, gid), w = w(~ 1/n), fn = fn("sum"), RE = TRUE) +
hm(id = id(cid), FE = fe(1)),
data = coalgov,
family = gaussian()
)In mm() blocks:
m <- bml(
Surv(dur_wkb, event_wkb) ~ 1 + majority +
mm(
id = id(pid, gid),
vars = vars(fix(cohesion, 1) + finance),
w = w(~ 1/n, scale = TRUE),
fn = fn("sum"),
RE = TRUE
),
data = coalgov,
family = weibull()
)Here, the coefficient of cohesion is fixed at 1 while
finance is freely estimated.