amcphail/hmatrix-gsl-stats — pull request #2 by joachifm (2012-06-10 07:36:16+00:00)
Title: multifit: use no. of columns in X to allocate covmat and coef vector

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 using `mat' 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 of `y') 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 for `covmat' and `c' in `multifit' and
`multifit_w'.