0

I am wondering if someone could help me interpret my piecewise lmm results. Why does ggpredict() produce different estimates for the knot at 10 weeks (end of tx; see ‘0’ in graph at end)? I've structured the data like so:

bpiDat <- bpiDat %>%
        mutate(baseToEndTx = ifelse(week <= 10, week, 1)) %>%
        mutate(endOfTxToFu = case_when(
                week <= 10 ~ 0,
                week == 18 ~ 8,
                week == 26 ~ 16,
                week == 34 ~ 24
        )) %>%
        select(id, treatment, baseHamd, week, baseToEndTx, endOfTxToFu,
               painInterferenceMean, painSeverityMean, bpiTotal) %>%
        mutate(baseHamd = scale(baseHamd, scale=F))

Which looks like this:

id treatment  baseHamd week baseToEndTx endOfTxToFu painSeverityMean
1 1 4.92529343  0   0   0   6.75
1 1 4.92529343  2   2   0   7.25
1 1 4.92529343  4   4   0   8.00
1 1 4.92529343  6   6   0   NA
1 1 4.92529343  8   8   0   8.25
1 1 4.92529343  10  10  0   8.00
1 1 4.92529343  18  1   8   8.25
1 1 4.92529343  26  1   16  8.25
1   4.92529343  34  1   24  8.00

The best fitting model:

model8 <- lme(painSeverityMean ~ baseHamd + baseToEndTx*treatment + endOfTxToFu + I(endOfTxToFu^2)*treatment,
              data = bpiDat,
              method = "REML",
              na.action = "na.exclude",
              random = ~baseToEndTx | id)

This is how I’m visualizing:

test1 <- ggpredict(model8, c("baseToEndTx", "treatment"), ci.lvl = NA) %>%
        mutate(x = x - 10) %>%
        mutate(phase = "duringTx")
        
test2 <- ggpredict(model8, c("endOfTxToFu", "treatment"), ci.lvl = NA) %>%
        mutate(phase = "followUp")

t <- rbind(test1, test2)

t <- t %>%
        pivot_wider(names_from = "phase",
                    values_from = "predicted")

ggplot(t) +
        geom_smooth(aes(x,duringTx,col=group),method="lm",se=FALSE) +
        geom_smooth(aes(x,followUp,col=group),method="lm",se=FALSE) +
        geom_point(aes(x,duringTx,col=group)) +
        geom_point(aes(x,followUp,col=group)) +
        ylim(2,6)

Which produces this: enter image description here

0 Answers0