gnu-octave / statistics

The Statistics package for GNU Octave
GNU General Public License v3.0
25 stars 24 forks source link

Implemented generalized linear model function `glmfit` #125

Closed ruchikasonagote closed 8 months ago

ruchikasonagote commented 8 months ago

Description

Issue

(https://github.com/gnu-octave/statistics/issues/49) Implementing multinomial regression and generalized linear models functions

TestCase

X = (1:20)';
beta_true = [1; 0.1];
mu_true = exp(beta_true(1) + beta_true(2) * X);
y = exp(mu_true);
distribution = 'poisson';
link = 'log';
beta = glmfit(X, y, distribution, link);
disp(beta);

ScreenShot of output

Screenshot from 2024-03-01 05-20-44

beta_true is similar to beta

pr0m1th3as commented 8 months ago

Thanks for the PR. It looks promising!

A few things to take care of:

  1. Restrict the texinfo docstring to 80 characters per line.
  2. Add a dot at the end error messages (Octave core doesn't do this, but Statistics do)
  3. Line comments should start with capitalized letter
  4. Add BISTs for testing input validation.
  5. Prefer warning ("glmfit: message.") instead of disp ('warning: ....')
  6. It it best to select the link functions and save them as a function handle before getting into your main loop. It is much faster this way.
  7. You could exploit fminsearch to compute beta.
  8. Use b instead of beta for returning argument to be more consistent with MATLAB.
  9. Keep in mind coding style
pr0m1th3as commented 8 months ago
  1. Use 2 spaces instead of 4 spaces for tab
  2. Parse the link argument as pair name-value style, to maintain MATLAB compatibility
ruchikasonagote commented 8 months ago

Sure, I will work on it.

pr0m1th3as commented 8 months ago

See the changes I 've made. Add input validation tests at the bottom using %!error syntax. Check other functions in statistics to get the idea

pr0m1th3as commented 8 months ago

I have merged this PR because I am about to make a new release. See the new issue about glmfit and let's continue there