21. llsq "data" Example

%  cat antelopes.ss

// From http://college.cengage.com/mathematics/brase/understandable_statistics/7e/students/datasets/mlr/frames/frame.html
// Thunder Basin Antelope Study
// The data (X1, X2, X3, X4) are for each year.
// X1 = spring fawn count/100
// X2 = size of adult antelope population/100
// X3 = annual precipitation (inches)
// X4 = winter severity index (1=mild,5=severe)
//
b0:c0 = { "Err", "Est" }; h0 = "Coeff";
fill d0:g1 {
"X1",	"X2",	"X3",	"X4",
2.9,	9.2,	13.2,	2,	// 8 sets of measured data
2.4,	8.7,	11.5,	3,
2,	7.2,	10.8,	4,
2.3,	8.5,	12.3,	2,
3.2,	9.6,	12.6,	3,
1.9,	6.8,	10.6,	5,
3.4,	9.7,	14.1,	1,
2.1,	7.9,	11.2,	3,
,	,	,	,
,	10,	10,	1,	// predict fawn count for these inputs
,	10,	10,	3,
,	10,	10,	5
};
{rank,h1:h3} = llsq("data",e1:g8,d1:d8);
b1:c8 = { c1-d1, dot($h$1:$h$3,e1:g1) };
h5 = sqrt(dot(b1:b8,b1:b8)); // norm(Err)
c10:c12 = { dot($h$1:$h$3,e10:g10) }; // predictions
eval; format h "%.6g"; print symbols values;

% SS -T antelopes.ss
 
  rank = 3
  $1 = {rank,H1:H3} = llsq("data",E1:G8,D1:D8) = 3
   B  C  D  E  F  G  H
0 Err Est X1 X2 X3 X4 Coeff
1 -0.02 2.88 2.90 9.20 13.20 2.00 0.32251
2 0.19 2.59 2.40 8.70 11.50 3.00 0.0103248
3 -0.01 1.99 2.00 7.20 10.80 4.00 -0.110479
4 0.35 2.65 2.30 8.50 12.30 2.00
5 -0.31 2.89 3.20 9.60 12.60 3.00 0.619503
6 -0.15 1.75 1.90 6.80 10.60 5.00
7 -0.24 3.16 3.40 9.70 14.10 1.00
8 0.23 2.33 2.10 7.90 11.20 3.00
9
10 3.22 10.00 10.00 1.00
11 3.00 10.00 10.00 3.00
12 2.78 10.00 10.00 5.00