amcphail / hmatrix-gsl-stats

GSL Statistics functions for Haskell hmatrix
BSD 3-Clause "New" or "Revised" License
6 stars 3 forks source link

multifit: use no. of columns in X to allocate covmat and coef vector #2

Closed joachifm closed 12 years ago

joachifm commented 12 years ago

A design matrix is a n \times p matrix, one column per coefficient. When specifying a design matrix, I expect the following to work:

let mat = fromColumns [ V.replicate 7 1         -- constant
                      , V.fromList (take 7 rng) -- x_1
                      , V.fromList (take 7 rng) -- x_2
                      ]

giving a (7><3) matrix, one column per predictor and a column for the intercept.

The multifit binding uses the size of y' to allocate storage for the coefficients (c') and the covariance matrix (covmat'). The result is that usingmat' above causes a crash:

gsl: multilinear.c:54: ERROR: number of parameters c does not
match columns of matrix X
Default GSL error handler invoked.

Here, c' will equal the number of observations (aka size ofy') and not the number of parameters (aka columns in `X').

Fix the problem by doing something like

let n = dim y   -- number of obs.
    p = cols x  -- number of params

and use p' to allocate storage forcovmat' and c' inmultifit' and `multifit_w'.