Public
Edited
Mar 12, 2024
1 fork
5 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
let X = [
[1, -1, 0],
[1, -1, 0],
[0, 1, -1],
[0, -1, 1],
[1, 0, -1],
[-1, 0, 1]
];
let y = [3, 2, 1, 2, 3, 1];

let M = math.multiply(math.transpose(X), X);
let n = M.length;
let last_row = math.ones(1, n).toArray().flat();
M[n - 1] = last_row;
let p = math.multiply(math.transpose(X), y);
p[n - 1] = 0;

return math.lusolve(M, p).flat();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
ratings = {
// Computing X and y
let X = big_south_games.map(function (d) {
let row = d3.range(10).map((d) => 0);
row[d.idx1] = 1;
row[d.idx2] = -1;
return row;
});
let y = big_south_games.map((d) => d.score1 - d.score2);

// Perform the Massey computation
let M = math.multiply(math.transpose(X), X);
let n = M.length;
let last_row = math.ones(1, n).toArray().flat();
M[n - 1] = last_row;
let p = math.multiply(math.transpose(X), y);
p[n - 1] = 0;
let ratings = math.lusolve(M, p).flat();

// Format the results:
let teams_with_ratings = d3
.sort(
d3.zip(
d3
.sort(
_.uniqBy(
big_south_games.map((d) => ({ name: d.name1, idx: d.idx1 })),
(o) => o.idx
),
(o) => o.idx
)
.map((o) => o.name),
ratings
),
(a) => -a[1]
)
.map((a) => ({ team: a[0], rating: Math.round(100 * a[1]) / 100 }));

// Return the results in a table:
return Inputs.table(teams_with_ratings);
}
Insert cell
Insert cell
big_south_games = FileAttachment("big_south_games.csv").csv({ typed: true })
Insert cell
import { big_south_chord_diagram } from "cbbe8ab362fb60e2"
Insert cell
math = require("mathjs")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more