Explicitly providing the location of X
(e.g. sample_dat$X
) in the call to glm
does the trick.
Here is a reproducible example:
library(segmented)
# sample data
set.seed(101)
sample_dat <- data.frame(Y = rpois(100, 3), X1 = rnorm(100), X2 = rnorm(100), X = rpois(100, 100))
# fit model
M1 = glm(Y ~ X1 + X2, data = sample_dat, offset = log(sample_dat$X), family = poisson)
seg.1 = segmented(M1, seg.Z=~X1, psi=list(X1 = c(0.5)), data = sample_dat)