LinearModelFit

LinearModelFit[{y1,y2,},{f1,f2,},x]
constructs a linear model of the form that fits the for successive x values 1, 2, .

LinearModelFit[{{x11,x12,,y1},{x21,x22,,y2},},{f1,f2,},{x1,x2,}]
constructs a linear model of the form where the depend on the variables .

LinearModelFit[{m,v}]
constructs a linear model from the design matrix m and response vector v.

Details and OptionsDetails and Options

  • LinearModelFit returns a symbolic FittedModel object to represent the linear model it constructs. The properties and diagnostics of the model can be obtained from model["property"].
  • The value of the best-fit function from LinearModelFit at a particular point , can be found from .
  • With data in the form , the number of coordinates , , should equal the number of variables .
  • Data in the form is equivalent to data in the form .
  • LinearModelFit produces a linear model of the form under the assumption that the original are independent normally distributed with mean and common standard deviation.
  • LinearModelFit takes the following options:
  • ConfidenceLevel95/100confidence level to use for parameters and predictions
    IncludeConstantBasisTruewhether to include a constant basis function
    LinearOffsetFunctionNoneknown offset in the linear predictor
    NominalVariablesNonevariables considered as nominal or categorical
    VarianceEstimatorFunctionAutomaticfunction for estimating the error variance
    WeightsAutomaticweights for data elements
    WorkingPrecisionAutomaticprecision used in internal computations
  • With the setting IncludeConstantBasis->False, a model of the form is fitted.
  • With the setting LinearOffsetFunction->h, a model of the form is fitted.
  • With ConfidenceLevel->p, probability-p confidence intervals are computed for parameter and prediction intervals.
  • With the setting Weights->{w1,w2,}, the error variance for is assumed to be . By default, unit weights are used.
  • With the setting VarianceEstimatorFunction->f, the variance is estimated by , where is the list of residuals and is the list of weights for the measurements .
  • Using VarianceEstimatorFunction->(1&) and Weights->{1/Δy12,1/Δy22,}, is treated as the known uncertainty of measurement and parameter standard errors are effectively computed only from the weights.
  • Properties related to data and the fitted function obtained using model["property"] include:
  • "BasisFunctions"list of basis functions
    "BestFit"fitted function
    "BestFitParameters"parameter estimates
    "Data"the input data or design matrix and response vector
    "DesignMatrix"design matrix for the model
    "Function"best fit pure function
    "Response"response values in the input data
  • Types of residuals include:
  • "FitResiduals"difference between actual and predicted responses
    "StandardizedResiduals"fit residuals divided by the standard error for each residual
    "StudentizedResiduals"fit residuals divided by single deletion error estimates
  • Properties related to the sum of squared errors include:
  • "ANOVATable"analysis of variance table
    "ANOVATableDegreesOfFreedom"degrees of freedom from the ANOVA table
    "ANOVATableEntries"unformatted array of values from the table
    "ANOVATableFStatistics"F-statistics from the table
    "ANOVATableMeanSquares"mean square errors from the table
    "ANOVATablePValues"values from the table
    "ANOVATableSumsOfSquares"sums of squares from the table
    "CoefficientOfVariation"response mean divided by the estimated standard deviation
    "EstimatedVariance"estimate of the error variance
    "PartialSumOfSquares"changes in model sum of squares as nonconstant basis functions are removed
    "SequentialSumOfSquares"the model sum of squares partitioned componentwise
  • Properties and diagnostics for parameter estimates include:
  • "CorrelationMatrix"parameter correlation matrix
    "CovarianceMatrix"parameter covariance matrix
    "EigenstructureTable"eigenstructure of the parameter correlation matrix
    "EigenstructureTableEigenvalues"eigenvalues from the table
    "EigenstructureTableEntries"unformatted array of values from the table
    "EigenstructureTableIndexes"index values from the table
    "EigenstructureTablePartitions"partitioning from the table
    "ParameterTable"table of fitted parameter information
    "ParameterConfidenceIntervals"parameter confidence intervals
    "ParameterConfidenceIntervalTable"table of confidence interval information for the fitted parameters
    "ParameterConfidenceIntervalTableEntries"unformatted array of values from the table
    "ParameterConfidenceRegion"ellipsoidal parameter confidence region
    "ParameterErrors"standard errors for parameter estimates
    "ParameterPValues"values for parameter statistics
    "ParameterTableEntries"unformatted array of values from the table
    "ParameterTStatistics"statistics for parameter estimates
    "VarianceInflationFactors"list of inflation factors for the estimated parameters
  • Properties related to influence measures include:
  • "BetaDifferences"DFBETAS measures of influence on parameter values
    "CatcherMatrix"catcher matrix
    "CookDistances"list of Cook distances
    "CovarianceRatios"COVRATIO measures of observation influence
    "DurbinWatsonD"DurbinWatson statistic for autocorrelation
    "FitDifferences"DFFITS measures of influence on predicted values
    "FVarianceRatios"FVARATIO measures of observation influence
    "HatDiagonal"diagonal elements of the hat matrix
    "SingleDeletionVariances"list of variance estimates with the ^(th) data point omitted
  • Properties of predicted values include:
  • "MeanPredictionBands"confidence bands for mean predictions
    "MeanPredictionConfidenceIntervals"confidence intervals for the mean predictions
    "MeanPredictionConfidenceIntervalTable"table of confidence intervals for the mean predictions
    "MeanPredictionConfidenceIntervalTableEntries"unformatted array of values from the table
    "MeanPredictionErrors"standard errors for mean predictions
    "PredictedResponse"fitted values for the data
    "SinglePredictionBands"confidence bands based on single observations
    "SinglePredictionConfidenceIntervals"confidence intervals for the predicted response of single observations
    "SinglePredictionConfidenceIntervalTable"table of confidence intervals for the predicted response of single observations
    "SinglePredictionConfidenceIntervalTableEntries"unformatted array of values from the table
    "SinglePredictionErrors"standard errors for the predicted response of single observations
  • Properties that measure goodness of fit include:
  • "AdjustedRSquared" adjusted for the number of model parameters
    "AIC"Akaike Information Criterion
    "AICc"finite sample corrected AIC
    "BIC"Bayesian Information Criterion
    "RSquared"coefficient of determination
  • In LinearModelFit[{m,v }], the design matrix m is formed from the values of basis functions at data points in the form . The response vector v is the list of responses .
  • 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 can be specified using the form LinearModelFit[{m,v},{f1,f2,}].

ExamplesExamplesopen allclose all

Basic Examples  (1)Basic Examples  (1)

Fit a linear model to some data:

In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Out[2]=

Obtain the functional form:

In[3]:=
Click for copyable input
Out[3]=

Evaluate the model at a point:

In[4]:=
Click for copyable input
Out[4]=

Visualize the fitted function with the data:

In[5]:=
Click for copyable input
Out[5]=

Extract information about the fitting:

In[6]:=
Click for copyable input
Out[6]=

Plot the residuals:

In[7]:=
Click for copyable input
Out[7]=
Introduced in 2008
(7.0)