การอนุมานเชิงสถิติ
Confidence intervals, hypothesis tests, regression and design of experiments
Why it matters
The data we collect is only a sample from the population we care about. Six test flights are not every flight this drone model will ever make. Statistical inference uses a sample to draw conclusions about the population and states how uncertain those conclusions are. In drone work it answers questions such as: does the drone meet its specification, is the new propeller really better or was that luck, how much extra power does another kilogram of payload cost, and how many tests are enough?
Confidence intervals
The sample mean x̄ is only an estimate of the true mean μ; a new sample would give a different x̄. The uncertainty of x̄ is the standard error, SE = s/√n. It shrinks as n grows, but slowly: halving SE takes four times the data.
A 95% confidence interval (CI) for the mean is x̄ ± t × SE, where t comes from the t distribution with n − 1 degrees of freedom. The t distribution replaces the normal because σ is unknown and estimated from s. For small n, t is clearly larger than 1.96. "95% confidence" correctly means that if the same experiment were repeated many times, intervals built this way would contain the true value about 95% of the time.
Hypothesis tests
A hypothesis test starts with a null hypothesis H0, the statement we look for evidence against, and an alternative H1. The significance level α, such as 0.05, is fixed before seeing the data. We then compute the p-value, the probability of a result at least this extreme if H0 were true. If p is below α, H0 is rejected.
There are two kinds of error. A Type I error rejects a true H0, with probability α. A Type II error fails to reject a false H0, with probability β; 1 − β is the power of the test. Failing to reject H0 therefore does not prove it; the data may simply be insufficient.
Worked example: hover power against a specification
Assume a specification requires mean electrical hover power below 250 W. Six independent flights give 242, 251, 238, 247, 255 and 244 W. The maker must show evidence of compliance, so H0: μ ≥ 250 and H1: μ < 250, at α = 0.05.
import numpy as np
from scipy import stats
p = np.array([242, 251, 238, 247, 255, 244.0]) # W
res = stats.ttest_1samp(p, popmean=250, alternative="less")
print(round(res.statistic, 2), round(res.pvalue, 3)) # -1.52 0.095
print(res.confidence_interval(0.95)) # one-sided upper bound
ci = stats.ttest_1samp(p, popmean=250).confidence_interval(0.95)
print(round(ci.low, 1), round(ci.high, 1)) # 239.7 252.6
- x̄ ≈ 246.2 W, s ≈ 6.18 W, SE ≈ 6.18/√6 ≈ 2.52 W.
- Test statistic t = (246.2 − 250)/2.52 ≈ −1.52; one-sided p ≈ 0.095.
- The two-sided critical t at 5 degrees of freedom is 2.571, so the 95% CI for μ is about 239.7 to 252.6 W.
Since p = 0.095 is above 0.05, H0 is not rejected. Six flights are not enough to demonstrate compliance, and the CI still includes 250 W. The correct conclusion is "not yet shown", not "fails", and certainly not "passes because the mean is below 250". The options are to collect more data or to reduce measurement variability.
Linear regression
Linear regression finds the line ŷ = b0 + b1x that minimises the sum of squared residuals (observed minus predicted). The slope b1 is the change in y per unit x, and it has its own confidence interval.
Assume hover power is measured at payloads of 0, 0.25, 0.5, 0.75 and 1.0 kg, giving 240, 262, 281, 305 and 327 W. The fitted line is ŷ ≈ 239.6 + 86.8x. The slope of 86.8 W/kg has SE ≈ 1.65 and a 95% CI of about 81.6 to 92.0 W/kg (t = 3.182 at 3 degrees of freedom). R2 ≈ 0.999, and the prediction at 0.6 kg is about 291.7 W.
A caution: momentum theory says hover power scales with mass to the power 3/2, so the true relation curves slightly. The straight line is good only within the measured range. Extrapolation, say to 3 kg, can be badly wrong, and a high R2 does not prove the model right. Check a residual plot as well.
Design of experiments
Design of experiments (DOE) plans which factors to vary, at what levels and with how many repeats, to reach reliable conclusions with as few runs as possible. Three basic principles apply: randomise the run order (to guard against things that drift with time, such as temperature or wind), replicate (to estimate variability) and block (to separate uncontrolled influences, such as the test day).
A 22 factorial experiment tests two factors at two levels each, all four combinations. It beats one-factor-at-a-time testing because it reveals interaction, whether one factor's effect depends on the level of the other. Assume two propeller sizes and two battery capacities, each combination flown twice in random order, with these means:
| Run | Propeller (A) | Battery (B) | Mean flight time (min) |
|---|---|---|---|
| 1 | small (−) | 4 Ah (−) | 18.0 |
| 2 | large (+) | 4 Ah (−) | 19.6 |
| 3 | small (−) | 5 Ah (+) | 21.1 |
| 4 | large (+) | 5 Ah (+) | 23.5 |
- Propeller main effect: (19.6 + 23.5)/2 − (18.0 + 21.1)/2 = 2.0 minutes.
- Battery main effect: (21.1 + 23.5)/2 − (18.0 + 19.6)/2 = 3.5 minutes.
- Interaction: (18.0 + 23.5)/2 − (19.6 + 21.1)/2 = 0.4 minutes. Small beside the main effects, but it must be compared with the replicate variability before calling it real.
How many tests?
The sample size per group for comparing two means is approximately n = 2(z1−α/2 + z1−β)2σ2/δ2, where δ is the difference worth detecting. With a flight-time standard deviation σ = 1.2 minutes, δ = 1.0 minute, α = 0.05 (z = 1.960) and 80% power (z = 0.842), n = 2 × (1.960 + 0.842)2 × 1.22/1.02 ≈ 22.6, rounded up to 23 flights per group. The number is usually larger than people expect, and it explains why three or four test flights so often end in "not enough data".
Common pitfalls
- Misreading the p-value. It is not the probability that H0 is true, and a small p does not mean a large or practically important effect.
- Concluding "no difference" when H0 is not rejected. Report the CI to show how large the plausible difference could be.
- Changing the test direction or α after seeing the data, which makes the p-value meaningless.
- Counting dependent data as independent samples. A thousand log points from one flight are not n = 1,000; the experimental unit is the flight.
- Running many comparisons and reporting only the significant ones. Twenty comparisons at α = 0.05 with no real differences are expected to give about one false positive.
- Extrapolating a regression beyond the data.
- Not randomising run order. Test the new propeller in calm morning air and the old one in gusty afternoons, and the difference is confounded with wind.
Continue in the lessons
Key references
- Montgomery, D. C., & Runger, G. C. (2018). Applied statistics and probability for engineers (7th ed.). Wiley. link
- NIST/SEMATECH. Confidence limits for the mean (section 1.3.5.2). e-Handbook of statistical methods. link
- NIST/SEMATECH. Two-sample t-test for equal means (section 1.3.5.3). e-Handbook of statistical methods. link
- NIST/SEMATECH. Linear least squares regression (section 4.1.4.1). e-Handbook of statistical methods. link
- Box, G. E. P., Hunter, J. S., & Hunter, W. G. (2005). Statistics for experimenters: Design, innovation, and discovery (2nd ed.). Wiley. link