WOLFRAM

Enable JavaScript to interact with content and submit forms on Wolfram websites. Learn how
Wolfram Language & System Documentation Center

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
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Data  
Properties  
Data & Fitted Functions  
Residuals  
Dispersion and Deviances  
Parameter Estimation Diagnostics  
Influence Measures  
Prediction Values  
Goodness-of-Fit Measures  
Generalizations & Extensions  
Options  
ConfidenceLevel  
CovarianceEstimatorFunction  
DispersionEstimatorFunction  
Show More Show More
IncludeConstantBasis  
LinearOffsetFunction  
NominalVariables  
Weights  
WorkingPrecision  
Properties & Relations  
Possible Issues  
See Also
Tech Notes
Related Guides
History
Cite this Page

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^(th) column of a matrix
    Tabular []name fit the column name in a tabular object
  • With multivariate data such as {{x_(11),x_(12),... ,y_(1)},{x_(21),x_(22),... ,y_(2)},...}, 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 all

Basic Examples  (1)

Define a dataset:

Wolfram Language code: 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:

Wolfram Language code: logit = LogitModelFit[data, x, x]

Evaluate the model at a point:

Wolfram Language code: logit[1.5]

Plot the data points and the models:

Wolfram Language code: 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:

Wolfram Language code: LogitModelFit[{1 / 3, 2 / 3, 5 / 5}, x, x]//Normal

This is equivalent to:

Wolfram Language code: LogitModelFit[{{1, 1 / 3}, {2, 2 / 3}, {3, 5 / 5}}, x, x]//Normal

Weight by the number of observations for each predictor value:

Wolfram Language code: LogitModelFit[{{1, 1 / 3}, {2, 2 / 3}, {3, 5 / 5}}, x, x, Weights -> {3, 6, 5}]//Normal

This gives the same best fit function as success failure data:

Wolfram Language code: 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]
Wolfram Language code: LogitModelFit[sfdata, x, x] //Normal

Fit a list of rules:

Wolfram Language code: LogitModelFit[{1 -> 1 / 3, 2 -> 2 / 3, 3 -> 3 / 3}, x, x]

Fit a rule of input values and responses:

Wolfram Language code: LogitModelFit[{1, 2, 3} -> {1 / 3, 2 / 3, 3 / 3}, x, x]

Specify a column as the response:

Wolfram Language code: data = {...};
Wolfram Language code: fit = LogitModelFit[data -> 1, {1, x, y}, {x, y}]
Wolfram Language code: 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:

Wolfram Language code: dm = {{1, 1}, {1, 2}, {1, 3}, {1, 4}}; resp = {0, 1, 0, 1};LogitModelFit[{dm, resp}]

See the functional form:

Wolfram Language code: Normal[%]

Fit the model referring to the basis functions as x and y:

Wolfram Language code: LogitModelFit[{dm, resp}, {x, y}]//Normal

Obtain a list of available properties:

Wolfram Language code: logit = LogitModelFit[RandomReal[1, 10], x, x]
Wolfram Language code: logit["Properties"]

Properties  (7)

Data & Fitted Functions  (1)

Fit a logit model:

Wolfram Language code: data = Join[RandomReal[10, {10, 2}], Transpose[{RandomReal[1, 10]}], 2];
Wolfram Language code: logit = LogitModelFit[data, {x, y}, {x, y}]

Extract the original data:

Wolfram Language code: logit["Data"]

Obtain and plot the best fit:

Wolfram Language code: fit = logit["BestFit"]
Wolfram Language code: Show[Plot3D[fit, {x, 0, 10}, {y, 0, 10}], Graphics3D[{PointSize[0.025], Point[logit["Data"]]}]]

Obtain the fitted function as a pure function:

Wolfram Language code: logit["Function"]

Get the design matrix and response vector for the fitting:

Wolfram Language code: MatrixForm /@ logit[{"DesignMatrix", "Response"}]

Residuals  (1)

Examine residuals for a fit:

Wolfram Language code: data = Join[RandomReal[10, {100, 2}], Transpose[{RandomReal[1, 100]}], 2];
Wolfram Language code: logit = LogitModelFit[data, {x, y}, {x, y}]
Wolfram Language code: {fr, ar, spr} = logit[{"FitResiduals", "StandardizedPearsonResiduals", "AnscombeResiduals"}];

Visualize the raw residuals:

Wolfram Language code: ListPlot[fr]

Visualize Anscombe residuals and standardized Pearson residuals in stem plots:

