bfast2 / bfast2/bfast

Low h parameter may result in fewer breaks

Open
#34 1 comment 0 reactions 0 assignees View on GitHub
question
Dominant language
R
Stars
53
Forks
16
PR merge metrics
No merged PRs in 30d

Description

In some cases, lowering _h_ might actually result in fewer breakpoints being detected. That is quite curious and may be good to check why that happens. An example was provided:

``` r
library(bfast)
set.seed(1234567)
opar = par(mfrow=c(1,2))
x <- rnorm(168,sd=1) # a vector without any inserted abrupt change
ts.plot(x)
bfast(ts(x),max.iter=1,season="none")
#> [1] "No seasonal model will be fitted!"
#>
#> TREND BREAKPOINTS: None
#>
#> SEASONAL BREAKPOINTS: None
y <- c(x[1:20],x[21:168]+1.5) # we insert an abrupt change from layer 20 onward
ts.plot(y)
```

![](https://i.imgur.com/7KWLT9a.png)

``` r
h <- seq(.05,.2,by=0.05) # a sequance of h to use in bfast function
R <- lapply(X=1:length(h), function(i){
bf = bfast(ts(y),h = h[i],max.iter=1,season="none")
if (!is.na(bf$output[[1]]$bp.Vt))
plot(bf$output[[1]]$bp.Vt)
bf
})
#> [1] "No seasonal model will be fitted!"
#> [1] "No seasonal model will be fitted!"
#> Warning in if (!is.na(bf$output[[1]]$bp.Vt)) plot(bf$output[[1]]$bp.Vt):
#> the condition has length > 1 and only the first element will be used
#> [1] "No seasonal model will be fitted!"
#> [1] "No seasonal model will be fitted!"
R
#> [[1]]
#>
#> TREND BREAKPOINTS: None
#>
#> SEASONAL BREAKPOINTS: None
#>
#>
#> [[2]]
#>
#> TREND BREAKPOINTS
#> Confidence intervals for breakpoints
#> of optimal 2-segment partition:
#>
#> Call:
#> confint.breakpointsfull(object = bp.Vt, het.err = FALSE)
#>
#> Breakpoints at observation number:
#> 2.5 % breakpoints 97.5 %
#> 1 19 20 26
#>
#> Corresponding to breakdates:
#> 2.5 % breakpoints 97.5 %
#> 1 19 20 26
#>
#> SEASONAL BREAKPOINTS: None
#>
#>
#> [[3]]
#>
#> TREND BREAKPOINTS: None
#>
#> SEASONAL BREAKPOINTS: None
#>
#>
#> [[4]]
#>
#> TREND BREAKPOINTS: None
#>
#> SEASONAL BREAKPOINTS: None
Rt = sapply(R, function(x)as.numeric(x$Time))
par(opar)
```

![](https://i.imgur.com/WjaEaAH.png)

``` r
data.frame(h=h,changepoint=Rt)
#> h changepoint
#> 1 0.05 NA
#> 2 0.10 20
#> 3 0.15 NA
#> 4 0.20 NA
```

Created on 2019-10-16 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)

Contributor guide

Open the contributing guide

Research direction

No source file or test is named. Start by running the provided R reprex with bfast() and compare the breakpoint results across h values from 0.05 to 0.2. Done means identifying why the lower h values produce fewer detected breakpoints and capturing the expected behavior in a regression test or issue resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.