import React, { useState } from 'react'; interface DataPoint { x: number; y: number; isOutlier?: boolean; } const ScatterplotInteractiveWidget: React.FC = () => { const [showLine, setShowLine] = useState(false); const [showResiduals, setShowResiduals] = useState(false); const [hasOutlier, setHasOutlier] = useState(false); // Base Data (approx linear y = 1.5x + 10) const basePoints: DataPoint[] = [ {x: 1, y: 12}, {x: 2, y: 14}, {x: 3, y: 13}, {x: 4, y: 17}, {x: 5, y: 18}, {x: 6, y: 19}, {x: 7, y: 22}, {x: 8, y: 21} ]; const points: DataPoint[] = hasOutlier ? [...basePoints, {x: 7, y: 5, isOutlier: true}] : basePoints; // Simple Linear Regression Calculation const n = points.length; const sumX = points.reduce((a, p) => a + p.x, 0); const sumY = points.reduce((a, p) => a + p.y, 0); const sumXY = points.reduce((a, p) => a + p.x * p.y, 0); const sumXX = points.reduce((a, p) => a + p.x * p.x, 0); const slope = (n * sumXY - sumX * sumY) / (n * sumXX - sumX * sumX); const intercept = (sumY - slope * sumX) / n; const predict = (x: number) => slope * x + intercept; // Scales const width = 400; const height = 250; const maxX = 9; const maxY = 25; const toX = (val: number) => (val / maxX) * width; const toY = (val: number) => height - (val / maxY) * height; return (