Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend Regression module to address first point in issue #67 #113

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

raibread
Copy link

@raibread raibread commented Dec 7, 2016

I extended olsRegress to the following settings with normally distributed errors

(1) homoskedastic errors, known variance
(2) homoskedastic errors, unknown variance
(3) heteroskedastic errors, known variance
(4) heteroskedastic errors, unknown variance

In case (4) will still assume that we known the diagonal matrix $W$ in the error covariance $var(\epsilon) = \sigma^2W$ but not $\sigma^2$. Case (4) addresses the first point specifically. The other cases are equally (or more) important from a statisticians point of view. In each case, standard errors for regression coefficients and overall model fit test statistics are computed along with their corresponding reference distributions.

I also provide example usage and implementation of Cholesky decomposition to use when extending the Regression module to eventually deal with regression error with arbitrary linear correlation structure (known as generalized least squares). This algorithm will also be useful if, in the future, one wanted to implement a version of R's glm.

Added two type classes, 'WeightedNormalRegress' and 'NormalRegress',
which have primary methods 'weightedNormalRegress' and 'normalRegress',
respectively, which run weigihted and ordinary least squares, again
respectively. These methods extend 'olsRegress' and compute regression
coefficient standard errors and an overall model fit test statistic
in addition to estimating the coefficients and returning the R-squared
goodness of fit metric. Both type classes have instances for when
the noise variance is unknown and when it is known. In both instances,
it is assumed that the noise is Gaussian.

Some auxiliary changes were needed to make these extensions to the
Regression module:

**(list below is of important addtions but is not exhaustive)**

  - A new error data type, 'TErr', which stores t-distributed errors
    was added to Statistics/Types.hs for coefficient standard errors
    when the noise variance is unknown.

  - A function 'diagOf' in the Statistics/Matrix.hs returns the
    diagonal of a square matrix. This is used to retrieve the standard
    errors of each regression coefficient in 'varCoeff'.

  - 'inv' in Statistics/Regression.hs can take the inverse of upper
    or lower triangular matrices (also needed in 'varCoeff'.

Some future-looking changes were made as well:

  - In anticipation of implementing generalized least square which
    allows for specifcation of arbitrary linear correlation structure
    across the noise component, this commit has implemented the
    Cholesky factorization 'chol' in Statistics/Matrix/Algorithms.hs.

  - 'solve' can now handle lower triangular matrices as well.
Previously extension of `solve` in Regression module to deal with
lower triangular matrices incorrectly used `rfor` for a forward
for loop. To resolve this issue and to still allow `solve` to work
for both with maximum code reusability I wrote a wrapper for `rfor`
and `for` in the Functions modules called `for_` that checks the
the start and end indices to determine which direction to run the
loop.
@Shimuuar
Copy link
Collaborator

Shimuuar commented Dec 7, 2016

Thank you I'' review it over the weekend

@ocramz
Copy link
Contributor

ocramz commented Mar 28, 2018

@raibread @Shimuuar are you still interested in merging this?

@Shimuuar
Copy link
Collaborator

Sorry I forgot about this PR. I really should add to readme that if I don't reapond for a long time one should ping me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants