Skip to content

Commit 481f7a1

Browse files
committed
feat(croston): print the demand and interval
1 parent 89c690f commit 481f7a1

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

R/croston.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ croston_model <- function(
144144
alpha = alpha,
145145
type = type,
146146
init = init,
147+
init_demand = init_demand,
148+
init_interval = init_interval,
147149
y = y,
148150
fit_demand = res$fit_demand,
149151
fit_interval = res$fit_interval,
@@ -233,6 +235,14 @@ print.croston_model <- function(
233235
cat("Call:", deparse(x$call), "\n\n")
234236
cat("alpha:", format(x$alpha, digits = digits), "\n")
235237
cat("method:", x$type, "\n")
238+
cat(
239+
"initial:",
240+
"demand =",
241+
format(x$init_demand, digits = digits),
242+
", interval =",
243+
format(x$init_interval, digits = digits),
244+
"\n"
245+
)
236246
invisible(x)
237247
}
238248

tests/testthat/test-croston.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ test_that("croston_model with numeric init and optimized alpha", {
5555
expect_equal(fit$fit_interval[1], 2)
5656
})
5757

58+
test_that("croston_model stores resolved initial values", {
59+
fit <- croston_model(y, init = c(3, 2))
60+
expect_equal(fit$init_demand, 3)
61+
expect_equal(fit$init_interval, 2)
62+
63+
fit_opt <- croston_model(y, alpha = NULL, init = "mean")
64+
expect_equal(fit_opt$init_demand, fit_opt$fit_demand[1])
65+
expect_equal(fit_opt$init_interval, fit_opt$fit_interval[1])
66+
})
67+
5868
test_that("croston_model errors on invalid init", {
5969
expect_error(croston_model(y, init = c(3)), "length 2")
6070
expect_error(croston_model(y, init = c(-1, 2)), "non-negative")

0 commit comments

Comments
 (0)