Categories &

Functions List

Function Reference: mnrval

statistics: pihat = mnrval (B, X)
statistics: [pihat, dlo, dhi] = mnrval (B, X, stats)
statistics: yhat = mnrval (B, X, ssize)
statistics: [yhat, dlo, dhi] = mnrval (B, X, ssize, stats)
statistics: […] = mnrval (…, name, value)

Predict values for a multinomial logistic regression model.

pihat = mnrval (B, X) returns the predicted category probabilities pihat of a multinomial logistic regression with coefficients B, evaluated at the predictor values in X. X is an N×P numeric matrix of N observations on P predictors. pihat is an N×K matrix, where K is the number of response categories and each row sums to one. B is the coefficient matrix returned by mnrfit (see below for its shape under each model).

mnrval is the prediction companion of mnrfit. Unlike the current mnrfit, which only fits ordinal and two-category nominal models, mnrval evaluates all three model types, so a coefficient matrix B obtained elsewhere (e.g. MATLAB) can be used for prediction.

yhat = mnrval (B, X, ssize) returns predicted category counts instead of probabilities, for the sample sizes in ssize (a scalar or an N×1 vector).

[pihat, dlo, dhi] = mnrval (B, X, stats) also returns 95% confidence bounds on the predictions. stats is the structure returned by mnrfit; its 'covb' field (the coefficient covariance matrix) is required. The confidence interval for each prediction is [pihat - dlo, pihat + dhi]. The bounds are nonsimultaneous and apply to the fitted values, not to new observations.

The following Name-Value pairs control the model:

NameValue
'model'The model type: 'nominal' (default), 'ordinal', or 'hierarchical'.
'interactions''on' to include category-specific coefficients, or 'off' for a common set of coefficients with category-specific intercepts only. Default is 'on' for nominal and hierarchical models and 'off' for ordinal models. With 'interactions','on', B is a (P+1)×(K-1) matrix. With 'interactions','off', B is a (K-1+P)×1 vector holding the K-1 intercepts followed by the P common slopes.
'link'The link function for ordinal and hierarchical models: 'logit' (default), 'probit', 'comploglog', or 'loglog'. Nominal models always use the multinomial logit link.
'type'The kind of probability returned: 'category' (default, N×K category probabilities), 'cumulative' (N×(K-1) cumulative probabilities of the first K-1 categories), or 'conditional' (N×(K-1) conditional probabilities of each category given membership in that or a later category).
'confidence'The confidence level for dlo and dhi, a scalar in the range (0,1). Default is 0.95.

Source Code: mnrval

See also: mnrfit, glmval, logistic_regression

Source Code: mnrval

Fit an ordinal model and predict the category probabilities

 X = [1; 2; 3; 4; 5; 6; 7; 8];
 Y = [1; 1; 1; 2; 2; 2; 3; 3];
 B = mnrfit (X, Y, 'model', 'ordinal');
 pihat = mnrval (B, X, 'model', 'ordinal')
pihat =

   1.0000        0        0
   1.0000        0        0
   1.0000   0.0000        0
   0.0000   1.0000        0
   0.0000   1.0000        0
   0.0000   1.0000   0.0000
   0.0000   0.0000   1.0000
   0.0000   0.0000   1.0000