Time Series Methods Based on Growth Curves
Overview
Provides tools for modelling and forecasting epidemic trajectories using a dynamic Gompertz model within a state space framework, with the Kalman filter for robust estimation of non-linear growth. Includes a reinitialization feature to adapt to new waves, and a leading-indicator extension that uses a related series moving ahead of the variable of interest (e.g. cases ahead of hospitalisations) to improve short-horizon forecasts, with model and lag selection via rolling-origin cross-validation. Applicable to data at daily, monthly, quarterly, or annual frequency, and to non-epidemic trajectories with similar dynamics, such as innovation diffusion and product adoption. Includes functions for data preprocessing, model fitting, forecast visualization, and accuracy evaluation using standard error measures. Methods are described in Harvey and Kattuman (2020) doi:10.1162/99608f92.828f40de, Harvey and Kattuman (2021) doi:10.1098/rsif.2021.0179, and Ashby, Harvey, Kattuman, Tang, and Thamotheram (2024) https://www.jbs.cam.ac.uk/wp-content/uploads/2024/03/cchle-tsgc-paper-2024.pdf.
Breaking changes
- Internal computation no longer relies on
xts/zoo. Series used during estimation and filtering are now represented with a new, dependency-freeidx_seriesclass, with calendar handling provided by a companionidx_calendarclass. Bundled datasets are unaffected and remainxtsobjects;xts_to_idx()is provided to convert user-suppliedxts/zoodata toidx_serieswhere needed. Code that relied on the internal (non-exported) representation of series may need to be updated. SSModelDynGompertzReinithas been deprecated. Its functionality is now provided directly bySSModelDynamicGompertzvia thereinit.idx,original.results, anduse.presample.infofields, so a single class now covers both the standard and reinitialised model.SSModelBasehas also been deprecated, with its logic folded intoSSModelDynamicGompertz.
Show all changes in 2.0.0Hide the rest of the changes in 2.0.0
- In
FilterResults, theconfidence_levelargument topredict_all()andget_gy_ci()has been renamed toconfidence.level, for consistency with naming elsewhere in the package. Calls that pass this argument by name will need to be updated. The default value ofsea.oninpredict_all()has also changed, fromFALSEtoTRUE. forecast_peak(),forecast.peak(), andplot_new_cases()have been deprecated.plot_new_cases()has been renamed toplot_forecast()as the growth curve theory extends beyond epidemiological settings.
New features
- Added a leading indicator model, via the new
SSModelLeadingIndicatorandFilterResultsLIreference classes, for modelling a target series using a leading series (see Harvey, A. (2021). "Time Series Modelling of Epidemics: Leading Indicators, Control Groups and Policy Assessment." *National Institute Economic Review*, 257, 83-100).FilterResultsLIprovidespredict_level(),predict_all(),get_growth_y(),get_gy_ci(),print(),summary(), andmapes()methods, parallelingFilterResultsfor the standard model. - Added five new example datasets:
ukitaly,gauteng_weather_2021,england_weather_2021,nintendo_sales, andetrading_apps, including weather data to support leading indicator examples. - Added
idx_series()and supporting methods (idx_cbind(),idx_rbind(),idx_diff(),idx_lag(),idx_range(),idx_values(),idx_positions(), and standard methods includinglength(),head(),tail(),as.matrix(),as.numeric(),as.double(), andprint()) as a dependency-free representation of time series for internal computation. - Added
idx_calendar()and supporting helpers (idx_step(),idx_to_date(),idx_calendar_offset(),idx_calendar_step(),idx_calendar_multi_step(), and related utilities) providing a consistent translation layer between integer positions and calendar dates for daily, weekly, monthly, quarterly, and annual data. - Added
get_timeframe(),idx_to_pos(),idx_offset_to_pos(), andidx_detect_calendar_pattern()to support the new indexing system. - Added
print_model_diagnostics()to surface model diagnostics more clearly. - Added
xts_to_idx()to convertxts/zooobjects to the internalidx_seriesrepresentation, for users supplying their ownxtsdata. - Added
cross_val()for cross-validating one or more models over a series of rolling estimation windows, andmapes()for computing mean absolute percentage errors from forecast results. - Added
df2ldl_lead()for handling two-column data for leading indicator models. - Added
print()andsummary()S3 methods forSSModelDynamicGompertz,SSModelLeadingIndicator,FilterResults, andFilterResultsLI. - Added new plotting functions
plot_compare_forecast()(compare forecasts across models),plot_log_forecast()(forecasts on the log scale), andplot_r0()(plot estimated reproduction numbers fromestimate_r0()). Also added plotting functionality for models (plot()takes in a model object) - Added a new set of accessor functions (
accessorFns.R) for extracting components from fitted model andKFSobjects, includingoutput(),modelKFS(),seasonalComp(),att(),Ptt(),get_V(),gety(),alphahat(), and a standaloneestimate()wrapper around a model'sestimate()method.
Improvements
- Substantially expanded plotting internals with helper functions (
idx_series_df(),idx_resolve_axis(),idx_axis_opts(),idx_x_scale(),idx_x_lab(),idx_add_info_box(), and related helpers) to give more consistent, better-labelled axes across all plot types, including support for non-daily frequencies. - Reduced the package's dependency footprint by removing reliance on
xts/zoofrom internal computation.
Bug fixes
- Various small fixes to filtering, forecasting, and plotting uncovered during the internal rewrite.
From NEWS.md in the release
Install
Health
- OK13 OK2026-08-04
- NOTE12 OK, 1 NOTE2026-08-01
- OK13 OK2026-06-09
- ERROR12 OK, 1 ERROR2026-06-08
- OK14 OK2026-03-10
Documentation
- Help pages
- 86
- Examples that run
- 100%48 run in a plain check
- Exported functions with examples
- 49%
- Documented parameters
- 92%
- Return-value docs
- 92%
- Help pages citing references
- 10%
Downloads
Repository
- PRs merged (all time)
- 71%
- Median days to close, 50 most recently updated closed issues
- not measured
- Median days to close, 50 most recently updated closed PRs
- 0
Stars over time
Forks over time
PRs over time
Commits over time
Commit identities over time
- github.com/craig-pt/tsgc · last recorded on 2026-08-30
4 development-tooling and community-health practices detected across 4 families in the upstream repository
Checks run against github.com/edwintang903/tsgc on 2026-10-25.
Dependencies
Code & Tests
Datasets
People & History
Previously maintained by Craig Thamotheram (0.0).
Pick two releases to compare their code metrics.
- 2.0.0Latest2026-09-01 · current release · diff ↗ ·
removed 5 exports
SSModelBase, SSModelDynGompertzReinit, forecast.peak, forecast_peak, plot_new_casesadded 42 exports
NCOL.idx_series, SSModelLeadingIndicator, as_idx_series, cross_val, df2ldl_lead, estimate, estimate_r0, get_V, get_timeframe, idx_axis_opts, idx_calendar, idx_calendar_multi_step, idx_calendar_offset, idx_calendar_step, idx_cbind, idx_diff, idx_lag, idx_ncol, idx_offset_to_pos, idx_positions, idx_range, idx_rbind, idx_series, idx_step, idx_step_add, idx_to_date, idx_to_pos, idx_values, is_idx_calendar, is_idx_series and 12 more - RR 4.6.0 released · 2026-04-24
- RR 4.5.0 released · 2025-04-11
- 0.02024-08-26
- RR 4.4.0 released · 2024-04-24
Package metadata
- First published
- 2024-08-26
- Total releases
- 2 / 2 yrs
- License
- GPL (>= 3) OSI
- Minimum R
- ≥ 3.5.0
- Bundled data
- 32 KB / 7 files
- Download size
- 526 KB
Cite
Cite this package
Run in R for the authors' preferred citation:
citation("tsgc")This package has no citation file, so citation() returns this entry built from DESCRIPTION.
Cite the R Observatory
For a number measured here: a download total, a coverage figure, an archival date.
From data release v2026-10-26, which the citation names so these numbers can be found later. More on citing and the projects behind them.