({{, (RefLink[LogitModelFit, paclet:ref/LogitModelFit])[{(Subscript[y, 1]),(Subscript[y, 2]),…},{(Subscript[f, 1]),(Subscript[f, 2]),…},x] 
constructs a binomial logistic regression model of the form 1/(1+(e^(-((Subscript[β, 0])+(Subscript[β, 1])(Subscript[f, 1]) +(Subscript[β, 2])(Subscript[f, 2]) +…)))) that fits the (Subscript[y, i]) for successive x values 1, 2, ….}, {, (RefLink[LogitModelFit, paclet:ref/LogitModelFit])[{{(Subscript[x, 11]),(Subscript[x, 12]),…,(Subscript[y, 1])},{(Subscript[x, 21]),(Subscript[x, 22]),…,(Subscript[y, 2])},…},{(Subscript[f, 1]),…},{(Subscript[x, 1]),(Subscript[x, 2]),…}]
constructs a binomial logistic regression model of the form 1/(1+(e^(-((Subscript[β, 0])+(Subscript[β, 1])(Subscript[f, 1]) +(Subscript[β, 2])(Subscript[f, 2]) +…)))) where the (Subscript[f, i]) depend on the variables (Subscript[x, k]).}, {, (RefLink[LogitModelFit, paclet:ref/LogitModelFit])[{m,v}]
constructs a binomial logistic regression model from the design matrix m and response vector v.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[LogitModelFit, paclet:ref/LogitModelFit]) returns a symbolic (RefLink[FittedModel, paclet:ref/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 (RefLink[LogitModelFit, paclet:ref/LogitModelFit]) at a particular point (Subscript[x, 1]), … can be found from model[(Subscript[x, 1]),…].

With data in the form {{(Subscript[x, 11]),(Subscript[x, 12]),…,(Subscript[y, 1])},{(Subscript[x, 21]),(Subscript[x, 22]),…,(Subscript[y, 2])},…}, the number of coordinates (Subscript[x, i1]), (Subscript[x, i2]), … should correspond to the number of variables (Subscript[x, i]).

The (Subscript[y, i]) are probabilities between 0 and 1.

Data in the form {(Subscript[y, 1]),(Subscript[y, 2]),…} is equivalent to data in the form {{1,(Subscript[y, 1])},{2,(Subscript[y, 2])},…}.

(RefLink[LogitModelFit, paclet:ref/LogitModelFit]) produces a logistic model of the form (OverHat[y])=1/(1+(e^(-((Subscript[β, 0])+(Subscript[β, 1])(Subscript[f, 1]) +(Subscript[β, 2])(Subscript[f, 2]) +…)))) under the assumption that the original (Subscript[n, i])(Subscript[y, i]) are independent observations following binomial distributions with mean (Subscript[n, i])(Subscript[(OverHat[y]), i]).

In (RefLink[LogitModelFit, paclet:ref/LogitModelFit])[{m,v}], the design matrix m is formed from the values of basis functions (Subscript[f, i]) at data points in the form {{(Subscript[f, 1]),(Subscript[f, 2]),…},{(Subscript[f, 1]),(Subscript[f, 2]),…},…}. The response vector v is the list of responses {(Subscript[y, 1]),(Subscript[y, 2]),…}.

For a design matrix m and response vector v, the model is (OverHat[v])=1/(1+(e^(-m.β))), where β is the vector of parameters to be estimated.

When a design matrix is used, the basis functions (Subscript[f, i]) can be specified using the form (RefLink[LogitModelFit, paclet:ref/LogitModelFit])[{m,v},{(Subscript[f, 1]),(Subscript[f, 2]),…}].

(RefLink[LogitModelFit, paclet:ref/LogitModelFit]) is equivalent to (RefLink[GeneralizedLinearModelFit, paclet:ref/GeneralizedLinearModelFit]) with (RefLink[ExponentialFamily, paclet:ref/ExponentialFamily])->"Binomial" and (RefLink[LinkFunction, paclet:ref/LinkFunction])->(RefLink[Automatic, paclet:ref/Automatic]).

(RefLink[LogitModelFit, paclet:ref/LogitModelFit]) takes the same options as (RefLink[GeneralizedLinearModelFit, paclet:ref/GeneralizedLinearModelFit]), with the exception of (RefLink[ExponentialFamily, paclet:ref/ExponentialFamily]) and (RefLink[LinkFunction, paclet:ref/LinkFunction]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (25)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Define a dataset:

data={{1,0},{1,1},{1,1},{2,0},{2,0},{2,1},{2,1},{2,1},{2,1},{3,1},{3,1},{3,1},{3,1},{3,1}};

Fit a logistic model to the data:

logit=LogitModelFit[data,x,x]

See the functional forms of the model:

Normal[logit]

Evaluate the model at a point:

logit[1.5]

Plot the data points and the models:

Show[ListPlot[data],Plot[logit[x],{x,1,3}],PlotRange->All,AxesOrigin->{.9,-.1}]

Compute the fitted values for the model:

logit["PredictedResponse"]

Visualize the deviance residuals:

ListPlot[logit["DevianceResiduals"]]

OpenersExampleSection1(Spacer1)Scope  (10)

Fit data with success probability responses:

LogitModelFit[{{1,2/3},{2,4/6},{3,5/5}},x,x]//Normal

Weight by the number of observations for each predictor value:

LogitModelFit[{{1,2/3},{2,4/6},{3,5/5}},x,x,Weights->{3,6,5}]//Normal

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

sfdata={{1,0},{1,1},{1,1},{2,0},{2,0},{2,1},{2,1},{2,1},{2,1},{3,1},{3,1},{3,1},{3,1},{3,1}};
LogitModelFit[sfdata,x,x] //Normal

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

See the functional form:

Normal[%]

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

LogitModelFit[{dm,resp},{x,y}]//Normal

Obtain a list of available properties:

logit=LogitModelFit[RandomReal[1,10],x,x]

logit["Properties"]

OpenersExampleSubsection0(Spacer1)Properties  (7)

OpenersExampleSubsubsection0(Spacer1)Data & Fitted Functions  (1)

Fit a logit model:

data=Join[RandomReal[10,{10,2}],Transpose[{RandomReal[1,10]}],2];

logit=LogitModelFit[data,{x,y},{x,y}]

Extract the original data:

logit["Data"]

Obtain and plot the best fit:

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

OpenersExampleSubsubsection1(Spacer1)Residuals  (1)

Examine residuals for a fit:

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

Visualize the raw residuals:

ListPlot[fr]

Visualize Anscombe residuals and standardized Pearson residuals in stem plots:

Map[ListPlot[#,Filling->0]&,{ar,spr}]

OpenersExampleSubsubsection2(Spacer1)Dispersion and Deviances  (1)

Fit a logit model to some data:

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 (χ^2) 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["DevianceTable"]

Get the residual deviances from the table:

logit["DevianceTableResidualDeviances"]

Extract the numeric entries from the table:

vals=logit["DevianceTableEntries"]

Use (RefLink[Grid, paclet:ref/Grid]) to add formatting:

Grid[Join[{{"","d.f.","dev.","res.\nd.f.","res.\ndev."}},Join[{{""},{"x"},{"y"}},Map[PadLeft[#,4,SpanFromLeft]&,vals],2]]]

OpenersExampleSubsubsection3(Spacer1)Parameter Estimation Diagnostics  (1)

Obtain a formatted table of parameter information:

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["ParameterTable"]

Extract the column of z-statistic values:

logit["ParameterZStatistics"]

Get the unformatted array of values from the table:

vals=logit["ParameterTableEntries"]

Add formatting using (RefLink[Grid, paclet:ref/Grid]):

Grid[Join[{{f,(OverHat[β]),(OverHat[σ]),z,P[Abs[Z]>Abs[z]]}},Join[{{1},{x},{Sin[x]},{Cos[x]}},vals,2]],Dividers->{GrayLevel[.5],GrayLevel[.5]}]//TraditionalForm

Add formatting via (RefLink[TableForm, paclet:ref/TableForm]):

TableForm[vals,TableHeadings->{{1,(Subscript[f, 1]),(Subscript[f, 2]),(Subscript[f, 3])},{(OverHat[β]),(OverHat[σ]),z,P[Abs[Z]>Abs[z]]}}]//TraditionalForm

OpenersExampleSubsubsection4(Spacer1)Influence 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]

OpenersExampleSubsubsection5(Spacer1)Prediction Values  (1)

Fit a logit model:

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]

OpenersExampleSubsubsection6(Spacer1)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}]}]

Rank the models by AIC:

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

OpenersExampleSection2(Spacer1)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}]

OpenersExampleSection3(Spacer1)Options  (8)

OpenersExampleSubsection1(Spacer1)ConfidenceLevel  (1)

The default gives 95% confidence intervals:

data={{0,1},{1,0},{3,1},{5,0}};

logit=LogitModelFit[data,x,x]

logit["ParameterConfidenceIntervals"]

Use 99% intervals instead:

logit=LogitModelFit[data,x,x,ConfidenceLevel->.99]

logit["ParameterConfidenceIntervals"]

Set the level to 90% within (RefLink[FittedModel, paclet:ref/FittedModel]):

logit["ParameterConfidenceIntervals",ConfidenceLevel->.9]

OpenersExampleSubsection2(Spacer1)CovarianceEstimatorFunction  (1)

Fit a logit model:

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

OpenersExampleSubsection3(Spacer1)DispersionEstimatorFunction  (1)

Fit a logit model:

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 (χ^2):

logit["CovarianceMatrix",DispersionEstimatorFunction->"PearsonChiSquare"]

OpenersExampleSubsection4(Spacer1)IncludeConstantBasis  (1)

Fit a logit model:

data={{0,1},{1,0},{3,1},{5,0}};

LogitModelFit[data,x,x]//Normal

Fit the model with no constant term:

LogitModelFit[data,x,x,IncludeConstantBasis->False]//Normal

OpenersExampleSubsection5(Spacer1)LinearOffsetFunction  (1)

Fit data to a logit model:

data={{0,1},{1,0},{3,1},{5,0}};

LogitModelFit[data,x,x]//Normal

Fit data to a model with a known (RefLink[Sqrt, paclet:ref/Sqrt])[x] term:

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

OpenersExampleSubsection6(Spacer1)NominalVariables  (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]//Normal

OpenersExampleSubsection7(Spacer1)Weights  (1)

Fit a model using equal weights:

data={{0,1},{1,0},{3,1},{5,0}};

LogitModelFit[data,x,x]//Normal

Give explicit weights for the data points:

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

OpenersExampleSubsection8(Spacer1)WorkingPrecision  (1)

Use (RefLink[WorkingPrecision, paclet:ref/WorkingPrecision]) to get higher precision in parameter estimates:

data=Table[{x,(10-x)/10},{x,10}]

logit=LogitModelFit[data,x,x,WorkingPrecision->30]

Obtain the fitted function:

logit["BestFit"]

Reduce the precision in property computations after the fitting:

logit["BestFit",WorkingPrecision->MachinePrecision]

OpenersExampleSection4(Spacer1)Properties & Relations  (4)

A default "Binomial" model from (RefLink[GeneralizedLinearModelFit, paclet:ref/GeneralizedLinearModelFit]) is equivalent to the model for (RefLink[LogitModelFit, paclet:ref/LogitModelFit]):

data=Table[{i,RandomReal[{i-1,i}]/10},{i,10}];

GeneralizedLinearModelFit[data,x,x,ExponentialFamily->"Binomial"]//Normal

LogitModelFit[data,x,x]//Normal

(RefLink[ProbitModelFit, paclet:ref/ProbitModelFit]) is equivalent to a "Binomial" model with "ProbitLink":

GeneralizedLinearModelFit[data,x,x,ExponentialFamily->"Binomial",LinkFunction->"ProbitLink"]//Normal

ProbitModelFit[data,x,x]//Normal

(RefLink[LogitModelFit, paclet:ref/LogitModelFit]) assumes binomially distributed responses:

data=Table[{i,RandomReal[{i-1,i}]/10},{i,10}];

lm=LogitModelFit[data,x,x]

(RefLink[NonlinearModelFit, paclet:ref/NonlinearModelFit]) assumes normally distributed responses:

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

The fits are not identical:

{Normal[lm],Normal[nm]}

Plot[{lm[x],nm[x]},{x,1,5}]

(RefLink[LogitModelFit, paclet:ref/LogitModelFit]) will use the time stamps of a (RefLink[TimeSeries, paclet:ref/TimeSeries]) as variables:

ts1=TimeSeries[];

ts1["Times"]

LogitModelFit[ts1,x,x]

Rescale the time stamps and fit again:

ts2=TimeSeriesRescale[ts1,{.1,2}]

ts2["Times"]

LogitModelFit[ts2,x,x]

Find fit for the values:

LogitModelFit[ts1["Values"],x,x]

(RefLink[LogitModelFit, paclet:ref/LogitModelFit]) acts pathwise on a multipath (RefLink[TemporalData, paclet:ref/TemporalData]):

LogitModelFit[TemporalData[],x,x]

OpenersExampleSection5(Spacer1)Possible Issues  (1)

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

LogitModelFit[Range[5],x,x]

LogitModelFit[Table[{i,2i},{i,10}],x,x]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[GeneralizedLinearModelFit, paclet:ref/GeneralizedLinearModelFit])  ▪  (RefLink[ProbitModelFit, paclet:ref/ProbitModelFit])  ▪  (RefLink[LinkFunction, paclet:ref/LinkFunction])  ▪  (RefLink[ExponentialFamily, paclet:ref/ExponentialFamily])  ▪  (RefLink[TimeSeriesModelFit, paclet:ref/TimeSeriesModelFit])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Statistical Model Analysis, paclet:tutorial/StatisticalModelAnalysis])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Statistical Model Analysis, paclet:guide/StatisticalModelAnalysis])}})}})