Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

The third listed syntax version of LogitModelFit allows one to specify input in a simple way: Only a design matrix (with a row of values of the explanatory input variables for each of the output values) and a response vector are needed. The following example is straight from the LogitModelFit help page:

dm = {{1, 1}, {1, 2}, {1, 3}, {1, 4}};
resp = {0, 1, 0, 1};
model = LogitModelFit[{dm, resp}]

Mathematica graphics

As usual in these types of fits, Mathematica returns an object that can be interrogated with various methods. In this case, I just want to have the best fit:


Mathematica graphics

I noted something here that I feel is strange. Although this looks like a pure function (which is what I expected, given no formal variable names are specified in this syntax), it really isn't, since the required & at the end is missing. Hence, a construction like model["BestFit"][1,2] doesn't work.

Is this a bug, or is this useful in some way and am I missing something?

I note that neither the "Function" method of LogitModelFit nor something like model//Normal yields anything useful. The former generates an error which suggests to me that there is indeed a bug in this syntax variant. The latter returns the same as "BestFit".

My workaround for now is to use:

mod = model["BestFit"] // Evaluate // Function;

(Evaluate because of the HoldAll attribute of function)

mod[1, 2]


share|improve this question
I confirm this behavior in Mathematica 8.0.4 under Windows 7 x64. Looks like a bug. –  Alexey Popkov May 14 '14 at 11:34
Why would you not just use model[1,2] in the example? I don't think this is a bug... –  ciao May 29 '14 at 9:34
@rasher I think you are right and I interpreted things wrong here. My initial assumption was that the intention of the "BestFit" parameter was to get you a pure function to work with. I didn't realize that the model itself is already such a pure function. I guess the output for "BestFit" just resembles a pure function because in this syntax variant there are no named variables and Slot is used instead. –  Sjoerd C. de Vries May 29 '14 at 14:27
@rasher On second thought, there is a very good reason not to use model[1,2] and that is that the FittedModel doesn't store the actual fit, but calculates it on the fly when called with arguments. This means that it will be actually very slow. In the above example model[1,2] is about 150 times slower than my proposed mod[1,2]. I expect that it slowness will increase with increasing model complexity and data size. So, you really need a "BestFit" output if you're going to use the model often. –  Sjoerd C. de Vries May 29 '14 at 14:55
model["Function"][1,2] works on the Raspberry Pi. –  bobthechemist May 29 '14 at 14:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.