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

temp_holdout removes ts start date #4

Open
gehusi opened this issue Jul 30, 2018 · 0 comments
Open

temp_holdout removes ts start date #4

gehusi opened this issue Jul 30, 2018 · 0 comments

Comments

@gehusi
Copy link

gehusi commented Jul 30, 2018

The temp_holdout function resets the input time series to year 1, month 1. Since it requires the input to be a time series object, it should retain the start parameter of the input.

I've modified the function below.

function (dataset) 
{
    lapply(dataset, function(seriesentry) {
        frq <- stats::frequency(seriesentry$x)
        st <- stats::start(seriesentry$x)
        if (length(seriesentry$x) - seriesentry$h < max(2 * frq + 
            1, 7)) {
            length_to_keep <- max(2 * stats::frequency(seriesentry$x) + 
                1, 7)
            seriesentry$h <- length(seriesentry$x) - length_to_keep
            if (seriesentry$h < 2) {
                warning(paste("cannot subset series by", 2 - 
                  seriesentry$h, " observations, adding a mean constant"))
                seriesentry$x <- stats::ts(c(seriesentry$x, rep(mean(seriesentry$x), 
                  2 - seriesentry$h)), frequency = frq)
                seriesentry$h <- 2
            }
        }
        seriesentry$xx <- utils::tail(seriesentry$x, seriesentry$h)
        seriesentry$x <- stats::ts(utils::head(seriesentry$x, 
            -seriesentry$h), frequency = frq, start=st)
        if (!is.null(seriesentry$n)) {
            seriesentry$n <- length(seriesentry$x)
        }
        seriesentry
    })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant