The weights are the set that makes the total miss smallest
Use one rule to estimate twenty flats, and each estimate will be a little high or a little low. Square each flat's miss and add them up, and you have the rule's total miss:
S=i=1∑20(yi−y^i)2
yi is the actual rent of flat i and y^i is the rule's estimate. The smaller S is, the closer the rule is to the real rents. You square before adding because if you simply added, an estimate 200 yuan too high and one 200 yuan too low would cancel out to zero. Squaring also magnifies big errors: a miss of 600 yuan, squared, is nine times a miss of 200 squared. So to make S small, the weights bend first toward the few flats that are furthest off.
Back to the rule that guessed 30 yuan: it undercounts each square meter by 10 yuan, so the 68-square-meter flat comes out 680 yuan lower than it would at 40 yuan. Regression doesn't need to try one setting after another like this. It solves directly for the set of weights that makes S smallest, a method called least squares. In a regression table, the fitted weights are called coefficients.
Add a variable, and the coefficient already there changes
Suppose you get hold of a company's payroll. Fit it with years of service alone, and each extra year adds 900 yuan to monthly pay. Put in "has a master's degree" as well, and the years-of-service term drops to 400 yuan a year, while the master's term is 3,000 yuan.
In its early years the company hired only people with master's degrees, so many of the long-serving staff have one. Looking at years of service alone, part of the higher pay of long-serving staff came from their degrees, but it was credited to years of service; put the degree in, and that part goes back to the degree. Write monthly pay as y and years of service as t, and let d=1 for a master's degree and d=0 for a bachelor's. The fitted formula is:
y=8000+400t+3000d
With the same degree, d doesn't change, and then one year's difference in service makes only 400 yuan of difference in monthly pay. With the same years of service, someone with a master's earns 3,000 yuan more than someone with a bachelor's.
When two variables rise and fall almost together, their separate coefficients can't be read reliably
Fit body weight on left foot length and right foot length together. If someone's left foot is a centimeter longer, their right foot is almost always about a centimeter longer too. So as long as the two coefficients add up to the right total, however that total is split between left and right, the estimated weights come out about the same. As a result, one group of people may give the left foot a big coefficient and the right foot a small one, and another group may give the exact opposite, while the two added together barely move.
Linear regression works best when the factors don't interfere with one another, when a little more of each one adds a little more to the result, and when what you want to know is exactly how much the result changes when one factor alone goes up by one unit. Dose and body weight do pull on each other: the same dose acts differently on a light person and a heavy one, so a single weight for dose can't get it right.
Ranking factors by the size of their coefficients goes wrong, because a coefficient follows its unit. Change one factor's unit from meters to millimeters and its coefficient shrinks a thousandfold, while what the factor does hasn't changed at all. The formula has also only been tested within the range the data covers. Fit the heights of children aged three to ten and you get six centimeters of growth a year; carry that on to age thirty, and a person would be 2.5 meters tall.