Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
mnrfit help

Subject: mnrfit help

From: J G

Date: 26 Jul, 2012 02:32:31

Message: 1 of 2

Hi, I'm having trouble interpreting the example for mnrfit on the help page. My data are are proportions of simulations that reach a particular outcome (three different outcomes are possible), across different x-values:

x = [0.1 0.25 0.5 0.75 0.9]';
Y = [0.248 0.109 0.643; 0.26 0.126 0.614; 0.276 0.115 0.609; 0.282 0.144 0.574; 0.304 0.13 0.566];

% so now I want to plot these data as a bar graph:

bar(x,Y,'grouped'); ylim([0 0.7]);

% and then fit a nominal model for the individual response category probabilities:

xx = linspace(0,1)';
betaHatOrd = mnrfit(x,Y,'model','ordinal','interactions','off');
pHatOrd = mnrval(betaHatOrd,xx,'type','cumulative','model','ordinal','interactions','off');
line(xx,pHatOrd,'LineWidth',2);

% this obviously doesn't work, what am I missing?

Thanks for any help!

Subject: mnrfit help

From: Peter Perkins

Date: 26 Jul, 2012 15:22:41

Message: 2 of 2

Jemma, one possible problem is that while you said, "nominal", but
you're fitting an ordinal model. Not sure which you really wanted, it
probably depends on what the categories represent.

Also, the help says

"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,:)."

and you are passing in a matrix of proportions. MNRFIT has no way to
know, for example, that the proportions in the first row of Y were based
on 10 trials and the proportions in the second row were based on 10
zillion. MNRFIT needs to kow the right weight to give to each row. It
may be that all your rows represent the same number of trials, and so
perhaps MNRFIT gets the right estimates, but really Y ought to be
counts, not proportions.

But the problem with your figure is simply that your bars are
proportions for each category, while your lines are cumulative
probabilities as a function of x. Change 'cumulative' to 'category',
and you'll get something like what you're expecting.

HOWEVER, because your bars are grouped, not stacked, the bars are not
really at the "right" x values. So change 'grouped' to 'stacked', and
'category' back to 'cumulative', and voila.

Hope this helps.


7/25/2012 10:32 PM, J G wrote:
> Hi, I'm having trouble interpreting the example for mnrfit on the help
> page. My data are are proportions of simulations that reach a
> particular outcome (three different outcomes are possible), across
> different x-values:
>
> x = [0.1 0.25 0.5 0.75 0.9]';
> Y = [0.248 0.109 0.643; 0.26 0.126 0.614; 0.276 0.115 0.609; 0.282 0.144
> 0.574; 0.304 0.13 0.566];
>
> % so now I want to plot these data as a bar graph:
>
> bar(x,Y,'grouped'); ylim([0 0.7]);
>
> % and then fit a nominal model for the individual response category
> probabilities:
>
> xx = linspace(0,1)';
> betaHatOrd = mnrfit(x,Y,'model','ordinal','interactions','off');
> pHatOrd =
> mnrval(betaHatOrd,xx,'type','cumulative','model','ordinal','interactions','off');
>
> line(xx,pHatOrd,'LineWidth',2);
>
> % this obviously doesn't work, what am I missing?
>
> Thanks for any help!

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us