Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possible bug in logLik() computation #78

Open
beanumber opened this issue Apr 4, 2024 · 2 comments
Open

possible bug in logLik() computation #78

beanumber opened this issue Apr 4, 2024 · 2 comments
Assignees

Comments

@beanumber
Copy link

I don't know if you will consider this a bug or not, but it baffled me for a while, so I'd figured I would report it.

data <- tidychangepoint::CET |>
  as.ts()

library(changepoint)
#> Loading required package: zoo
#> 
#> Attaching package: 'zoo'
#> The following objects are masked from 'package:base':
#> 
#>     as.Date, as.Date.numeric
#> Successfully loaded changepoint package version 2.2.4
#>  See NEWS for details of changes.

x <- cpt.meanvar(data, method = "PELT")
x@cpts
#> [1]  55  57 309 311 330 362
logLik(x)
#>      -2*logLik -2*Loglike+pen 
#>           -Inf           -Inf

y <- cpt.meanvar(data, method = "PELT", minseglen = 3)
y@cpts
#> [1] 237 330 362
logLik(y)
#>      -2*logLik -2*Loglike+pen 
#>       619.9626       656.9956

Created on 2024-04-04 with reprex v2.1.0

The problem occurs here, because there is a segment of length 2 with 0 variance, and thus the likelihood computation returns -Inf.

It seems weird to me that the algorithm works, but the logLik() returns -Inf. If not an error, perhaps at least a warning should be thrown?

@rkillick
Copy link
Owner

rkillick commented Apr 7, 2024

Yes, this is a "feature" :-)
The logLik() function should handle this in the same way that the C code handles segments with zero variance.
Thanks for catching!

@rkillick rkillick self-assigned this Apr 7, 2024
@beanumber
Copy link
Author

OK, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants