File size: 3,109 Bytes
23d418f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { INK } from '@/lib/chart'
import type { Pair } from '@/lib/types'

const MIN = -0.1
const MAX = 0.5
const TICKS = [0, 0.1, 0.2, 0.3, 0.4, 0.5]

/** Paired comparisons: for each pair, the accuracy difference on the SAME questions as
 * a dot with its 95% interval, against a zero line; beside it what changed (fixed /
 * broken) and McNemar's p. A difference to a baseline is a dot-and-interval form, in
 * ink, not a system colour (each row is a pair, not a system). */
export function PairsPlot({ pairs }: { pairs: Pair[] }) {
  const x = (v: number) => ((v - MIN) / (MAX - MIN)) * 100 // percent of the track
  return (
    <div className="space-y-1">
      <div className="grid grid-cols-[6rem_1fr] gap-3 text-[11px] text-muted-foreground sm:grid-cols-[7rem_1fr_13rem]">
        <span />
        <div className="relative h-4">
          {TICKS.map((t) => (
            <span key={t} className="absolute -translate-x-1/2 tabular-nums" style={{ left: `${x(t)}%` }}>
              {t === 0 ? '0' : `+${Math.round(t * 100)}`}
            </span>
          ))}
        </div>
        <span className="hidden sm:block" />
      </div>
      {pairs.map((p) => {
        const [low, high] = [p.ci[0] ?? p.diff, p.ci[1] ?? p.diff]
        return (
          <div key={`${p.new}${p.base}`} className="grid grid-cols-[6rem_1fr] items-center gap-3 sm:grid-cols-[7rem_1fr_13rem]">
            <span className="text-sm font-medium">
              {p.new.toUpperCase()} vs {p.base.toUpperCase()}
              {p.primary && <span className="ml-1 text-[10px] font-normal text-muted-foreground">declared</span>}
            </span>
            <svg
              className="h-8 w-full overflow-visible"
              role="img"
              aria-label={`${p.new.toUpperCase()} vs ${p.base.toUpperCase()}: +${Math.round(p.diff * 100)} points, 95% interval +${Math.round(low * 100)} to +${Math.round(high * 100)}`}
            >
              {TICKS.map((t) => (
                <line key={t} x1={`${x(t)}%`} x2={`${x(t)}%`} y1="0" y2="100%" stroke={t === 0 ? INK.secondary : INK.grid} strokeWidth="1" />
              ))}
              <line x1={`${x(low)}%`} x2={`${x(high)}%`} y1="50%" y2="50%" stroke={INK.primary} strokeWidth="2" strokeLinecap="round" />
              <circle cx={`${x(p.diff)}%`} cy="50%" r="5" fill={INK.primary} stroke="white" strokeWidth="2">
                <title>
                  +{Math.round(p.diff * 100)} points (95% interval +{Math.round(low * 100)} to +{Math.round(high * 100)})
                </title>
              </circle>
            </svg>
            <span className="col-span-2 text-xs tabular-nums text-muted-foreground sm:col-span-1">
              <span className="font-medium text-foreground">+{Math.round(p.diff * 100)} pts</span> 路 {p.fixed} fixed 路{' '}
              {p.broken} broken 路 p {p.p < 0.001 ? '< 0.001' : `= ${p.p.toFixed(3)}`}
            </span>
          </div>
        )
      })}
      <p className="pt-1 text-[11px] text-muted-foreground">Accuracy difference in points on the same questions; the line is the 95% interval.</p>
    </div>
  )
}