Ha! The frequentists want in on the action? Let's make this a proper statistical showdown! 🥊
We'll extend our app to include frequentist methods and create a head-to-head comparison. Time to settle the age-old debate with interactive visualizations!
Updated Architecture: Bayesian vs Frequentist Showdown
Let's modify our existing structure to accommodate both approaches:
bayesian-vs-frequentist-app/
├── src/
│ ├── analog/
│ │ ├── components/
│ │ │ ├── bayesian-simulator.component.ts
│ │ │ ├── frequentist-simulator.component.ts
│ │ │ └── comparison-simulator.component.ts # NEW!
│ ├── pages/
│ │ ├── bayesian.astro
│ │ ├── frequentist.astro # NEW!
│ │ └── showdown.astro # NEW!
1. Enhanced Navigation
src/layouts/Layout.astro
---
interface Props {
title: string;
}
const { title } = Astro.props;
---
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<title>{title} - Statistical Modeling Showdown</title>
<style>
.nav-frequentist { background: linear-gradient(45deg, #dc2626, #ef4444); }
.nav-bayesian { background: linear-gradient(45deg, #2563eb, #3b82f6); }
.nav-showdown { background: linear-gradient(45deg, #7c3aed, #a855f7); }
</style>
</head>
<body>
<nav class="main-nav">
<div class="nav-brand">
<h1>📊 Statistical Showdown</h1>
</div>
<div class="nav-links">
<a href="/" class="nav-home">Home</a>
<a href="/bayesian" class="nav-bayesian">🔮 Bayesian</a>
<a href="/frequentist" class="nav-frequentist">📈 Frequentist</a>
<a href="/showdown" class="nav-showdown">⚔️ SHOWDOWN</a>
</div>
</nav>
<main>
<slot />
</main>
<style>
.main-nav {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem 2rem;
background: #1f2937;
color: white;
}
.nav-links {
display: flex;
gap: 1rem;
}
.nav-links a {
padding: 0.5rem 1rem;
border-radius: 0.5rem;
text-decoration: none;
color: white;
font-weight: bold;
transition: transform 0.2s;
}
.nav-links a:hover {
transform: scale(1.05);
}
</style>
</body>
</html>
2. Frequentist Simulator Component
src/analog/components/frequentist-simulator.component.ts
import { Component, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
interface ConfidenceInterval {
lower: number;
upper: number;
level: number;
}
@Component({
selector: 'frequentist-simulator',
standalone: true,
imports: [CommonModule, FormsModule],
template: `
<div class="frequentist-simulator">
<div class="frequentist-header">
<h2>📈 Frequentist Approach</h2>
<p class="motto">"In the long run, we'll figure it out!"</p>
</div>
<div class="controls">
<div class="sample-controls">
<label>Sample Size:
<input type="number" [(ngModel)]="sampleSize" (ngModelChange)="updateAnalysis()"
min="1" max="10000" step="1">
</label>
<label>Observed Successes:
<input type="number" [(ngModel)]="successes" (ngModelChange)="updateAnalysis()"
min="0" [max]="sampleSize">
</label>
<label>Confidence Level:
<select [(ngModel)]="confidenceLevel" (ngModelChange)="updateAnalysis()">
<option value="0.90">90%</option>
<option value="0.95">95%</option>
<option value="0.99">99%</option>
</select>
</label>
</div>
</div>
<div class="results-grid">
<div class="result-card">
<h3>Point Estimate</h3>
<div class="big-number">{{ pointEstimate | number:'1.3-3' }}</div>
<p>Maximum Likelihood Estimate (MLE)</p>
</div>
<div class="result-card">
<h3>Confidence Interval</h3>
<div class="interval">
[{{ confidenceInterval.lower | number:'1.3-3' }},
{{ confidenceInterval.upper | number:'1.3-3' }}]
</div>
<p>{{ (confidenceLevel * 100) }}% Confidence</p>
</div>
<div class="result-card">
<h3>Standard Error</h3>
<div class="big-number">{{ standardError | number:'1.4-4' }}</div>
<p>Uncertainty in estimate</p>
</div>
<div class="result-card">
<h3>P-Value</h3>
<div class="big-number">{{ pValue | number:'1.4-4' }}</div>
<p>Testing H₀: p = 0.5</p>
</div>
</div>
<div class="hypothesis-test">
<h3>Hypothesis Test Results</h3>
<div class="test-result" [class.reject]="rejectNull" [class.fail-to-reject]="!rejectNull">
<strong>{{ rejectNull ? 'REJECT' : 'FAIL TO REJECT' }}</strong> H₀: p = 0.5
</div>
<p>{{ testInterpretation }}</p>
</div>
<div class="frequentist-philosophy">
<h4>🎯 Frequentist Interpretation:</h4>
<ul>
<li>If we repeated this experiment many times, {{ (confidenceLevel * 100) }}% of confidence intervals would contain the true parameter</li>
<li>The p-value is the probability of observing this extreme data (or more) if H₀ were true</li>
<li>We either reject or fail to reject hypotheses - no "probability that H₀ is true"</li>
</ul>
</div>
</div>
`,
styles: [`
.frequentist-simulator {
padding: 1.5rem;
border: 3px solid #dc2626;
border-radius: 12px;
background: linear-gradient(135deg, #fef2f2, #ffffff);
}
.frequentist-header {
text-align: center;
margin-bottom: 2rem;
}
.motto {
font-style: italic;
color: #dc2626;
font-weight: bold;
}
.results-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 1rem;
margin: 2rem 0;
}
.result-card {
background: white;
padding: 1rem;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
text-align: center;
}
.big-number {
font-size: 2rem;
font-weight: bold;
color: #dc2626;
}
.interval {
font-size: 1.5rem;
font-weight: bold;
color: #dc2626;
font-family: monospace;
}
.test-result {
padding: 1rem;
border-radius: 8px;
font-size: 1.2rem;
text-align: center;
margin: 1rem 0;
}
.reject {
background: #fee2e2;
border: 2px solid #dc2626;
color: #dc2626;
}
.fail-to-reject {
background: #f0f9ff;
border: 2px solid #2563eb;
color: #2563eb;
}
.frequentist-philosophy {
background: #f9fafb;
padding: 1rem;
border-radius: 8px;
margin-top: 2rem;
}
`]
})
export class FrequentistSimulatorComponent implements OnInit {
sampleSize = 100;
successes = 50;
confidenceLevel = 0.95;
pointEstimate = 0.5;
standardError = 0;
confidenceInterval: ConfidenceInterval = { lower: 0, upper: 1, level: 0.95 };
pValue = 1;
rejectNull = false;
testInterpretation = '';
ngOnInit() {
this.updateAnalysis();
}
updateAnalysis() {
// Ensure valid inputs
this.successes = Math.min(this.successes, this.sampleSize);
this.successes = Math.max(0, this.successes);
// Point estimate (MLE)
this.pointEstimate = this.sampleSize > 0 ? this.successes / this.sampleSize : 0;
// Standard error
this.standardError = this.sampleSize > 0 ?
Math.sqrt(this.pointEstimate * (1 - this.pointEstimate) / this.sampleSize) : 0;
// Confidence interval (Wald method)
this.calculateConfidenceInterval();
// Hypothesis test (two-tailed test for p = 0.5)
this.calculateHypothesisTest();
}
calculateConfidenceInterval() {
const alpha = 1 - this.confidenceLevel;
const zScore = this.getZScore(alpha / 2);
const margin = zScore * this.standardError;
this.confidenceInterval = {
lower: Math.max(0, this.pointEstimate - margin),
upper: Math.min(1, this.pointEstimate + margin),
level: this.confidenceLevel
};
}
calculateHypothesisTest() {
const nullHypothesis = 0.5;
const standardErrorNull = Math.sqrt(nullHypothesis * (1 - nullHypothesis) / this.sampleSize);
const zStat = (this.pointEstimate - nullHypothesis) / standardErrorNull;
// Two-tailed p-value
this.pValue = 2 * (1 - this.normalCDF(Math.abs(zStat)));
// Decision at α = 0.05
this.rejectNull = this.pValue < 0.05;
this.testInterpretation = this.rejectNull ?
`Strong evidence against H₀. The coin appears biased (p ≠ 0.5).` :
`Insufficient evidence to conclude the coin is biased. Could be fair.`;
}
// Helper functions for statistical calculations
getZScore(alpha: number): number {
// Approximate inverse normal CDF for common confidence levels
const zScores: { [key: number]: number } = {
0.05: 1.645, // 90% CI
0.025: 1.96, // 95% CI
0.005: 2.576 // 99% CI
};
return zScores[alpha] || 1.96;
}
normalCDF(z: number): number {
// Approximation of standard normal CDF
return 0.5 * (1 + this.erf(z / Math.sqrt(2)));
}
erf(x: number): number {
// Approximation of error function
const a1 = 0.254829592;
const a2 = -0.284496736;
const a3 = 1.421413741;
const a4 = -1.453152027;
const a5 = 1.061405429;
const p = 0.3275911;
const sign = x >= 0 ? 1 : -1;
x = Math.abs(x);
const t = 1.0 / (1.0 + p * x);
const y = 1.0 - (((((a5 * t + a4) * t) + a3) * t + a2) * t + a1) * t * Math.exp(-x * x);
return sign * y;
}
}
3. Epic Showdown Component
src/analog/components/comparison-simulator.component.ts
import { Component, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
@Component({
selector: 'comparison-simulator',
standalone: true,
imports: [CommonModule, FormsModule],
template: `
<div class="showdown-arena">
<div class="arena-header">
<h1>⚔️ STATISTICAL SHOWDOWN ⚔️</h1>
<p class="tagline">Bayesian vs Frequentist: The Ultimate Face-Off!</p>
</div>
<div class="experiment-setup">
<h3>🎯 The Challenge: Coin Flip Analysis</h3>
<div class="setup-controls">
<label>Sample Size:
<input type="number" [(ngModel)]="sampleSize" (ngModelChange)="runShowdown()"
min="10" max="1000" step="10">
</label>
<label>True Probability (Hidden):
<input type="range" [(ngModel)]="trueProbability" (ngModelChange)="runShowdown()"
min="0.1" max="0.9" step="0.05">
<span>{{ trueProbability }}</span>
</label>
<button (click)="generateNewData()" class="generate-btn">🎲 Generate New Data</button>
</div>
<p><strong>Observed:</strong> {{ observedSuccesses }} successes out of {{ sampleSize }} trials</p>
</div>
<div class="competitors">
<!-- Bayesian Corner -->
<div class="competitor bayesian-corner">
<div class="corner-header">
<h2>🔮 BAYESIAN</h2>
<p class="fighting-style">"I update my beliefs!"</p>
</div>
<div class="stats">
<div class="stat">
<label>Posterior Mean:</label>
<span class="value">{{ bayesianResults.posteriorMean | number:'1.3-3' }}</span>
</div>
<div class="stat">
<label>95% Cre