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

[BUGZILLA #17527] stats::window() fails with start argument #6701

Open
MichaelChirico opened this issue May 19, 2020 · 1 comment
Open

[BUGZILLA #17527] stats::window() fails with start argument #6701

MichaelChirico opened this issue May 19, 2020 · 1 comment

Comments

@MichaelChirico
Copy link
Owner

Say we have a monthly time series starting from year 1998. We want to obtain the last value via window() function:

x = ts(1:20, start = 1998, frequency = 12)                                    
x                                                                             
 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec                                                                                                                                                                                           

1998 1 2 3 4 5 6 7 8 9 10 11 12
1999 13 14 15 16 17 18 19 20

window(x, start = c(1999, 8), end = c(1999, 8))
 Aug

1999 20

which is equivalent of

window(x, start = c(1999, 8))                                                 
 Aug                                                                                                                                                                                                                                       

1999 20

Now if we start the time series from A.D. 1,

x2 = ts(1:20, start = 1, frequency = 12)                                      
x2                                                                            

Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1 1 2 3 4 5 6 7 8 9 10 11 12
2 13 14 15 16 17 18 19 20

window(x2, start = c(2, 8), end = c(2, 8))

Aug
2 20

which is fine. But

window(x2, start = c(2, 8))                                                   

Error in window.default(x, ...) : 'start' cannot be after 'end'

sessionInfo()

R version 3.5.2 (2018-12-20)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)

Matrix products: default
BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/libmkl_rt.so

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
[4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached):
[1] compiler_3.5.2


METADATA

  • Bug author - Feng Li
  • Creation time - 2019-01-30 14:58:17 UTC
  • Bugzilla link
  • Status - UNCONFIRMED
  • Alias - None
  • Component - Analyses
  • Version - R 3.5.0
  • Hardware - All All
  • Importance - P5 normal
  • Assignee - R-core
  • URL -
  • Modification time - 2019-11-25 12:59 UTC
@MichaelChirico
Copy link
Owner Author

This seems to be a floating point issue. On my computer, when end is not present and the row name is 2 as in the example, the function calculates it with 2 + 7/12 shown as 2.5833333. This is greater than the value from the tsp[2] 2.583333. When end is provided it is 2.583333 (the same as from tsp[2]).

For the x example 1999.583 is for both the tsp[2] and (1999 + 7/12).

If in window.default() we changed the check to something like (start > end & !all.equal(start, end, .001)) that would work for this case, but obviously has other implications.


METADATA

  • Comment author - elin.waring
  • Timestamp - 2019-11-25 12:59:57 UTC

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

1 participant