;
; GNP.deflator  GNP   Unemployed Armed.Forces Population Year Employed
(define longley (matrix
'(83.0  234.289 235.6 159.0 107.608 1947 60.323 
  88.5  259.426 232.5 145.6 108.632 1948 61.122 
  88.2  258.054 368.2 161.6 109.773 1949 60.171 
  89.5  284.599 335.1 165.0 110.929 1950 61.187 
  96.2  328.975 209.9 309.9 112.075 1951 63.221 
  98.1  346.999 193.2 359.4 113.270 1952 63.639 
  99.0  365.385 187.0 354.7 115.094 1953 64.989 
  100.0 363.112 357.8 335.0 116.219 1954 63.761 
  101.2 397.469 290.4 304.8 117.388 1955 66.019 
  104.6 419.180 282.2 285.7 118.734 1956 67.857 
  108.4 442.769 293.6 279.8 120.445 1957 68.169 
  110.8 444.546 468.1 263.7 121.950 1958 66.513 
  112.6 482.704 381.3 255.2 123.366 1959 68.655 
  114.2 502.601 393.1 251.4 125.368 1960 69.564 
  115.7 518.173 480.6 257.2 127.852 1961 69.331 
  116.9 554.894 400.7 282.7 130.081 1962 70.551) 16 7))

(define longley2 (matrix
'(830/10  234289/1000 2356/10 1590/10 107608/1000 1947 60323/1000 
  885/10  259426/1000 2325/10 1456/10 108632/1000 1948 61122/1000 
  882/10  258054/1000 3682/10 1616/10 109773/1000 1949 60171/1000 
  895/10  284599/1000 3351/10 1650/10 110929/1000 1950 61187/1000 
  962/10  328975/1000 2099/10 3099/10 112075/1000 1951 63221/1000 
  981/10  346999/1000 1932/10 3594/10 113270/1000 1952 63639/1000 
  990/10  365385/1000 1870/10 3547/10 115094/1000 1953 64989/1000 
  1000/10 363112/1000 3578/10 3350/10 116219/1000 1954 63761/1000 
  1012/10 397469/1000 2904/10 3048/10 117388/1000 1955 66019/1000 
  1046/10 419180/1000 2822/10 2857/10 118734/1000 1956 67857/1000 
  1084/10 442769/1000 2936/10 2798/10 120445/1000 1957 68169/1000 
  1108/10 444546/1000 4681/10 2637/10 121950/1000 1958 66513/1000 
  1126/10 482704/1000 3813/10 2552/10 123366/1000 1959 68655/1000 
  1142/10 502601/1000 3931/10 2514/10 125368/1000 1960 69564/1000 
  1157/10 518173/1000 4806/10 2572/10 127852/1000 1961 69331/1000 
  1169/10 554894/1000 4007/10 2827/10 130081/1000 1962 70551/1000) 16 7))


  (define (reg XY) 
    (let* ((nv (+ (ncol XY) 1)) (W (cbind (matrix 1 (nrow XY) 1) XY)))
      (let loop ((i 1) (A (matmult (transpose W) W))) 
        (if (= i nv) 
           (col A nv)
           (loop (+ i 1) (sweep A i))))))