Wolfram Language code: Map[ListPlot[#, Filling -> 0]&, {ar, spr}]

Dispersion and Deviances  (1)

Fit a logit model to some data:

Wolfram Language code: 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:

Wolfram Language code: logit["EstimatedDispersion"]

Use Pearson's as the dispersion estimator instead:

Wolfram Language code: logit["EstimatedDispersion", DispersionEstimatorFunction -> "PearsonChiSquare"]

Plot the deviances for each point:

Wolfram Language code: ListPlot[logit["Deviances"], Filling -> 0]

Obtain the analysis of deviance table:

Wolfram Language code: logit["DevianceData"]

Get the residual deviances from the table:

Wolfram Language code: logit["DevianceData"][All, "ResidualDeviance"]//Normal

Parameter Estimation Diagnostics  (1)

Obtain a formatted table of parameter information:

Wolfram Language code: 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];
Wolfram Language code: logit["ParameterEstimates"]

Extract the column of -statistic values:

Wolfram Language code: logit["ParameterEstimates"][All, "ZStatistic"]//Normal

Influence Measures  (1)

Fit some data containing extreme values to a logit model:

Wolfram Language code: 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]];
Wolfram Language code: ListPlot[data]
Wolfram Language code: logit = LogitModelFit[data, {x, Log[x]}, x]

Check Cook distances to identify highly influential points:

Wolfram Language code: ListPlot[logit["CookDistances"], PlotRange -> {0, All}, Filling -> 0]

Check the diagonal elements of the hat matrix to assess influence of points on the fitting:

Wolfram Language code: ListPlot[logit["HatDiagonal"], PlotRange -> {0, All}, Filling -> 0]

Prediction Values  (1)

Fit a logit model:

Wolfram Language code: 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:

Wolfram Language code: 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:

