I have an ordina categorical variable Y with 3 categories (-1; 0; 1) and continuous independent variable X - range from 0.04 to 0.09. I'd like to use mnrfit() function which hopefuly could give me the estimate of ordinal regression model. Afterwards I'd like to predict a cumulative probability of category 0 and 1 for any value of X.
When I put it into mnrfit function it says:
"??? Error using ==> mnrfit at 195
If Y is a column vector, it must contain positive integer category numbers."
Maybe it's trivial question but why does it say "positive integer". Should I change my categories to greater than 1? Can someone please help with that. THank you for any advice.
Diana
> Hello,
>
> I have an ordina categorical variable Y with 3 categories (-1; 0; 1) ...
>
> When I put it into mnrfit function it says:
> "??? Error using ==> mnrfit at 195
> If Y is a column vector, it must contain positive integer category
> numbers."
>
> Maybe it's trivial question but why does it say "positive integer".
> Should I change my categories to greater than 1? Can someone please help
> with that. THank you for any advice.
...
Don't have mntfit here so just hypothesizing...
Guess would be it's setup for categories 1,2,...,N rather than arbitrary.
Try Y+2 as input instead; you can always translate the resulting model
if that is the issue.
--
Hello,
If I copy / paste the printout from help would it help? I hope u'll manage to figure out something.
" MNRFIT Fit a nominal or ordinal multinomial regression model.
B = MNRFIT(X,Y) fits a nominal multinomial logistic regression model for
the response Y and predictor matrix X. X is an N-by-P design matrix with
N observations on P predictor variables. 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 (rows of X and Y) are given by the row sums SUM(Y,2).
Alternatively, Y can be an N element 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. MNRFIT automatically includes intercept
(constant) terms; do not enter a column of ones directly into X.
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 K-th category are taken to be zero.
MNRFIT treats NaNs in X and Y as missing data, and removes the
corresponding observations."
EXAMPLES:
"Example: 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]);
% 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);"
BTW. Thank for trying to help.
Diana
-- Tom
"Diana " <ze...@op.pl> wrote in message
news:it7g55$ohr$1...@newscl01ah.mathworks.com...