Available: statistics:holtWinters() v1.269.0

The statistics:holtWinters() function is available from version 1.269.0.

The statistics:holtWinters() function models and forecasts a series of numeric values. The statistics:holtWinters() function uses the Holt-Winters method to produce forecasts. This method applies exponential smoothing to each of three components:

Component Description Smoothing parameter
Level The smoothed average value, without the seasonal effect baselineConstant (alpha)
Trend The change in level from one event to the next slopeConstant (beta)
Seasonal component A pattern that repeats every cycleLength events seasonalityConstant (gamma)

A cycle is one complete repetition of the seasonal pattern.

The model must learn the seasonal pattern before it can predict values. The model learns this pattern from the first two full cycles of events. This learning period is the warm-up. The warm-up contains 2 × cycleLength events.

The statistics:holtWinters() function writes each prediction to the as field. The as parameter sets the name of this field. By default, the as field is _prediction.

The statistics:holtWinters() function returns three types of events in the following order:

  • Warm-up events: The function returns the first 2 × cycleLength input events unchanged. These events have no prediction.

  • Input events with a prediction: The function adds the as field (default _prediction) to every later input event. The field contains the prediction of the model for that event.

  • Forecast events: The function adds new events after the last input event. Each forecast event contains a forecast value in the as field. It also contains a timestamp if the function can calculate one.

To select events by type, add a filter after the function. Filter on the fields that the function sets:

  • _prediction=* returns only events with a prediction, which includes forecast events. Use this filter to compare actual values with predicted values. If you set the as parameter, use that field name instead.

  • field!=* returns only forecast events. Use this filter to chart or export only the forecast. Replace field with the value of the field parameter.

Typical use cases include the following tasks:

  • Forecast the next values of a periodic metric. For example, forecast hourly request counts with a daily pattern (cycleLength=24).

  • Find anomalies by comparing actual values with predicted values. For example, pass the input field and the as field to a later math:rangeOutliers() call, or compare them with a plain comparison, such as test().

  • Extend a time series graph with a short forecast.

Example:

logscale
sort(@timestamp, order=asc)
| statistics:holtWinters(field=requests, cycleLength=24)

Example of anomaly detection:

logscale
sort(@timestamp, order=asc)
| statistics:holtWinters(field=requests, cycleLength=24)
| math:rangeOutliers(field=requests, low=_prediction * 0.8, high=_prediction * 1.2)

This query finds all time intervals where the number of incoming requests differs from the expected number by more than 20%. Warm-up events and forecast events lack one of the required fields. As a result, math:rangeOutliers() drops them.

Function Summary
Signaturestatistics:holtWinters([as], [baselineConstant], cycleLength, field, [forecastLength], [seasonalityConstant], [seasonalityMode], [slopeConstant])
Parameters for statistics:holtWinters()
ParameterTypeInterpreted TypeRequiredDefault ValueDescription
as stringoptional[a] _prediction The name of the as field. The value must be a field name. The default is _prediction. This field contains predictions on input events and forecast values on forecast events.
baselineConstant numberoptional[a] 0.3 The smoothing constant for the level, also called alpha. Higher values make the level follow recent events more closely.
   Minimum0 
   Maximum1 
cycleLength integerrequired   The number of events in one cycle.
   Minimum2 
field[b] stringrequired   The input field that contains the values to model. The value must be a field name. The function removes events with no numeric value in this field.
forecastLength integeroptional[a] 1 The number of forecast events to add after the last input event.
   Minimum1 
seasonalityConstant numberoptional[a] 0.1 The smoothing constant for the seasonal component, also called gamma. Higher values make the seasonal component follow recent cycles more closely.
   Minimum0 
   Maximum1 
seasonalityMode stringoptional[a] multiplicative The method that combines the seasonal component with the level. For more information, see Seasonality Modes.
    Values
    additiveThe seasonal component is a fixed offset that the model adds to the level.
    multiplicativeThe seasonal component is a factor. The seasonal effect increases and decreases with the level.
