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]


  • $\begingroup$ I confirm this behavior in Mathematica 8.0.4 under Windows 7 x64. Looks like a bug. $\endgroup$ – Alexey Popkov May 14 '14 at 11:34
  • $\begingroup$ Why would you not just use model[1,2] in the example? I don't think this is a bug... $\endgroup$ – ciao May 29 '14 at 9:34
  • $\begingroup$ @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. $\endgroup$ – Sjoerd C. de Vries May 29 '14 at 14:27
  • $\begingroup$ @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. $\endgroup$ – Sjoerd C. de Vries May 29 '14 at 14:55
  • $\begingroup$ model["Function"][1,2] works on the Raspberry Pi. $\endgroup$ – bobthechemist May 29 '14 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.