import graph3;
import math; // for the leastsquares routine
Billboard.targetsize = true; // Perspective should not affect the labels.
currentprojection = perspective(60 * (5, 2, 3));
file duncan = input("linearregression.dat");
string headers = duncan;
real[][] independentvars;
real[] dependentvars;
while (!eof(duncan)) {
string line = duncan;
string[] entries = split(line);
if (entries.length < 5) continue;
string type = entries[1];
real income = (real)(entries[2]);
real education = (real)(entries[3]);
real prestige = (real)(entries[4]);
// include 1.0 for the residue
independentvars.push(new real[] {income, education, 1.0});
dependentvars.push(prestige);
}
real[] coeffs = leastsquares(independentvars, dependentvars, warn=false);
if (coeffs.length == 0) {
abort("Unable to find regression: independent variables are "
+ "linearly dependent.");
}