slopeConstant numberoptional[a] 0.1 The smoothing constant for the trend, also called beta. Higher values make the trend follow recent changes more closely.
   Minimum0 
   Maximum1 

[a] Optional parameters use their default value unless explicitly set.

[b] The parameter name field can be omitted.

Hide omitted argument names for this function

Show omitted argument names for this function

statistics:holtWinters() Function Operation

The statistics:holtWinters() function has specific implementation and operational considerations, outlined below.

Smoothing Constants

The smoothing constants control how quickly each component adapts.

Value Effect
0 The component keeps its initial estimate.
1 The component reflects only the latest value.
Any number from 0 to 1 The component changes gradually between these two extremes. A higher value moves it closer to the latest value.

Input Requirements

Event Order and Spacing

The statistics:holtWinters() function treats events as an ordered series. Each event is one step in the series.

The model ignores timestamps during modeling. For example, events one second apart count as one step. Events one hour apart also count as one step. As a result, cycleLength and forecastLength count events, not time units. The function reads timestamps only to place forecast events in time. For more information, see Forecast Phase.

The statistics:holtWinters() function processes events in the order that it receives them. To prepare the input, complete the following tasks:

  • Required: Sort the events before you call the function. In most queries, sort with sort(@timestamp, order=asc). Alternatively, sort on a bucket field.

  • Required: Space the events evenly.

  • Required for time-based cycles: Bucket the data into exactly one event for each time slot. Every time slot must contain an event, including slots with no activity.

Query Placement

The statistics:holtWinters() function is an aggregate function. Place it after another aggregate function, such as sort(), bucket(), or groupBy(). statistics:holtWinters() runs once on the full output of the previous aggregate function.

The statistics:holtWinters() function models one series per query. To model multiple groups, filter the data to one group first.

Note

Do not call the statistics:holtWinters() function inside a Cartesian products. For example, a stats() function can contain several functions that each return multiple events. This combination creates a cartesian product. In this case, the query fails.

Data from Persisted Aggregations

Data from readPersistedAggregation() is often evenly spaced. Each stored bucket covers one fixed time interval. For rolled-up data, each bucket covers one span. The @timestamp field of each bucket contains the start time of the bucket.

Some persisted aggregations produce one row for each bucket. For example, count() without groupBy() produces one row for each bucket. These rows form a series that the function can process directly. For more information, see Forecast from a persisted aggregation.

Behavior

The statistics:holtWinters() function processes events in three phases: warm-up, prediction, and forecast.

Warm-up Phase

The statistics:holtWinters() function collects the first 2 × cycleLength events with a numeric value in the input field. From these events, the function calculates the following initial estimates:

  • Level: The mean of the first cycle.

  • Trend: The difference in level between the first cycle and the second cycle.

  • Seasonal component: The distance of each cycle position above or below the average.

Next, the statistics:holtWinters() function processes the warm-up values one at a time, in sequence. This step refines the initial estimates.

Note

The statistics:holtWinters()function returns warm-up events unchanged. Warm-up events never contain the as field.

Prediction Phase

For each later event, the model performs the following steps in sequence:

  1. Predict: The model calculates a prediction and writes it to the as field. The prediction combines the level, one step of trend, and the current seasonal component. For more information, see Seasonality Modes.

  2. Update: The model reads the actual value and updates its components.

The model calculates each prediction before it reads the value of the event. As a result, the prediction is independent of that value. A large difference between the input field and the as field indicates an unusual event.

A prediction can be NaN or infinite. For example, input values near the largest double-precision value can cause an overflow. In this case, the function omits the prediction and reports a warning. For an input event, the function returns the event without the as field. For a forecast event, the function does not add the event.

Forecast Phase

After the last input event, the function adds forecast events. The forecastLength parameter sets the number of forecast events. Each forecast event has a position, called k. The first forecast event is position 1, the second is position 2, and so on. Forecast event k is k steps after the last input event.