Wolfram Language code: 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];
Wolfram Language code: logit = LogitModelFit[data, {x, y, z}, {x, y, z}]
Wolfram Language code: Grid[Transpose[{#, logit[#]}&[{"AIC", "BIC", "LikelihoodRatioIndex", "PearsonChiSquare"}]], Alignment -> Left]

Compute goodness-of-fit measures for all subsets of predictor variables:

Wolfram Language code: sub = Table[Join[{i}, LogitModelFit[data, i, {x, y, z}][{"AIC", "BIC", "LikelihoodRatioIndex", "PearsonChiSquare"}]], {i, Subsets[{x, y, z}]}]

Rank the models by AIC:

Wolfram Language code: Grid[Join[{{"Model", "AIC", "BIC", "LikelihoodRatioIndex", "PearsonChiSquare"}}, SortBy[sub, -#[[2]]&]]]

Generalizations & Extensions  (1)

Perform other mathematical operations on the functional form of the model:

Wolfram Language code: logit = LogitModelFit[Table[{i, RandomReal[{i - 1, i}] / 10}, {i, 10}], x, x]

Integrate symbolically and numerically:

Wolfram Language code: Integrate[logit[x], x]
Wolfram Language code: NIntegrate[logit[x], {x, 1, 5}]

Find a predictor value that gives a particular value for the model:

Wolfram Language code: FindRoot[logit[x] == .5, {x, 5}]

Options  (8)

ConfidenceLevel  (1)

The default gives 95% confidence intervals:

Wolfram Language code: data = {{0, 1}, {1, 0}, {3, 1}, {5, 0}};
Wolfram Language code: logit = LogitModelFit[data, x, x]
Wolfram Language code: logit["ParameterEstimates"][All, "ConfidenceInterval"]//Normal

Use 99% intervals instead:

Wolfram Language code: logit = LogitModelFit[data, x, x, ConfidenceLevel -> .99]
Wolfram Language code: logit["ParameterEstimates"][All, "ConfidenceInterval"]//Normal

Set the level to 90% within FittedModel :

Wolfram Language code: logit["ParameterEstimates", ConfidenceLevel -> .9][All, "ConfidenceInterval"]//Normal

CovarianceEstimatorFunction  (1)

Fit a logit model:

Wolfram Language code: data = {{0, 1}, {1, 0}, {3, 1}, {5, 0}};
Wolfram Language code: logit = LogitModelFit[data, x, x]

Compute the covariance matrix using the expected information matrix:

Wolfram Language code: logit["CovarianceMatrix"]

Use the observed information matrix instead:

Wolfram Language code: logit["CovarianceMatrix", CovarianceEstimatorFunction -> "ObservedInformation"]

DispersionEstimatorFunction  (1)

Fit a logit model:

Wolfram Language code: data = {{1, 0}, {1, 1}, {1, 1}, {2, 0}, {2, 0}, {2, 1}, {2, 1}, {2, 1}, {2, 1}};
Wolfram Language code: logit = LogitModelFit[data, x, x]

Compute the covariance matrix:

Wolfram Language code: logit["CovarianceMatrix"]

Compute the covariance matrix estimating the dispersion by Pearson's :

Wolfram Language code: logit["CovarianceMatrix", DispersionEstimatorFunction -> "PearsonChiSquare"]

IncludeConstantBasis  (1)

Fit a logit model:

Wolfram Language code: data = {{0, 1}, {1, 0}, {3, 1}, {5, 0}};
Wolfram Language code: LogitModelFit[data, x, x]//Normal

Fit the model with no constant term:

Wolfram Language code: LogitModelFit[data, x, x, IncludeConstantBasis -> False]//Normal

LinearOffsetFunction  (1)

Fit data to a logit model:

Wolfram Language code: data = {{0, 1}, {1, 0}, {3, 1}, {5, 0}};
Wolfram Language code: LogitModelFit[data, x, x]//Normal

Fit data to a model with a known Sqrt [x] term:

Wolfram Language code: LogitModelFit[data, x, x, LinearOffsetFunction -> (Sqrt[#]&)]//Normal

NominalVariables  (1)

Wolfram Language code: 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:

Wolfram Language code: nom = LogitModelFit[data, {x, y}, {x, y}, NominalVariables -> x]
Wolfram Language code: Normal[nom]

Treat both variables as nominal:

Wolfram Language code: LogitModelFit[data, {x, y}, {x, y}, NominalVariables -> All]//Normal

Weights  (1)

Fit a model using equal weights:

Wolfram Language code: data = {{0, 1}, {1, 0}, {3, 1}, {5, 0}};
Wolfram Language code: LogitModelFit[data, x, x]//Normal

Give explicit weights for the data points:

Wolfram Language code: LogitModelFit[data, x, x, Weights -> {1, (1/2), (1/3), (1/4)}]//Normal

WorkingPrecision  (1)

Use WorkingPrecision to get higher precision in parameter estimates:

Wolfram Language code: data = Table[{x, (10 - x) / 10}, {x, 10}]
Wolfram Language code: logit = LogitModelFit[data, x, x, WorkingPrecision -> 30]

Obtain the fitted function:

Wolfram Language code: logit["BestFit"]

Reduce the precision in property computations after the fitting:

Wolfram Language code: logit["BestFit", WorkingPrecision -> MachinePrecision]

Properties & Relations  (4)

A default "Binomial" model from GeneralizedLinearModelFit is equivalent to the model for LogitModelFit :

Wolfram Language code: data = Table[{i, RandomReal[{i - 1, i}] / 10}, {i, 10}];
Wolfram Language code: GeneralizedLinearModelFit[data, x, x, ExponentialFamily -> "Binomial"]//Normal
Wolfram Language code: LogitModelFit[data, x, x]//Normal

ProbitModelFit is equivalent to a "Binomial" model with "ProbitLink":

Wolfram Language code: GeneralizedLinearModelFit[data, x, x, ExponentialFamily -> "Binomial", LinkFunction -> "ProbitLink"]//Normal
Wolfram Language code: ProbitModelFit[data, x, x]//Normal

LogitModelFit assumes binomially distributed responses:

Wolfram Language code: data = Table[{i, RandomReal[{i - 1, i}] / 10}, {i, 10}];
Wolfram Language code: lm = LogitModelFit[data, x, x]

NonlinearModelFit assumes normally distributed responses:

Wolfram Language code: nm = NonlinearModelFit[data, 1 / (1 + Exp[a + b x]), {a, b}, x]

The fits are not identical:

Wolfram Language code: {Normal[lm], Normal[nm]}
Wolfram Language code: Plot[{lm[x], nm[x]}, {x, 1, 5}]

LogitModelFit will use the time stamps of a TimeSeries as variables:

Wolfram Language code: 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];
Wolfram Language code: ts1["Times"]
Wolfram Language code: LogitModelFit[ts1, x, x]

Rescale the time stamps and fit again:

Wolfram Language code: ts2 = TimeSeriesRescale[ts1, {.1, 2}]
Wolfram Language code: ts2["Times"]
Wolfram Language code: LogitModelFit[ts2, x, x]

Find fit for the values:

Wolfram Language code: LogitModelFit[ts1["Values"], x, x]

LogitModelFit acts pathwise on a multipath TemporalData :

Wolfram Language code: 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]

Possible Issues  (1)

Responses outside the interval from 0 to 1 are not valid for logit models:

Wolfram Language code: LogitModelFit[Range[5], x, x]
Wolfram Language code: LogitModelFit[Table[{i, 2i}, {i, 10}], x, x]
Wolfram Research (2008), LogitModelFit, Wolfram Language function, https://reference.wolfram.com/language/ref/LogitModelFit.html (updated 2025).

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: 13-August-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: 13-August-2026]}

Top [フレーム]

AltStyle によって変換されたページ (->オリジナル) /