I'm conducting a study on diurnal preferences across the lifespan, with a focus on sex-specific trajectories. Before conducting sex-specific segmented regressions, I perform an initial segmented regression with the entire sample to identify breakpoints (BPs) that guide the subsequent analyses by sex.
In order to obtain the BPs with the overall sample, I used the selgmented function:
data_lm <- lm(diurnal preferences ~ age + sex + age * sex, data = data)
data_selgmented <- selgmented(data_lm, seg.Z = ~age, Kmax = 10,
type = 'aic', alpha = 0.05,
control = seg.control(n.boot = 50, display = FALSE,
tol = 1e-05, it.max = 30, fix.npsi = TRUE,
maxit.glm = 25, h = 1, break.boot = 5,
size.boot = NULL, jt = FALSE, nonParam = TRUE,
random = TRUE, seed = 12345, fn.obj = NULL,
digits = NULL, conv.psi = FALSE, alpha = NULL,
min.step = .0001, powers = c(1,1), last = TRUE,
stop.if.error = NULL, gap = FALSE, fc = .95),
refit = TRUE, stop.if = 100, return.fit = TRUE,
bonferroni = FALSE, msg = TRUE, plot.ic = TRUE,
th = NULL, G = 1, check.dslope = TRUE)
A BP was detected at 37 years of age.
The results showed me that the right slope can be set to zero, as there was no significant relationship between the variables of interest.
I've tried to follow the approach outlined in Muggeo’s 2008 paper (https://journal.r-project.org/articles/RN-2008-004/RN-2008-004.pdf), specifically the “Plant” example, but I'm encountering some difficulties. Here's what I've done:
neg.age <- - age
data_lm <- lm(diurnal preferences ~ sex + neg.age * sex,
data = data)
data_segmented <- segmented(data_lm, seg.Z = ~neg.age,
psi = -37)
confint(data_segmented,rev.sgn=c(TRUE))
slope(data_segmented, rev.sgn=c(TRUE))
However, I've encountered an issue where the right slope is not being constrained. Additionally, I'm curious whether it's advisable to always constrain a slope when there is no significant relationship?
I hope this question was clear… First time posting, and I am quite inexperienced when it comes to statistics. Any insight is greatly appreciated.
agevariable flexibly, for example with a regression spline? Sharp cutoff points aren't often reasonable in biological studies, and they pose problems similar to what you find with binning continuous predictors. See Section 2.4 of Frank Harrell's Regression Modeling Strategies. – EdM Oct 27 '23 at 17:18