Each forecast value combines the following values:

  • The last level.

  • k steps of trend.

  • The seasonal component at that cycle position.

The model learns only from input values. As a result, a long forecast repeats the last cycle along a straight trend line.

Each forecast event contains only the following fields:

  • The as field: The forecast value.

  • Timestamp field: The calculated time of the forecast event. By default, this field is @timestamp. If the query runs on ingest time, this field is @ingesttimestamp.

The function calculates each forecast timestamp with the following formula:

forecast timestamp = last input timestamp + (k × gap)

The gap is the time between the first two events with a numeric value. The function ignores the spacing of later events.

If either of the first two events lacks a timestamp, the gap is unknown. In this case, forecast events have no timestamp field. For example, some aggregations produce events without a timestamp.

Events Without a Numeric Value

The function removes events from the output where the field parameter has a missing or non-numeric value. These events do not count as steps in the series. The model runs as if these events do not exist.

The function does not insert replacement values. As a result, missing values shorten the series. Missing values can also shift the cycle positions of later events.

The string NaN is an exception. The function treats the string NaN as a numeric value, not as a non-numeric value. A NaN value propagates into the level and trend. As a result, all later predictions are NaN, and the function omits them.

Insufficient Data

The warm-up requires 2 × cycleLength events with a numeric value. If the input contains fewer events, the warm-up does not finish. In this case, the function performs the following actions:

  • Returns all events unchanged.

  • Adds no forecast events.

  • Reports a warning.

Seasonality Modes

The seasonalityMode parameter sets how the seasonal component combines with the level.

Mode Seasonal component Example data Recommended for
multiplicative (default) A factor. The seasonal effect increases and decreases with the level. Web traffic with a daily peak of about twice the daily average. Values that remain well above 0.
additive A fixed offset that the model adds to the level. A temperature that varies by about ±5 degrees every day. The size of this variation is independent of the average. Values with a constant variation size. Also values that can be 0 or negative.

In multiplicative mode, each seasonal factor is a ratio to the level. Levels near 0 can produce inaccurate or very large factors. Series that cross 0 can produce meaningless factors. For this type of data, select additive mode.

statistics:holtWinters() Syntax Examples

Each example sorts events by @timestamp in ascending order. Unless an example states otherwise, timestamps are one hour apart.

Timestamps are in Unix epoch milliseconds. For example, 1451606400000 is 1 January 2016, 00:00 UTC.

In the input and result listings, an empty value means that the event does not contain that field.

Quarterly sales

This example models and forecasts quarterly sales.

This example models six years of quarterly sales data. The data comes from the NIST/SEMATECH e-Handbook of Statistical Methods. Sales increase every year. The third quarter always has the highest sales.

The query sets the following parameter values:

  • cycleLength=4: One cycle is one year. As a result, the first two years are the warm-up.

  • forecastLength=4: The function forecasts the next year.

  • Smoothing constants: These values match the values in the handbook example.

Each @timestamp value is the start of its quarter, simplified to 90 days apart. This simplification keeps the series evenly spaced.

logscale
sort(@timestamp, order=asc)
| statistics:holtWinters(field=sales, cycleLength=4, forecastLength=4, baselineConstant=0.7556, slopeConstant=0, seasonalityConstant=0.9837)

If event data looks like this:

@timestampsales
1451606400000362
1459382400000385
1467158400000432
1474934400000341
1482710400000382
1490486400000409
1498262400000498
1506038400000387
1513814400000473
1521590400000513
1529366400000582
1537142400000474
1544918400000544
1552694400000582
1560470400000681
1568246400000557
1576022400000628
1583798400000707
1591574400000773
1599350400000592
1607126400000627
1614902400000725
1622678400000854
1630454400000661

it would return:

