Skip to content

Error in if (is.nan(p0) || p0 < a2 || p0 > (1 - a2)) {: missing value where TRUE/FALSE needed #18

@GreatEmerald

Description

@GreatEmerald

In the confint.breakpointsfull() function, sometimes we may get singularities in the regression, which leads to coefficients being NA and propagating all the way down, causing this:

library(strucchange)
#> Loading required package: zoo
#> 
#> Attaching package: 'zoo'
#> The following objects are masked from 'package:base':
#> 
#>     as.Date, as.Date.numeric
#> Loading required package: sandwich
library(bfast)
testdata = c(NA, NA, 29, NA, NA, 9, NA, NA, 10, 13, 22, 17, 31, 32, 25, 24, 21, 20, 9, NA, NA, NA, NA, NA, NA, 10, 14, NA, NA, NA, 7, 16, 17, 25, 33, 22, 28, 28, NA, 19, 13, 17, 26, NA, NA, NA, NA, NA, NA, NA, NA, 13, NA, NA, 10, 2, 17, 25, 44, 20, 20, 22, NA, 14, 16, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 36, 37, 24, 33, 32, 25, 22, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 10, 20, 7, 26, 32, 42, 36, 40, 30, 19, NA, 30, 36, NA, NA, NA, NA, NA, NA, NA, NA, 17, NA, NA, 23, 28, NA, 37, 45, 37, 44, 29, 35, 28, 30, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 19, 27, 35, 39, 31, 35, 31, 30, 29, 25, 47, NA, NA, NA, NA, NA, NA, NA, NA, NA, 16, NA, 18, 23, 27, 39, 31, 41, 33, 30, 34, 32, 26, NA, 34, NA, NA, NA, NA, NA, 25, NA, NA, 21, 17, NA, 23, 26, 40, 37, 27, 35, 28, 30, 27, 25, 22, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 21, 25, 32, 34, 30, 31, 28, 24, 23, 20, 22, NA, NA, 0, NA, NA, NA, NA, NA, NA, NA, NA, 30, 20, 17, 20, 26, 20, 19, 25, 23, 13, 16, NA, NA, 3, NA, NA)
testts = ts(testdata, freq=23)
bpp = bfastpp(testts)
bpp$season = cut(as.numeric(as.character(bpp$season)), 23*0.3)
bp = breakpoints(response~trend+season, data=bpp, h=23)
confint(bp)
#> Error in if (is.nan(p0) || p0 < a2 || p0 > (1 - a2)) {: missing value where TRUE/FALSE needed

Created on 2020-03-27 by the reprex package (v0.3.0)

There should be either some checks on https://github.com/bfast2/strucchange/blob/28bc6be918c4c2033f8de7d0a8bbe55a856cab0a/R/breakpoints.R#L622 or replace the is.nan with !is.finite on https://github.com/bfast2/strucchange/blob/28bc6be918c4c2033f8de7d0a8bbe55a856cab0a/R/breakpoints.R#L672.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions