Files
2nd/10_Wiki/Topics/Frontend/대수의 법칙(Law of Large Numbers).md
T
koriweb d8a80f6272 chore(wiki): dangling 링크 canonical 정규화 (768파일/1200건)
이름만 다른(표기 변형) [[위키링크]]를 대상 문서의 canonical 제목으로 치환해
끊겼던 1,200개 링크를 연결. 제목/파일명 정규화 일치만 적용하고 별칭 매칭은
과병합 위험으로 제외(애매성 가드). 원본은 _link_reconcile_backup/ 에 백업.
도구: Datacollect/scripts/link_reconcile_apply.mjs

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-08 12:24:15 +09:00

169 lines
5.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
id: wiki-2026-0508-대수의-법칙-law-of-large-numbers
title: 대수의 법칙(Law of Large Numbers)
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [LLN, Law of Large Numbers, 큰 수의 법칙]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [statistics, probability, frontend-analytics, ab-testing]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
language: typescript
framework: analytics
---
# 대수의 법칙(Law of Large Numbers)
## 매 한 줄
> **"매 sample 수가 커질수록 sample mean 의 expected value 로의 수렴"**. 매 Bernoulli (1713) 의 weak LLN, Kolmogorov (1930) 의 strong LLN. 매 frontend analytics / A/B testing / RUM (Real User Monitoring) 의 통계적 정당성 — 매 sample 적으면 의미 X.
## 매 핵심
### 매 두 형태
- **Weak LLN**: $\bar{X}_n \xrightarrow{P} \mu$ — 매 probability convergence.
- **Strong LLN**: $\bar{X}_n \xrightarrow{a.s.} \mu$ — 매 almost sure convergence.
- 매 둘 다 finite mean μ 가정.
### 매 frontend 함의
- **A/B test sample size**: 매 N=100 의 noise 지배 — 매 N=10,000+ 필요 (effect size 의 함수).
- **Core Web Vitals p75**: 매 RUM 의 "75th percentile" — 매 N>1,000 sessions 권장 (Google).
- **Conversion rate stabilization**: 매 daily flux → weekly average 의 수렴.
- **Error rate monitoring**: 매 small traffic page 의 false alert.
### 매 응용
1. A/B test power analysis (sample size calculator).
2. Web Vitals percentile reliability.
3. Recommendation system click-through rate.
4. Survival analysis of user retention.
## 💻 패턴
### Sample size for A/B test
```typescript
// Two-proportion z-test, 80% power, α=0.05
function abTestSampleSize(
baselineRate: number,
minDetectableEffect: number,
): number {
const p1 = baselineRate;
const p2 = baselineRate + minDetectableEffect;
const pBar = (p1 + p2) / 2;
const z_alpha = 1.96; // two-sided 0.05
const z_beta = 0.84; // power 0.80
const numerator =
Math.pow(z_alpha * Math.sqrt(2 * pBar * (1 - pBar)) +
z_beta * Math.sqrt(p1 * (1 - p1) + p2 * (1 - p2)), 2);
return Math.ceil(numerator / Math.pow(p2 - p1, 2));
}
// Baseline 5% conversion, want to detect +1 percentage point lift
console.log(abTestSampleSize(0.05, 0.01)); // ~3,000 per arm
```
### Running mean (LLN visualizer)
```typescript
function* runningMean(samples: Iterable<number>) {
let n = 0;
let mean = 0;
for (const x of samples) {
n += 1;
mean += (x - mean) / n; // Welford
yield { n, mean };
}
}
// Coin flip (true mean = 0.5)
const flips = Array.from({ length: 10000 }, () => (Math.random() < 0.5 ? 1 : 0));
for (const { n, mean } of runningMean(flips)) {
if (n % 1000 === 0) console.log(`n=${n}, mean=${mean.toFixed(4)}`);
}
// n=1000 mean ≈ 0.49
// n=10000 mean ≈ 0.50 (LLN convergence)
```
### Web Vitals percentile reliability check
```typescript
import { onLCP } from 'web-vitals';
const lcpSamples: number[] = [];
onLCP((metric) => {
lcpSamples.push(metric.value);
if (lcpSamples.length >= 1000) {
const sorted = [...lcpSamples].sort((a, b) => a - b);
const p75 = sorted[Math.floor(sorted.length * 0.75)];
sendBeacon({ p75, n: lcpSamples.length });
}
});
// p75 trustworthy only after N>1,000 (Google CrUX guidance)
```
### Bayesian early-stopping (avoid LLN trap)
```typescript
// Don't peek at A/B test before sample size reached!
function shouldStop(arm: { successes: number; trials: number }, target: number) {
if (arm.trials < target) return false;
// proceed to analysis
return true;
}
```
### Bootstrap confidence interval
```typescript
function bootstrapCI(samples: number[], B = 10000, alpha = 0.05) {
const means: number[] = [];
for (let b = 0; b < B; b++) {
let sum = 0;
for (let i = 0; i < samples.length; i++) {
sum += samples[Math.floor(Math.random() * samples.length)];
}
means.push(sum / samples.length);
}
means.sort((a, b) => a - b);
return [
means[Math.floor(B * (alpha / 2))],
means[Math.floor(B * (1 - alpha / 2))],
];
}
```
## 매 결정 기준
| 상황 | Sample size guideline |
|---|---|
| Web Vitals p75 (Google CrUX) | N > 1,000 sessions per page |
| A/B test (5% baseline, 1pp lift) | ~3,000 per arm |
| Click-through rate stabilization | N > 10,000 impressions |
| Error rate monitoring (rare events) | Apply Poisson, not LLN naively |
**기본값**: 매 결과 보고 전 N≥1,000 — 매 LLN safety zone.
## 🔗 Graph
- 부모: [[Probability Theory]] · [[Statistical Inference]]
- 응용: [[Core Web Vitals Optimization (INP, LCP, CLS)|Core Web Vitals]]
- Adjacent: [[Monte Carlo Methods]]
## 🤖 LLM 활용
**언제**: 매 sample size 결정 / 매 metric 의 reliability 의 statistical 정당화 / 매 small-N false-positive 의 진단.
**언제 X**: 매 비-i.i.d. data (autocorrelated time series) — 매 LLN naive 적용 X. 매 stationarity 확인.
## ❌ 안티패턴
- **Peeking at A/B test**: 매 N=50 에서 "winner" 선언 — 매 LLN 미달 + multiple testing.
- **Rare event LLN**: 매 0.01% conversion → 매 N=1000 의 평균 0 가능. 매 Poisson 필요.
- **Heavy-tail distribution**: 매 Cauchy (no finite mean) — 매 LLN 미적용.
- **Selection bias**: 매 sample 이 random 이 X — 매 N 무관 의 biased estimate.
## 🧪 검증 / 중복
- Verified (Kolmogorov, "Foundations of Probability"; Google web.dev — Web Vitals reporting).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — LLN with frontend analytics applications |