@timestampsales_prediction
1451606400000362<no value>
1459382400000385<no value>
1467158400000432<no value>
1474934400000341<no value>
1482710400000382<no value>
1490486400000409<no value>
1498262400000498<no value>
1506038400000387<no value>
1513814400000473472.6783251204108
1521590400000513512.819245596629
1529366400000582581.8711685205286
1537142400000474474.278735019053
1544918400000544543.887818599726
1552694400000582581.8391191906799
1560470400000681680.7583922694411
1568246400000557557.1718297096573
1576022400000628627.9805715539404
1583798400000707706.7063636443364
1591574400000773772.9033485285262
1599350400000592592.2817872743749
1607126400000627627.2181524515316
1614902400000725724.7498653945511
1622678400000854853.6157099345223
1630454400000661661.121647332818
1638230400000<no value>752.3916735092856
1646006400000<no value>809.2209663778008
1653782400000<no value>868.1841716231351
1661558400000<no value>695.4674617504612

The output contains all three types of events:

  • Warm-up events: Rows 1 to 8, the first two years.

  • Input events with a prediction: Rows 9 to 24, the third year to the sixth year.

  • Forecast events: Rows 25 to 28. These events are 90 days apart. They contain only the as field and the @timestamp field.

Predictions and a forecast

This example shows predictions and a forecast with a renamed as field.

In this example, cycleLength=2 sets a warm-up of 4 events. The fifth and sixth events receive a prediction. The function then adds one forecast event. The as parameter renames the as field to myForecast.

logscale
sort(@timestamp, order=asc)
| statistics:holtWinters(field=value, cycleLength=2, as=myForecast)

If event data looks like this:

@timestampvalue
145160640000010
145161000000012
14516136000009
145161720000013
145162080000011
145162440000014

it would return:

@timestampvaluemyForecast
145160640000010<no value>
145161000000012<no value>
14516136000009<no value>
145161720000013<no value>
1451620800000119.410829834119513
14516244000001413.134062139661907
1451628000000<no value>10.308574238130804
Multiple forecast steps

This example adds multiple forecast events.

In this example, forecastLength=2 adds two forecast events. These events are one step and two steps after the last input event. The input contains exactly the warm-up events. As a result, the function produces forecasts but no predictions on input events.

logscale
sort(@timestamp, order=asc)
| statistics:holtWinters(field=value, cycleLength=2, forecastLength=2)

If event data looks like this:

@timestampvalue
145160640000010
145161000000012
14516136000009
145161720000013

it would return:

@timestampvalue_prediction
145160640000010<no value>
145161000000012<no value>
14516136000009<no value>
145161720000013<no value>
1451620800000<no value>9.410829834119513
1451624400000<no value>12.440609260359615
Exact periodic series in additive mode

This example models an exact periodic series in additive mode.

In this example, the series 9, 5, 1, 5 repeats with cycleLength=4. The model starts with the following estimates:

  • Level: 5, the mean of one cycle.

  • Trend: 0.

  • Seasonal offsets: +4, 0, -4, and 0.

These estimates fit the series exactly. The query sets the following smoothing constants:

  • baselineConstant=0 and slopeConstant=0: The level and trend keep their initial estimates.

  • seasonalityConstant=1: Each seasonal offset equals the latest observed offset. The series fits exactly, so the offsets stay the same.

The forecast for the next position is 5 + 0 + 4 = 9.

logscale
sort(@timestamp, order=asc)
| statistics:holtWinters(field=value, cycleLength=4, seasonalityMode="additive", baselineConstant=0, slopeConstant=0, seasonalityConstant=1)

If event data looks like this:

@timestampvalue
14516064000009
14516100000005
14516136000001
14516172000005
14516208000009
14516244000005
14516280000001
14516316000005

it would return:

@timestampvalue_prediction
14516064000009<no value>
14516100000005<no value>
14516136000001<no value>
14516172000005<no value>
14516208000009<no value>
14516244000005<no value>
14516280000001<no value>
14516316000005<no value>
1451635200000<no value>9

