
Predict the baseline intensity trend at one or more future time points
Source:R/gof.R
predict_baseline_trend.RdDecomposes the estimated piecewise-constant log-baseline (est_time)
into a smooth trend component (via LOESS) and a seasonal/residual component,
following the same approach used in the application plot script. The fitted
trend is then extrapolated to target_times using
predict.loess() so that the baseline used for out-of-sample scoring
reflects the long-run level of activity rather than any arbitrary fixed
value.
Arguments
- model
A
redeem_resultobject with non-nullest_timeandtime_changepointsfields.- target_times
Numeric vector: the times at which to predict the trend (typically the unique timestamps of the test events).
- loess_span
Numeric; the span argument passed to
stats::loess. Larger values give a smoother (more conservative) trend extrapolation. Defaults to 0.75.
Value
A numeric vector of predicted log-baseline (trend component) values,
one per element of target_times. Falls back to
mean(est_time) for each time point if there are fewer than 3
observations or if the LOESS fit fails.
Details
The decomposition mirrors the plot code in the application:
Build a data frame of
(time, est_time)using the changepoints stored inmodel$time_changepoints. The first interval [0, changepoint_1) is given time = 0; each subsequent interval gets the corresponding changepoint value.Fit LOESS on the log-scale
est_timevalues.Predict at each
target_times; predictions are clamped to the range of the observedest_timeto avoid wild extrapolation.