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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more