All eight input events are warm-up events, so the function returns them unchanged. The forecast event is one hour after the last input event (_prediction = 9).

Forecast timestamps

This example shows how the function calculates forecast timestamps.

In this example, the first two events are 2000 milliseconds apart. Later events have different spacing. The function calculates forecast timestamps from the first gap only. As a result, the forecast events are 2000 and 4000 milliseconds after the last input event.

logscale
sort(@timestamp, order=asc)
| statistics:holtWinters(field=value, cycleLength=2, forecastLength=2)

If event data looks like this:

@timestampvalue
145160640000010
145160640200012
14516064030009
145160640900013

it would return:

@timestampvalue_prediction
145160640000010<no value>
145160640200012<no value>
14516064030009<no value>
145160640900013<no value>
1451606411000<no value>9.410829834119513
1451606413000<no value>12.440609260359615
Removal of events without the input field

This example shows that the function removes events without the input field.

In this example, two events lack the value field. The function removes these events. They do not count as steps in the series.

The remaining events contain the values 10, 12, 9, and 13. With these values, the forecast value is 9.410829834119513.

The first two remaining events are two hours apart. As a result, the forecast event is two hours after the last input event.

logscale
sort(@timestamp, order=asc)
| statistics:holtWinters(field=value, cycleLength=2)

If event data looks like this:

@timestampvalueother
145160640000010<no value>
1451610000000<no value>foo
145161360000012<no value>
14516172000009<no value>
1451620800000<no value>bar
145162440000013<no value>

it would return:

@timestampvalue_prediction
145160640000010<no value>
145161360000012<no value>
14516172000009<no value>
145162440000013<no value>
1451631600000<no value>9.410829834119513
Insufficient data

This example shows the result when the input is too short for the warm-up.

In this example, cycleLength=3 requires a warm-up of 6 events. The input contains only 5 events. As a result, the function returns the events unchanged. The function adds no forecast events and reports a warning.

logscale
sort(@timestamp, order=asc)
| statistics:holtWinters(field=value, cycleLength=3)

If event data looks like this:

@timestampvalue
14516064000001
14516100000002
14516136000003
14516172000004
14516208000005

it would return:

@timestampvalue
14516064000001
14516100000002
14516136000003
14516172000004
14516208000005
Constant series

This example models a constant series in both seasonality modes.

In this example, every value is 10. The function forecasts the same constant in both seasonality modes.

Query in multiplicative mode:

logscale
sort(@timestamp, order=asc)
| statistics:holtWinters(field=value, cycleLength=2)

Query in additive mode:

logscale
sort(@timestamp, order=asc)
| statistics:holtWinters(field=value, cycleLength=2, seasonalityMode="additive")

If event data looks like this:

@timestampvalue
145160640000010
145161000000010
145161360000010
145161720000010

both queries would return:

@timestampvalue_prediction
145160640000010<no value>
145161000000010<no value>
145161360000010<no value>
145161720000010<no value>
1451620800000<no value>10

The output holds the four events unchanged, followed by one forecast event with _prediction = 10.

Forecast from a persisted aggregation

This example forecasts values from a persisted aggregation.

In this example, a persisted aggregation with the tag hourlyRequests stores a count() result every hour. The query reads the aggregation with span="1h". This setting returns one row for each hour.

Each row contains the following fields:

  • _count: The number of requests in that hour.

  • @timestamp: The start of that hour.

The rows are evenly spaced, so the query requires no bucketing. The query sets the following parameter values:

  • cycleLength=24: The model learns a daily pattern.

  • forecastLength=24: The function forecasts the next day.

logscale
readPersistedAggregation("hourlyRequests", view="myView", span="1h", timezone="UTC")
| sort(@timestamp, order=asc, limit=max)
| statistics:holtWinters(field=_count, cycleLength=24, forecastLength=24)

The output contains the following events, in order:

  • Warm-up events: The first 48 hours, unchanged.

  • Input events with a prediction: Each later hour, with the as field (_prediction).

  • Forecast events: 24 events, one hour apart, after the last hour.

