inst/doc/hmix.R

## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")

## ----forecast-----------------------------------------------------------------
library(hmix)
data(dummy_set)
y <- tail(dummy_set$AMZN.Close, 255)
train <- head(y, -5)
holdout <- tail(y, 5)

fit <- hmix(train, horizon = 5, centers = 4, n_hidden = 2,
            n_tests = 0, n_samples = 500, seed = 42)
names(fit$model)

## ----marginal-----------------------------------------------------------------
first <- fit$model$pred_funs$t1
first$qfun(c(0.1, 0.5, 0.9))
first$pfun(holdout[1])
first$rfun(5)

## ----paths--------------------------------------------------------------------
set.seed(123)
paths <- fit$model$random_path(3)
paths

## ----validate-----------------------------------------------------------------
validated <- hmix(train, horizon = 5, centers = 4, n_hidden = 2,
                  n_tests = 3, warmup = 0.6, n_samples = 500, seed = 42)
validated$error_sets$crps_set

## ----tune---------------------------------------------------------------------
grid <- data.frame(centers = c(3, 4), n_hidden = c(2, 2))
selection <- tune_hmix(train, horizon = 5, candidates = grid,
                       n_tests = 2, n_samples = 500, seed = 42)
selection$results[, c("centers", "n_hidden", "mean_crps", "error")]
selection$best

Try the hmix package in your browser

Any scripts or data that you put into this service are public.

hmix documentation built on Dec. 2, 2026, 1:09 a.m.