Published
Edited
Nov 11, 2020
2 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
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function mle(Y, A, C) {
let AT = math.transpose(A);
let X = math.multiply(math.inv(
math.multiply(math.multiply(AT, math.inv(C)), A)), math.multiply(math.multiply(AT, math.inv(C)), Y));
let covX = math.inv(math.multiply(math.multiply(AT, math.inv(C)), A));
return {X:X, covX:covX}
}
Insert cell
function fit_data (data) {
let Y = math.matrix(data.map( d=> [d.y] ))
let A = math.matrix(data.map( d => [ 1.0, d.x ] ))
let C = math.diag( data.map( d=>d.sigma_y * d.sigma_y ))
let result = mle(Y, A, C)
return result;
}
Insert cell
function pprint_result(result) {
return mtex`\vec{w} = \begin{bmatrix}b \\ m \end{bmatrix}= ${MatrixToTex(result.X)}\;\; \mathrm{cov}(\vec{w}) = ${MatrixToTex(result.covX)}`
}
Insert cell
Insert cell
r = fit_data(hoggdata)
Insert cell
pprint_result(r)
Insert cell
Insert cell
r1 = fit_data(hoggdata.filter(x => x.id>4))
Insert cell
pprint_result(r1)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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