| Contents | Index |
B = mnrfit(X,Y)
B = mnrfit(X,Y,param1,val1,param2,val2,...)
[B,dev] = mnrfit(...)
[B,dev,stats] = mnrfit(...)
B = mnrfit(X,Y) returns a matrix B of coefficient estimates for a multinomial logistic regression of the responses in Y on the predictors in X. X is an n-by-p matrix of p predictors at each of n observations. Y is an n-by-k matrix, where Y(i,j) is the number of outcomes of the multinomial category j for the predictor combinations given by X(i,:). The sample sizes for each observation are given by the row sums sum(Y,2).
Alternatively, Y can be an n-by-1 column vector of scalar integers from 1 to k indicating the value of the response for each observation, and all sample sizes are taken to be 1.
The result B is a (p+1)-by-(k–1) matrix of estimates, where each column corresponds to the estimated intercept term and predictor coefficients, one for each of the first k–1 multinomial categories. The estimates for the kth category are taken to be zero.
Note mnrfit automatically includes a constant term in all models. Do not enter a column of 1s directly into X. |
mnrfit treats NaNs in either X or Y as missing values, and ignores them.
B = mnrfit(X,Y,param1,val1,param2,val2,...) allows you to specify optional parameter name/value pairs to control the model fit. Parameters are:
'model' — The type of model to fit; one of the text strings 'nominal' (the default), 'ordinal', or 'hierarchical'
'interactions' — Determines whether the model includes an interaction between the multinomial categories and the coefficients. Specify as 'off' to fit a model with a common set of coefficients for the predictor variables, across all multinomial categories. This is often described as parallel regression. Specify as 'on' to fit a model with different coefficients across categories. In all cases, the model has different intercepts across categories. Thus, B is a vector containing k–1+p coefficient estimates when 'interaction' is 'off', and a (p+1)-by-(k–1) matrix when it is 'on'. The default is 'off' for ordinal models, and 'on' for nominal and hierarchical models.
'link' — The link function to use for ordinal and hierarchical models. The link function defines the relationship g(μij) = xibj between the mean response for the ith observation in the jth category, μij , and the linear combination of predictors xibj. Specify the link parameter value as one of the text strings 'logit'(the default), 'probit', 'comploglog', or 'loglog'. You may not specify the 'link' parameter for nominal models; these always use a multivariate logistic link.
'estdisp' — Specify as 'on' to estimate a dispersion parameter for the multinomial distribution in computing standard errors, or 'off' (the default) to use the theoretical dispersion value of 1.
[B,dev] = mnrfit(...) returns the deviance of the fit dev.
[B,dev,stats] = mnrfit(...) returns a structure stats that contains the following fields:
dfe — Degrees of freedom for error
s — Theoretical or estimated dispersion parameter
sfit — Estimated dispersion parameter
se — Standard errors of coefficient estimates B
coeffcorr — Estimated correlation matrix for B
covb — Estimated covariance matrix for B
t — t statistics for B
p — p-values for B
resid — Residuals
residp — Pearson residuals
residd — Deviance residuals
Fit multinomial logistic regression models to data with one predictor variable and three categories in the response variable:
x = [-3 -2 -1 0 1 2 3]';
Y = [1 11 13; 2 9 14; 6 14 5; 5 10 10; 5 14 6; 7 13 5;...
8 11 6];
bar(x,Y,'stacked'); ylim([0 25]);

% Now fit a nominal model for the individual response % category probabilities, with separate slopes on the % single predictor variable, x, for each % category: % The first row of betaHatNom contains the intercept terms % for the first two response categories. The second row % contains the slopes. betaHatNom = mnrfit(x,Y,'model','nominal',... 'interactions','on') % Compute the predicted probabilities for the three % response categories: xx = linspace(-4,4)'; pHatNom = mnrval(betaHatNom,xx,'model','nominal',... 'interactions','on'); line(xx,cumsum(25*pHatNom,2),'LineWidth',2);

Fit a "parallel" ordinal model for the cumulative response category probabilities, with a common slope on the single predictor variable, x, across all categories:
% The first two elements of betaHatOrd are the % intercept terms for the first two response categories. % The last element of betaHatOrd is the common slope. betaHatOrd = mnrfit(x,Y,'model','ordinal',... 'interactions','off') % Compute the predicted cumulative probabilities for the % first two response categories. The cumulative % probability for the third category is always 1. pHatOrd = mnrval(betaHatOrd,xx,'type','cumulative',... 'model','ordinal','interactions','off'); bar(x,cumsum(Y,2),'grouped'); ylim([0 25]); line(xx,25*pHatOrd,'LineWidth',2);

[1] McCullagh, P., and J. A. Nelder. Generalized Linear Models. New York: Chapman & Hall, 1990.
glmfit | glmval | mnrval | regress | regstats
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |