LogitModelFit[{{x1,y1},{x2,y2},…},{f1,f2,…},x]
constructs a binomial logistic regression model of the form
that fits the yi for each xi.
LogitModelFit[data,{f1,…},{x1,x2,…}]
constructs a binomial logistic regression model of the form
where the fi depend on the variables xk.
LogitModelFit[{m,v}]
constructs a binomial logistic regression model from the design matrix m and response vector v.
LogitModelFit
LogitModelFit[{{x1,y1},{x2,y2},…},{f1,f2,…},x]
constructs a binomial logistic regression model of the form
that fits the yi for each xi.
LogitModelFit[data,{f1,…},{x1,x2,…}]
constructs a binomial logistic regression model of the form
where the fi depend on the variables xk.
LogitModelFit[{m,v}]
constructs a binomial logistic regression model from the design matrix m and response vector v.
Details and Options
- LogitModelFit attempts to model the data using a linear combination of basis functions composed with a logistic sigmoid.
- LogitModelFit is typically used in classification to model probability values.
- LogitModelFit produces a generalized linear model of the form
under the assumption that the original
are independent realizations of Bernoulli trials with probabilities
. - The function
is the LogisticSigmoid. - LogitModelFit returns a symbolic FittedModel object to represent the logistic model it constructs. The properties and diagnostics of the model can be obtained from model["property"].
- The value of the best-fit function from LogitModelFit at a particular point x1, … can be found from model[x1,…].
- Possible forms of data are:
-
{y1,y2,…} equivalent to the form {{1,y1},{2,y2},…} {{x11,x12,…,y1},…} a list of independent values xij and the responses yi {{x11,x12,…}y1,…} a list of rules between input values and response {{x11,x12,…},…}{y1,y2,…} a rule between a list of input values and responses {{x11,…,y1,…},…}n fit the n
column of a matrixTabular[…]name fit the column name in a tabular object - With multivariate data such as
, the number of coordinates xi1, xi2, … should equal the number of variables xi. - The yi are probabilities between 0 and 1.
- Additionally, data can be specified using a design matrix without specifying functions and variables:
-
{m,v} a design matrix m and response vector v - In LogitModelFit[{m,v}], the design matrix m is formed from the values of basis functions fi at data points in the form {{f1,f2,…},{f1,f2,…},…}. The response vector v is the list of responses {y1,y2,…}.
- For a design matrix m and response vector v, the model is
, where
is the vector of parameters to be estimated. - When a design matrix is used, the basis functions fi can be specified using the form LogitModelFit[{m,v},{f1,f2,…}].
- LogitModelFit is equivalent to GeneralizedLinearModelFit with ExponentialFamily->"Binomial" and LinkFunction->Automatic.
- LogitModelFit takes the same options as GeneralizedLinearModelFit, with the exception of ExponentialFamily and LinkFunction.
Examples
open all close allBasic Examples (1)
data = {{1, 0}, {2, 0}, {2, 0}, {2, 1}, {2, 0}, {3, 0}, {3, 0}, {3, 0}, {3, 1}, {3, 1}, {3, 1}, {4, 1}, {4, 1}, {5, 0}, {6, 1}, {7, 1}};Fit a logistic model to the data:
logit = LogitModelFit[data, x, x]Evaluate the model at a point:
logit[1.5]Plot the data points and the models:
Show[ListPlot[data, PlotStyle -> PointSize[Medium]], Plot[logit[x], {x, 0, 8}]]Scope (13)
Data (6)
Fit data with success probability responses, assuming increasing integer-independent values:
LogitModelFit[{1 / 3, 2 / 3, 5 / 5}, x, x]//NormalLogitModelFit[{{1, 1 / 3}, {2, 2 / 3}, {3, 5 / 5}}, x, x]//NormalWeight by the number of observations for each predictor value:
LogitModelFit[{{1, 1 / 3}, {2, 2 / 3}, {3, 5 / 5}}, x, x, Weights -> {3, 6, 5}]//NormalThis gives the same best fit function as success failure data:
sfdata = {{1, 0}, {1, 1}, {1, 0}, {2, 0}, {2, 0}, {2, 1}, {2, 1}, {2, 1}, {2, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}};
GroupBy[sfdata, First -> Last]LogitModelFit[sfdata, x, x] //NormalLogitModelFit[{1 -> 1 / 3, 2 -> 2 / 3, 3 -> 3 / 3}, x, x]Fit a rule of input values and responses:
LogitModelFit[{1, 2, 3} -> {1 / 3, 2 / 3, 3 / 3}, x, x]Specify a column as the response:
data = {...};fit = LogitModelFit[data -> 1, {1, x, y}, {x, y}]Show[
Plot3D[fit[x, y], {x, -5, 5}, {y, -5, 5}],
ListPointPlot3D[data[[All, {2, 3, 1}]]],
PlotRange -> All
]Fit a model given a design matrix and response vector:
dm = {{1, 1}, {1, 2}, {1, 3}, {1, 4}};
resp = {0, 1, 0, 1};LogitModelFit[{dm, resp}]Normal[%]Fit the model referring to the basis functions as x and y:
LogitModelFit[{dm, resp}, {x, y}]//NormalObtain a list of available properties:
logit = LogitModelFit[RandomReal[1, 10], x, x]logit["Properties"]Properties (7)
Data & Fitted Functions (1)
data = Join[RandomReal[10, {10, 2}], Transpose[{RandomReal[1, 10]}], 2];logit = LogitModelFit[data, {x, y}, {x, y}]logit["Data"]fit = logit["BestFit"]Show[Plot3D[fit, {x, 0, 10}, {y, 0, 10}], Graphics3D[{PointSize[0.025], Point[logit["Data"]]}]]Obtain the fitted function as a pure function:
logit["Function"]Get the design matrix and response vector for the fitting:
MatrixForm /@ logit[{"DesignMatrix", "Response"}]Residuals (1)
data = Join[RandomReal[10, {100, 2}], Transpose[{RandomReal[1, 100]}], 2];logit = LogitModelFit[data, {x, y}, {x, y}]{fr, ar, spr} = logit[{"FitResiduals", "StandardizedPearsonResiduals", "AnscombeResiduals"}];ListPlot[fr]Visualize Anscombe residuals and standardized Pearson residuals in stem plots:
Map[ListPlot[#, Filling -> 0]&, {ar, spr}]Dispersion and Deviances (1)
Fit a logit model to some data:
SeedRandom[1];
data = Flatten[Table[{x, y, 1 / (1 + Exp[.2 + .3x + .1y + RandomReal[{-1, 1}]])}, {x, RandomReal[5, 10]}, {y, RandomReal[5, 10]}], 1];logit = LogitModelFit[data, {x, y}, {x, y}]The estimated dispersion is 1 by default:
logit["EstimatedDispersion"]Use Pearson's
as the dispersion estimator instead:
logit["EstimatedDispersion", DispersionEstimatorFunction -> "PearsonChiSquare"]Plot the deviances for each point:
ListPlot[logit["Deviances"], Filling -> 0]Obtain the analysis of deviance table:
logit["DevianceData"]Get the residual deviances from the table:
logit["DevianceData"][All, "ResidualDeviance"]//NormalParameter Estimation Diagnostics (1)
Obtain a formatted table of parameter information:
SeedRandom[1];
data = Table[{i, RandomInteger[BinomialDistribution[20, .05 + i / 30 + Sin[i] / 10]] / 20}, {i, 1, 20, .2}];
logit = LogitModelFit[data, {x, Sin[x], Cos[x]}, x];logit["ParameterEstimates"]Extract the column of
-statistic values:
logit["ParameterEstimates"][All, "ZStatistic"]//NormalInfluence Measures (1)
Fit some data containing extreme values to a logit model:
SeedRandom[3];data = Table[{i, 1 / (1 + Exp[2 + 4i - Log[i] + RandomReal[]])}, {i, RandomReal[{1, 10}, 20]}];
data[[{3, 8}, -1]] = 1 - data[[{3, 8}, -1]];ListPlot[data]logit = LogitModelFit[data, {x, Log[x]}, x]Check Cook distances to identify highly influential points:
ListPlot[logit["CookDistances"], PlotRange -> {0, All}, Filling -> 0]Check the diagonal elements of the hat matrix to assess influence of points on the fitting:
ListPlot[logit["HatDiagonal"], PlotRange -> {0, All}, Filling -> 0]Prediction Values (1)
SeedRandom[3];data = Flatten[Table[{x, y, 1 / (1 + Exp[.3x - .5y + RandomReal[{-1, 1}]])}, {x, RandomReal[5, 3]}, {y, RandomReal[5, 3]}], 1];logit = LogitModelFit[data, {x, y}, {x, y}]Plot the predicted values against the observed values:
ListPlot[Transpose[logit[{"Response", "PredictedResponse"}]], FrameLabel -> {"observed", "predicted"}, Frame -> True, Axes -> False]Goodness-of-Fit Measures (1)
Obtain a table of goodness-of-fit measures for a logit model:
SeedRandom[3];data = Flatten[Table[{i, j, RandomReal[10], 1 / (1 + Exp[30i - 10j + RandomReal[5]])}, {i, RandomReal[10, 5]}, {j, RandomReal[10, 5]}], 1];logit = LogitModelFit[data, {x, y, z}, {x, y, z}]Grid[Transpose[{#, logit[#]}&[{"AIC", "BIC", "LikelihoodRatioIndex", "PearsonChiSquare"}]], Alignment -> Left]Compute goodness-of-fit measures for all subsets of predictor variables:
sub = Table[Join[{i}, LogitModelFit[data, i, {x, y, z}][{"AIC", "BIC", "LikelihoodRatioIndex", "PearsonChiSquare"}]], {i, Subsets[{x, y, z}]}]Grid[Join[{{"Model", "AIC", "BIC", "LikelihoodRatioIndex", "PearsonChiSquare"}}, SortBy[sub, -#[[2]]&]]]Generalizations & Extensions (1)
Perform other mathematical operations on the functional form of the model:
logit = LogitModelFit[Table[{i, RandomReal[{i - 1, i}] / 10}, {i, 10}], x, x]Integrate symbolically and numerically:
Integrate[logit[x], x]NIntegrate[logit[x], {x, 1, 5}]Find a predictor value that gives a particular value for the model:
FindRoot[logit[x] == .5, {x, 5}]Options (8)
ConfidenceLevel (1)
The default gives 95% confidence intervals:
data = {{0, 1}, {1, 0}, {3, 1}, {5, 0}};logit = LogitModelFit[data, x, x]logit["ParameterEstimates"][All, "ConfidenceInterval"]//Normallogit = LogitModelFit[data, x, x, ConfidenceLevel -> .99]logit["ParameterEstimates"][All, "ConfidenceInterval"]//NormalSet the level to 90% within FittedModel:
logit["ParameterEstimates", ConfidenceLevel -> .9][All, "ConfidenceInterval"]//NormalCovarianceEstimatorFunction (1)
data = {{0, 1}, {1, 0}, {3, 1}, {5, 0}};logit = LogitModelFit[data, x, x]Compute the covariance matrix using the expected information matrix:
logit["CovarianceMatrix"]Use the observed information matrix instead:
logit["CovarianceMatrix", CovarianceEstimatorFunction -> "ObservedInformation"]DispersionEstimatorFunction (1)
data = {{1, 0}, {1, 1}, {1, 1}, {2, 0}, {2, 0}, {2, 1}, {2, 1}, {2, 1}, {2, 1}};logit = LogitModelFit[data, x, x]Compute the covariance matrix:
logit["CovarianceMatrix"]Compute the covariance matrix estimating the dispersion by Pearson's
:
logit["CovarianceMatrix", DispersionEstimatorFunction -> "PearsonChiSquare"]IncludeConstantBasis (1)
LinearOffsetFunction (1)
data = {{0, 1}, {1, 0}, {3, 1}, {5, 0}};LogitModelFit[data, x, x]//NormalFit data to a model with a known Sqrt[x] term:
LogitModelFit[data, x, x, LinearOffsetFunction -> (Sqrt[#]&)]//NormalNominalVariables (1)
data = {{a, 0, 0}, {b, 2, 1}, {a, 2, 0}, {b, 0, 1}, {a, 2, 1}, {b, 0, 0}};Fit the data treating the first variable as a nominal variable:
nom = LogitModelFit[data, {x, y}, {x, y}, NominalVariables -> x]Normal[nom]Treat both variables as nominal:
LogitModelFit[data, {x, y}, {x, y}, NominalVariables -> All]//NormalWeights (1)
WorkingPrecision (1)
Use WorkingPrecision to get higher precision in parameter estimates:
data = Table[{x, (10 - x) / 10}, {x, 10}]logit = LogitModelFit[data, x, x, WorkingPrecision -> 30]logit["BestFit"]Reduce the precision in property computations after the fitting:
logit["BestFit", WorkingPrecision -> MachinePrecision]Properties & Relations (4)
A default "Binomial" model from GeneralizedLinearModelFit is equivalent to the model for LogitModelFit:
data = Table[{i, RandomReal[{i - 1, i}] / 10}, {i, 10}];GeneralizedLinearModelFit[data, x, x, ExponentialFamily -> "Binomial"]//NormalLogitModelFit[data, x, x]//NormalProbitModelFit is equivalent to a "Binomial" model with "ProbitLink":
GeneralizedLinearModelFit[data, x, x, ExponentialFamily -> "Binomial", LinkFunction -> "ProbitLink"]//NormalProbitModelFit[data, x, x]//NormalLogitModelFit assumes binomially distributed responses:
data = Table[{i, RandomReal[{i - 1, i}] / 10}, {i, 10}];lm = LogitModelFit[data, x, x]NonlinearModelFit assumes normally distributed responses:
nm = NonlinearModelFit[data, 1 / (1 + Exp[a + b x]), {a, b}, x]{Normal[lm], Normal[nm]}Plot[{lm[x], nm[x]}, {x, 1, 5}]LogitModelFit will use the time stamps of a TimeSeries as variables:
ts1 = TemporalData[TimeSeries, {{{0.7758532198866042, 0.20426632015371096, 0.2353690565215641,
0.4448009174525732, 0.5081575045542254, 0.5371908040104083, 0.6223323745794831,
0.669522447912184, 0.7204685251554224, 0.7633871517003976}}, {{0, 9, 1}}, 1, {"Continuous", 1},
{"Discrete", 1}, 1, {ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}}}, False,
10.1];ts1["Times"]LogitModelFit[ts1, x, x]Rescale the time stamps and fit again:
ts2 = TimeSeriesRescale[ts1, {.1, 2}]ts2["Times"]LogitModelFit[ts2, x, x]LogitModelFit[ts1["Values"], x, x]LogitModelFit acts pathwise on a multipath TemporalData:
LogitModelFit[TemporalData[Automatic, {{{0.009753347177267509, 0.18455899093641098, 0.20260886672737863,
0.37977270854029854, 0.45927203330240407, 0.5010683896315415, 0.6468842072138713,
0.7452632634563319, 0.8683334166368966, 0.9876532168951402},
... 2138713, 0.7452632634563319,
0.8683334166368966, 0.9876532168951402}}, {{0, 9, 1}, {0.1, 2., 0.2111111111111111}}, 2,
{"Continuous", 2}, {"Discrete", 2}, 1,
{ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}}}, False, 10.1], x, x]Tech Notes
Text
Wolfram Research (2008), LogitModelFit, Wolfram Language function, https://reference.wolfram.com/language/ref/LogitModelFit.html (updated 2025).
CMS
Wolfram Language. 2008. "LogitModelFit." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/LogitModelFit.html.
APA
Wolfram Language. (2008). LogitModelFit. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/LogitModelFit.html
BibTeX
@misc{reference.wolfram_2026_logitmodelfit, author="Wolfram Research", title="{LogitModelFit}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/LogitModelFit.html}", note=[Accessed: 15-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_logitmodelfit, organization={Wolfram Research}, title={LogitModelFit}, year={2025}, url={https://reference.wolfram.com/language/ref/LogitModelFit.html}, note=[Accessed: 15-June-2026]}