{"spec_id":"coefficient-confidence","library":"highcharts","language":"javascript","code":"// anyplot.ai\n// coefficient-confidence: Coefficient Plot with Confidence Intervals\n// Library: highcharts 12.6.0 | JavaScript 22.23.2\n// Quality: 90/100 | Created: 2026-09-01\n\nconst t = window.ANYPLOT_TOKENS;\n// ANYPLOT_TOKENS has no \"muted\" field — derive the theme-adaptive muted-ink\n// anchor locally (see prompts/default-style-guide.md \"Theme-adaptive Chrome\").\nconst inkMuted = window.ANYPLOT_THEME === \"dark\" ? \"#A8A79F\" : \"#6B6A63\";\n\n// --- Data (in-memory, deterministic) ----------------------------------------\n// Coefficients from a multiple linear regression predicting housing prices\n// (thousands of USD per unit change), ordered by |coefficient| ascending so\n// the strongest effect sits at the top of the axis.\nconst coefficients = [\n  { variable: \"Age of Property (years)\", coefficient: -1.3, ciLower: -3.2, ciUpper: 0.6 },\n  { variable: \"Garage Spaces\", coefficient: 1.5, ciLower: -0.4, ciUpper: 3.4 },\n  { variable: \"Crime Rate Index\", coefficient: -2.1, ciLower: -4.5, ciUpper: 0.3 },\n  { variable: \"Lot Size (1,000 sq ft)\", coefficient: 2.8, ciLower: 0.9, ciUpper: 4.7 },\n  { variable: \"Number of Bedrooms\", coefficient: 3.6, ciLower: 1.5, ciUpper: 5.7 },\n  { variable: \"Distance to City Center (km)\", coefficient: -4.2, ciLower: -6.0, ciUpper: -2.4 },\n  { variable: \"School Rating (1-10)\", coefficient: 5.4, ciLower: 3.1, ciUpper: 7.7 },\n  { variable: \"Renovation Year (decade)\", coefficient: 6.1, ciLower: 3.8, ciUpper: 8.4 },\n  { variable: \"Square Footage (100 sq ft)\", coefficient: 8.9, ciLower: 6.7, ciUpper: 11.1 },\n].map((row, index) => ({\n  ...row,\n  index,\n  significant: row.ciLower > 0 || row.ciUpper < 0,\n}));\n\nconst categories = coefficients.map((row) => row.variable);\nconst significantRows = coefficients.filter((row) => row.significant);\nconst notSignificantRows = coefficients.filter((row) => !row.significant);\n\n// Highcharts core has no errorbar/columnrange series (highcharts-more is not\n// loaded), so each whisker is drawn as a two-point horizontal line segment;\n// a null point after every pair breaks the line before the next coefficient.\nconst whiskerData = (rows) =>\n  rows.flatMap((row) => [\n    [row.ciLower, row.index],\n    [row.ciUpper, row.index],\n    [null, null],\n  ]);\n\n// --- Chart -------------------------------------------------------------------\nHighcharts.chart(\"container\", {\n  chart: {\n    type: \"line\",\n    backgroundColor: \"transparent\",\n    animation: false,\n    style: { fontFamily: \"inherit\" },\n  },\n  credits: { enabled: false },\n  title: {\n    text: \"coefficient-confidence · javascript · highcharts · anyplot.ai\",\n    style: { color: t.ink, fontSize: \"22px\", fontWeight: \"600\" },\n  },\n  xAxis: {\n    title: { text: \"Coefficient Estimate ($1,000s per unit)\", style: { color: t.inkSoft, fontSize: \"16px\" } },\n    lineColor: t.inkSoft,\n    tickColor: t.inkSoft,\n    gridLineWidth: 1,\n    gridLineColor: t.grid,\n    labels: { style: { color: t.inkSoft, fontSize: \"14px\" } },\n    plotLines: [{ value: 0, color: t.inkSoft, width: 2, dashStyle: \"ShortDash\" }],\n  },\n  yAxis: {\n    categories,\n    title: { text: null },\n    lineColor: t.inkSoft,\n    tickColor: t.inkSoft,\n    gridLineWidth: 0,\n    labels: { style: { color: t.inkSoft, fontSize: \"14px\" } },\n  },\n  legend: {\n    itemStyle: { color: t.inkSoft, fontSize: \"14px\" },\n    itemHoverStyle: { color: t.ink },\n  },\n  plotOptions: {\n    series: { animation: false },\n    line: { marker: { enabled: false }, enableMouseTracking: false, showInLegend: false, lineWidth: 3 },\n    scatter: { marker: { radius: 8, lineColor: t.pageBg, lineWidth: 1.5 } },\n  },\n  series: [\n    { type: \"line\", name: \"CI (not significant)\", data: whiskerData(notSignificantRows), color: inkMuted },\n    { type: \"line\", name: \"CI (significant)\", data: whiskerData(significantRows), color: t.palette[0] },\n    {\n      type: \"scatter\",\n      name: \"Not significant (95% CI includes 0)\",\n      data: notSignificantRows.map((row) => ({ x: row.coefficient, y: row.index })),\n      color: inkMuted,\n    },\n    {\n      type: \"scatter\",\n      name: \"Significant (95% CI excludes 0)\",\n      data: significantRows.map((row) => ({ x: row.coefficient, y: row.index })),\n      color: t.palette[0],\n    },\n  ],\n});\n"}