Overview
The statistics node computes rolling statistical measures over
a sliding window of incoming numeric values. Calculates mean, median, mode, standard deviation,
min/max, sum, count, and percentiles. Essential for real-time sensor monitoring, anomaly detection,
trend analysis, and data quality assessment on edge devices.
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| windowSize | number | 100 | Number of values in sliding window |
| operations | array | ["mean"] | mean, median, mode, stddev, min, max, sum, count, percentile |
| property | string | "payload" | Message property containing numeric value |
| percentileValue | number | 95 | Percentile to compute (1-99) |
| septopics | boolean | true | Maintain separate windows per topic |
Statistical Operations
Central Tendency
Measures of the center of data
mean: arithmetic average
median: middle value (sorted)
mode: most frequent value
Window: [22, 23, 23, 24, 25]
mean: 23.4
median: 23
mode: 23 Dispersion
Measures of data spread
stddev: standard deviation
min: minimum value
max: maximum value
Window: [22, 23, 23, 24, 25]
stddev: 1.02
min: 22
max: 25 Aggregation
Cumulative and positional metrics
sum: total of all values
count: number in window
percentile: value at Nth %
Window: [22, 23, 23, 24, 25]
sum: 117
count: 5
p95: 25 Example: Rolling Average of Temperature
Smooth noisy temperature readings using a rolling mean over the last 20 values.
// Statistics node configuration
{
"windowSize": 20,
"operations": ["mean", "min", "max"],
"property": "payload",
"septopics": true
}
// Flow: DHT22 sensor → statistics → dashboard gauge
// Incoming readings (noisy):
// 24.1, 24.8, 23.9, 24.5, 25.1, 24.3, 24.7, ...
// Output after 20 readings:
{
"payload": {
"mean": 24.42,
"min": 23.8,
"max": 25.1
},
"topic": "sensor/kitchen"
}
// The rolling mean smooths noise:
// Raw: 24.1, 24.8, 23.9, 25.1, 24.3, ...
// Average: 24.3, 24.4, 24.3, 24.4, 24.4, ...
// Much smoother for dashboard display Example: Anomaly Detection with Standard Deviation
Flag sensor readings that deviate more than 2 standard deviations from the mean.
// Statistics node configuration
{
"windowSize": 50,
"operations": ["mean", "stddev"],
"property": "payload.value"
}
// Flow: sensor → statistics → function (detect) → switch → alert
// Function node: Check for anomalies
var stats = msg.payload;
var current = msg.originalValue;
var zScore = Math.abs(current - stats.mean) / stats.stddev;
msg.payload = {
value: current,
mean: stats.mean,
stddev: stats.stddev,
zScore: zScore,
isAnomaly: zScore > 2.0 // Beyond 2 sigma
};
return msg;
// Normal reading: value=24.5, mean=24.3, stddev=0.8
// zScore = |24.5 - 24.3| / 0.8 = 0.25 → OK
//
// Anomaly: value=28.0, mean=24.3, stddev=0.8
// zScore = |28.0 - 24.3| / 0.8 = 4.63 → ALERT Common Use Cases
Sensor Smoothing
Rolling averages to reduce noise in readings
Anomaly Detection
Flag outliers using standard deviation thresholds
Performance Monitoring
Track P95/P99 latency for SLA compliance
Data Quality
Monitor value ranges and detect sensor drift