Besides θ = 0, which θ leaves the variance exactly where it started?
Most bugs in this function leave θ off by some factor m. Put θ=mθ∗ into the parabola:
σY2Var(Y−mθ∗X)=1−ρ2m(2−m)
In words: the share of the variance left is 1 at m=0 and again at m=2, and lowest at m=1. At ρ=0.7:
θ
Variance left
0, no adjustment
1.00
0.5θ∗
0.63
θ∗, the slope
0.51
1.5θ∗
0.63
2θ∗
1.00
3θ∗
2.47
−θ∗, the flipped sign
2.47
Anything between 0 and 2θ∗ helps, and the floor is at the slope itself. At 2θ∗ the variance is back to the raw, as the eight users' bars showed, and past it the adjustment adds noise. Three of the practice problem's broken versions are points on this curve.
In the editor, adjust is ready. Write best_theta(y, x): the bottom of the U, exactly.
Pick an answer above to see the rest
Instructions
1
Write best_theta(y, x), the θ that gives y - theta * (x - x.mean()) the smallest variance. adjust is in the editor. One test uses a two-week pre-period against a one-week metric, so x varies about three times as much as y.