The series must be continuous (no gaps). A missing hour shortens the series and shifts the cycle. For more information, see Events Without a Numeric Value and Removal of events without the input field.

The function models one series only. If the persisted aggregation includes groupBy(), each bucket contains one row for each group. In this case, filter the data to a single group before you call statistics:holtWinters().

Click + next to an example below to get the full details.

Forecast Values With A Renamed Output Field

Predict and forecast seasonal values in a custom field using the statistics:holtWinters() function

Query
logscale
sort(@timestamp, order=asc)
| statistics:holtWinters(field=value, cycleLength=2, as=myForecast)
Introduction

In this example, the statistics:holtWinters() function is used to return predictions and a forecast of the number of escalated support tickets per shift. The as parameter renames the output field to myForecast.

The data contains one event for each 12-hour shift. The night shift starts at 20:00 and the day shift starts at 08:00. The day shift consistently has more escalated tickets than the night shift, so the pattern repeats every two events.

Example incoming data might look like this:

@timestampshiftvalue
2026-03-01T20:00:00Znight10
2026-03-02T08:00:00Zday12
2026-03-02T20:00:00Znight9
2026-03-03T08:00:00Zday13
2026-03-03T20:00:00Znight11
2026-03-04T08:00:00Zday14
Step-by-Step
  1. Starting with the source repository events.

  2. logscale
    sort(@timestamp, order=asc)

    Sorts the events by the @timestamp field in ascending order, so that the oldest event comes first.

    Sorting is required, because statistics:holtWinters() processes events in the order that it receives them and treats each event as one step in the series.

    As statistics:holtWinters() is an aggregate function, it must be placed after another aggregate function, such as sort(), bucket(), or groupBy().

    Note that sort() returns a maximum of 200 events by default. For longer series, set the limit parameter, for example, to max.

  3. logscale
    | statistics:holtWinters(field=value, cycleLength=2, as=myForecast)

    Applies Holt-Winters triple exponential smoothing to the values in the value field and returns the predictions and the forecast in a new field named myForecast.

    The function uses the following parameters:

    • The field parameter specifies the input field with the values to model, in this example value. The function removes events with a missing or non-numeric value in this field.

    • The cycleLength parameter specifies the number of events in one cycle. The value 2 matches the alternating night and day shifts. The value counts events, not time units.

    • The as parameter renames the output field to myForecast. If the parameter is not specified, statistics:holtWinters() returns the values in a field named _prediction.

    As no other parameters are specified, statistics:holtWinters() uses the following default values:

    The statistics:holtWinters() function first uses 2 × cycleLength events, in this example four events, as a warm-up to learn the seasonal pattern. It then adds a prediction to each later input event and finally adds the forecast event after the last input event.

  4. Event Result set.

Summary and Results

The query is used to model the number of escalated support tickets per shift, to return a prediction for each shift after the warm-up, and to forecast the number of tickets for the next shift.

This query is useful, for example, to plan staffing for upcoming shifts, or to detect shifts where the actual number of escalated tickets differs significantly from the predicted number.

Sample output from the incoming example data:

shiftvaluemyForecast 
2026-03-01T20:00:00Znight10<no value>
2026-03-02T08:00:00Zday12<no value>
2026-03-02T20:00:00Znight9<no value>
2026-03-03T08:00:00Zday13<no value>
2026-03-03T20:00:00Znight119.410829834119513
2026-03-04T08:00:00Zday1413.134062139661907
2026-03-04T20:00:00Z<no value><no value>10.308574238130804

Note that the first four events are warm-up events without the myForecast field, and that the last event is a forecast event that contains only the myForecast and @timestamp fields. The forecast timestamp is 12 hours after the last input event, based on the gap between the first two events.

Also note that the model counts events, not time, so the data must contain exactly one event for each shift. A large difference between the value field and the myForecast field indicates an unusual event.