# Third syntax version of LogitModelFit: unexpected result of “BestFit”

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}]


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:

model["BestFit"]


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]


0.3883882668

• 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