data = FileAttachment("data/gentoo.csv").csv({ typed: true })
pred = data.map(
x => [{
bill_length_mm: x.bill_length_mm,
bill_depth_mm: x.bill_depth_mm,
pred: (x.bill_length_mm * slope) + intercept
}]
).flat()
xvalues = data.map(
x =>[
x.bill_length_mm
]
).flat()
yvalues = data.map(
y =>[
y.bill_depth_mm
]
).flat()
xrange = [d3.min(xvalues), d3.max(xvalues)]
yrange = [d3.min(yvalues), d3.max(yvalues)]
reg_line = xrange.map(
x => [{
x: x,
y: (x*slope)+intercept
}]
).flat()
sqe = d3.sum(pred.map(
foo => [
(foo.bill_depth_mm - foo.pred)**2
]
).flat()
)
lab = "SSqE= "
annotate = [
{
x: 42,
y: 17,
text: lab.concat(d3.format(".2f")(sqe))
}
]
Plot.plot({
y: {domain: yrange},
x: {domain: xrange},
inset: 8,
grid: true,
color: {
legend: true,
},
marks: [
Plot.dot(data, {x: "bill_length_mm", y: "bill_depth_mm"}),
Plot.link(pred,{
x1: "bill_length_mm",
x2: "bill_length_mm",
y1: "bill_depth_mm",
y2: "pred"
}),
Plot.line(reg_line, {
x: "x",
y:"y",
stroke: "#CC6677",
strokeWidth: 3
}),
Plot.text(annotate, {
x: "x",
y: "y",
text: "text"
}
)
]
})
Manual Regression
notes
Original scale
Centered predictor
Reuse
CC-BY 4.0
Citation
BibTeX citation:
@online{fruehwald,
author = {Fruehwald, Josef},
title = {Manual {Regression}},
url = {https://lin611-2024.github.io/notes/meetings/zz_residuals.html},
langid = {en}
}
For attribution, please cite this work as:
Fruehwald, Josef. n.d. “Manual Regression.” https://lin611-2024.github.io/notes/meetings/zz_residuals.html.