Categories &

Functions List

Function Reference: glmfit

statistics: b = glmfit (X, y, distribution)
statistics: b = glmfit (X, y, distribution,Name, Value)
statistics: [b, dev] = glmfit (…)

Perform generalized linear model fitting.

b = glmfit (X, y, distribution) returns a coefficient estimates vector, b for a generalized linear regression model of responses in y and predictors in X, using the distribution.

  • X is an n×p numeric matrix of predictor variables with n observations and p predictors.
  • y is a n× 1 numeric vector of responses for all supported distributions, except for the ’binomial’ distribution which can also have y as a n× 2 matrix, where the first column contains the number of successes and the second column contains the number of trials.
  • distribution specifies the distribution of the response variable (e.g., ’poisson’).

b = glmfit (…, Name, Value) specifies additional options using Name-Value pair arguments.

NameValue
"link"A character vector specifying a link function.
"constant"Specifies whether to include a constant term in the model. Options are "on" (default) or "off".

[b, dev] = glmfit (…) returns the estimated coefficient vector, b, as well as the deviance, dev, of the fit.

Supported distributions include ’poisson’, ’binomial’, and ’normal’. Supported link functions include ’identity’, ’log’, ’logit’, ’probit’, ’loglog’, ’comploglog’, ’reciprocal’ and a custom link. Custom link function provided as a structure with three fields: Link Function, Derivative Function, Inverse Function.

Source Code: glmfit

Example: 1

 

 rand ("seed", 1);
 X = rand (100, 1);
 b_true = [0.5; -1.2];
 mu = exp (b_true(1) + b_true(2) * X);
 randp ("seed", 1);
 y = poissrnd (mu);
 ## Fit a GLM model using the poisson distribution
 [b,dev] = glmfit (X, y, 'poisson');

                    

Example: 2

 

 x = [2100 2300 2500 2700 2900 3100 3300 3500 3700 3900 4100 4300]';
 n = [48 42 31 34 31 21 23 23 21 16 17 21]';
 y = [1 2 0 3 8 8 14 17 19 15 17 21]';
 [b,dev] = glmfit (x,[y n],'binomial','Link','probit');