Search code examples
rlinear-regressionpiecewise

Piecewise regression : davies.test returns p-value = NA


My data :

require(segmented)
cp <- c(0.079, 0.079, 0.079, 0.080, 0.080, 0.081, 0.081, 0.081, 0.081, 0.081, 0.081, 0.082, 0.083, 0.084, 0.086, 0.088, 0.088, 0.088, 0.088, 0.088)
dates <- c(1443991015, 1443994615, 1443998215, 1444001815, 1444005415, 1444009015, 1444012615, 1444016215, 1444019815, 1444023415, 1444027015, 1444030615, 1444034215, 1444037815, 1444041415, 
       1444045015, 1444048615, 1444052215, 1444055815, 1444059415)

I would test the breakpoint occurrence. So I did the Davies.test, as suggested here :

davies.test(lm(cp ~ dates), seg.Z = ~ dates)

But it returns p-value = NA :

    Davies' test for a change in the slope

data:  formula = cp ~ dates ,   method = lm 
model = gaussian , link = identity  
segmented variable = dates
= , n.points = 0, p-value = NA
alternative hypothesis: two.sided

Solution

  • It looks like davies.test can't handle values on that scale; some kind of overflow is happening internally.

    dd <- scale(dates)
    davies.test(lm(cp ~ dd), seg.Z = ~ dd)
    

    seems to work fine.