({{, (RefLink[LinearModelFit, paclet:ref/LinearModelFit])[{(Subscript[y, 1]),(Subscript[y, 2]),…},{(Subscript[f, 1]),(Subscript[f, 2]),…},x]
constructs a linear model of the form (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[LinearModelFit, paclet:ref/LinearModelFit])[{{(Subscript[x, 11]),(Subscript[x, 12]),…,(Subscript[y, 1])},{(Subscript[x, 21]),(Subscript[x, 22]),…,(Subscript[y, 2])},…},{(Subscript[f, 1]),(Subscript[f, 2]),…},{(Subscript[x, 1]),(Subscript[x, 2]),…}]
constructs a linear model of the form (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[LinearModelFit, paclet:ref/LinearModelFit])[{m,v}]
constructs a linear model from the design matrix m and response vector v.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[LinearModelFit, paclet:ref/LinearModelFit]) returns a symbolic (RefLink[FittedModel, paclet:ref/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 (RefLink[LinearModelFit, paclet:ref/LinearModelFit]) 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 equal the number of variables (Subscript[x, i]).

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[LinearModelFit, paclet:ref/LinearModelFit]) produces a linear model of the form (OverHat[y])=(Subscript[β, 0])+(Subscript[β, 1])(Subscript[f, 1])+(Subscript[β, 2])(Subscript[f, 2])+… under the assumption that the original (Subscript[y, i]) are independent normally distributed with mean (Subscript[(OverHat[y]), i]) and common standard deviation.

(RefLink[LinearModelFit, paclet:ref/LinearModelFit]) takes the following options:

With the setting (RefLink[IncludeConstantBasis, paclet:ref/IncludeConstantBasis])->(RefLink[False, paclet:ref/False]), a model of the form (Subscript[β, 1])(Subscript[f, 1])+(Subscript[β, 2])(Subscript[f, 2])+… is fitted. The option (RefLink[IncludeConstantBasis, paclet:ref/IncludeConstantBasis]) is ignored if the design matrix is specified in the input.

With the setting (RefLink[LinearOffsetFunction, paclet:ref/LinearOffsetFunction])->h, a model of the form h((Subscript[x, 1]), (Subscript[x, 2]), …) +(Subscript[β, 0])+(Subscript[β, 1])(Subscript[f, 1])+(Subscript[β, 2])(Subscript[f, 2])+… is fitted.

With (RefLink[ConfidenceLevel, paclet:ref/ConfidenceLevel])->p, probability-p confidence intervals are computed for parameter and prediction intervals.

With the setting (RefLink[Weights, paclet:ref/Weights])->{(Subscript[w, 1]),(Subscript[w, 2]),…}, the error variance for (Subscript[y, i]) is assumed to be (σ^2)/(Subscript[w, i]). By default, unit weights are used.

With the setting (RefLink[VarianceEstimatorFunction, paclet:ref/VarianceEstimatorFunction])->f, the variance is estimated by f[res,w], where res={(Subscript[y, 1])-(Subscript[(OverHat[y]), 1]),(Subscript[y, 2])-(Subscript[(OverHat[y]), 2]),…} is the list of residuals and w={(Subscript[w, 1]),(Subscript[w, 2]),…} is the list of weights for the measurements (Subscript[y, i]).

Using (RefLink[VarianceEstimatorFunction, paclet:ref/VarianceEstimatorFunction])->(1&) and (RefLink[Weights, paclet:ref/Weights])->{1/((Subscript[Δy, 1])^2),1/((Subscript[Δy, 2])^2),…}, (Subscript[Δy, i]) is treated as the known uncertainty of measurement (Subscript[y, i]) and parameter standard errors are effectively computed only from the weights.

Properties related to data and the fitted function obtained using model["property"] include:

Types of residuals include:

Properties related to the sum of squared errors include:

Properties and diagnostics for parameter estimates include:

Properties related to influence measures include:

Properties of predicted values include:

Properties that measure goodness of fit include:

For the properties "RSquared" and "AdjustedRSquared", the computation of the total sum of squares is mean adjusted only when the constant basis is included.

In (RefLink[LinearModelFit, paclet:ref/LinearModelFit])[{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])=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[LinearModelFit, paclet:ref/LinearModelFit])[{m,v},{(Subscript[f, 1]),(Subscript[f, 2]),…}].

OpenersPrimaryExamplesSection(Spacer1)Examples  (35)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Fit a linear model to some data:

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

lm=LinearModelFit[data,x,x]

Obtain the functional form:

Normal[lm]

Evaluate the model at a point:

lm[2.3]

Visualize the fitted function with the data:

Show[ListPlot[data],Plot[lm[x],{x,0,5}],Frame->True]

Extract information about the fitting:

lm["FitResiduals"]

Plot the residuals:

ListPlot[lm["FitResiduals"], Filling->Axis]

OpenersExampleSection1(Spacer1)Scope  (11)

Fit a model of more than one variable:

data=Flatten[Table[{x,y,Sin[x+y]},{x,5},{y,5}],1];

LinearModelFit[data,{x,y},{x,y}]

Normal[%]

Fit data to a linear combination of nonlinear functions of predictor variables:

LinearModelFit[data,{Sin[x],Cos[y]},{x,y}]//Normal

Fit a model with categorical predictor variables:

data={{a,1},{b,2},{a,1.8},{b,2.5}};

nom=LinearModelFit[data,x,x,NominalVariables->x]

Obtain an analysis of variance table for the model:

nom["ANOVATable"]

Extract the unformatted array of values:

nom["ANOVATableEntries"]

Extract the mean squares values from the table:

nom["ANOVATableMeanSquares"]

Fit a model given a design matrix and response vector:

dm={{1,1},{1,2},{1,3},{1,4}};
resp={1,3,6,10};LinearModelFit[{dm,resp}]

See the functional form:

Normal[%]

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

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

Obtain a list of available properties for a linear model:

lm=LinearModelFit[Range[10],x^2,x]

lm["Properties"]

OpenersExampleSubsection0(Spacer1)Properties  (7)

OpenersExampleSubsubsection0(Spacer1)Data & Fitted Functions  (1)

Fit a linear model:

data=Block[{i,j},Table[{i=RandomReal[10],j=RandomReal[10],4i+2j+RandomReal[]},{10}]];
lm=LinearModelFit[data,{x,y},{x,y}]

Extract the original data:

lm["Data"]

Obtain and plot the best fit:

{fit = lm["BestFit"],Show[Plot3D[fit,{x,0,10},{y,0,10},PlotRange->All], Graphics3D[{PointSize[0.025],Point[data]}]]}

Obtain the fitted function as a pure function:

lm["Function"]

Get the design matrix and response vector for the fitting:

MatrixForm/@lm[{"DesignMatrix","Response"}]

OpenersExampleSubsubsection1(Spacer1)Residuals  (1)

Examine residuals for a fit:

lm=LinearModelFit[RandomReal[10,{100,3}],{x,y},{x,y}]

{fr,sr1,sr2}=lm[{"FitResiduals","StandardizedResiduals","StudentizedResiduals"}];

Visualize the raw residuals:

ListPlot[fr]

Visualize scaled residuals in stem plots:

Map[ListPlot[#,Filling->0]&,{sr1,sr2}]//Row

Plot the absolute differences between the standardized and Studentized residuals:

ListPlot[sr1-sr2]

OpenersExampleSubsubsection2(Spacer1)Sums of Squares  (1)

Fit a linear model to some data:

data=Flatten[Table[{x,y,.2+.3x+.1y+RandomReal[{-1,1}]},{x,RandomReal[5,10]},{y,RandomReal[5,10]}],1];lm=LinearModelFit[data,{x,y},{x,y}]

Extract the estimated error variance and coefficient of variation:

lm[{"EstimatedVariance","CoefficientOfVariation"}]

Obtain an analysis of variance table for the model:

lm["ANOVATable"]

Get the F-statistics from the table:

lm["ANOVATableFStatistics"]

Extract the numeric entries from the table:

vals=lm["ANOVATableEntries"]

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

Grid[Join[{{"","d.f.","s.o.s.","m.s.","f","p(F>f)"}},Join[{{"x"},{"y"},{"error"},{"sum"}},vals,2]],Alignment->Right]

OpenersExampleSubsubsection3(Spacer1)Parameter Estimation Diagnostics  (1)

Obtain a formatted table of parameter information:

data=Table[{x,.2+.3x+.1Sin[x]+RandomReal[{-.2,.2}]},{x,RandomReal[5,100]}];lm=LinearModelFit[data,{x,Sin[x],Cos[x]},x]

lm["ParameterTable"]

Obtain an analysis of variance table for the model:

lm["ParameterTStatistics"]

Get the unformatted array of values from the table:

vals=lm["ParameterTableEntries"]

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

Grid[Join[{{f,(OverHat[β]),(OverHat[σ]),t,P[Abs[T]>Abs[t]]}},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[σ]),t,P[Abs[T]>Abs[t]]}}]//TraditionalForm

OpenersExampleSubsubsection4(Spacer1)Influence Measures  (1)

Fit some data containing extreme values to a linear model:

data=Table[{i,2+4i-Log[i]+RandomReal[]},{i,RandomReal[{1,10},20]}];
data[[{3,8},-1]]=data[[{3,8},-1]]+5;
lm=LinearModelFit[data,{x,Log[x]},x]

Use single deletion variances to check the impact on the error variance of removing each point:

ListPlot[lm["SingleDeletionVariances"],PlotRange->{0,All},Filling->0]

Check Cook distances to identify highly influential points:

ListPlot[lm["CookDistances"],PlotRange->{0,All},Filling->0]

Use DFFITS values to assess the influence of each point on the fitted values:

ListPlot[lm["FitDifferences"],PlotRange->All,Filling->0]

Use DFBETAS values to assess the influence of each point on each estimated parameter:

MapThread[ListPlot[#1,PlotRange->All,Filling->0,PlotLabel->#2]&,{Transpose[lm["BetaDifferences"]],{"(Subscript[β, 1])","(Subscript[β, 2])","(Subscript[β, 3])"}}]//Row

OpenersExampleSubsubsection5(Spacer1)Prediction Values  (1)

Fit a linear model:

data=Flatten[Table[{x,y,3Exp[-x]+1.2y+RandomReal[{-1,1}]},{x,RandomReal[5,3]},{y,RandomReal[5,3]}],1];lm=LinearModelFit[data,{Exp[-x],y},{x,y}]

Plot the predicted values against the observed values:

ListPlot[Transpose[lm[{"Response","PredictedResponse"}]],FrameLabel->{"observed","predicted"},Frame->True,Axes->False]

Obtain tabular results for mean and single prediction confidence intervals:

lm[{"MeanPredictionConfidenceIntervalTable","SinglePredictionConfidenceIntervalTable"}]

Get the single prediction intervals from the table:

lm["SinglePredictionConfidenceIntervals"]

Extract 99% mean prediction bands:

lm["MeanPredictionBands",ConfidenceLevel->.99]

OpenersExampleSubsubsection6(Spacer1)Goodness-of-Fit Measures  (1)

Obtain a table of goodness-of-fit measures for a linear model:

data=Flatten[Table[{i,j,RandomReal[10],30i-10j+RandomReal[5]},{i,RandomReal[10,5]},{j,RandomReal[10,5]}],1];

lm=LinearModelFit[data,{x,y,z},{x,y,z}]

Grid[Transpose[{#,lm[#]}&[{"AdjustedRSquared","AIC","BIC","RSquared"}]],Alignment->Left]

Compute goodness-of-fit measures for all possible linear submodels:

sub=Table[Join[{i},LinearModelFit[data,i,{x,y,z}][{"AdjustedRSquared","RSquared","AIC","BIC"}]],{i,Subsets[{x,y,z}]}]

Rank the models by (R^2):

Grid[Join[{{"Model","AdjustedRSquared","RSquared","AIC","BIC"}},SortBy[sub,-#[[3]]&]]]

Rank the models by adjusted (R^2), which penalizes for adding terms:

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

OpenersExampleSection2(Spacer1)Generalizations & Extensions  (1)

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

lm=LinearModelFit[RandomReal[10,20],{x,Log[x]},x]

Integrate symbolically and numerically:

Integrate[lm[x],x]

NIntegrate[lm[x],{x,1,5}]

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

FindRoot[lm[x]==5.5,{x,10}]

OpenersExampleSection3(Spacer1)Options  (7)

OpenersExampleSubsection1(Spacer1)ConfidenceLevel  (1)

The default gives 95% confidence intervals:

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

lm=LinearModelFit[data,x,x]

lm["ParameterConfidenceIntervals"]

Use 99% intervals instead:

lm=LinearModelFit[data,x,x,ConfidenceLevel->.99]

lm["ParameterConfidenceIntervals"]

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

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

OpenersExampleSubsection2(Spacer1)IncludeConstantBasis  (1)

Fit a simple linear regression model:

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

LinearModelFit[data,x,x]//Normal

Fit the linear model with intercept zero:

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

OpenersExampleSubsection3(Spacer1)LinearOffsetFunction  (1)

Fit data to a linear model:

data={{0,1},{1,1.5},{3,2},{5,4}};

LinearModelFit[data,x,x]//Normal

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

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

OpenersExampleSubsection4(Spacer1)NominalVariables  (1)

Fit data treating the first variable as a nominal variable:

data={{a,0,1},{b,2,2},{a,2,1.8},{b,0,2.5}};nom=LinearModelFit[data,{x,y},{x,y},NominalVariables->x]

Normal[nom]

Treat both variables as nominal:

LinearModelFit[data,{x,y},{x,y},NominalVariables->All]//Normal

OpenersExampleSubsection5(Spacer1)VarianceEstimatorFunction  (1)

Use the default unbiased estimate of error variance:

lm=LinearModelFit[Range[10]^2,{x},{x}]

lm["EstimatedVariance"]

Assume a known error variance:

lm["EstimatedVariance",VarianceEstimatorFunction->(20&)]

Estimate the variance by the mean squared error:

lm["EstimatedVariance",VarianceEstimatorFunction->(Mean[#^2]&)]

OpenersExampleSubsection6(Spacer1)Weights  (1)

Fit a model using equal weights:

LinearModelFit[Range[10]^2,x,x]//Normal

Give explicit weights for the data points:

LinearModelFit[Range[10]^2,x,x,Weights->1/Range[10]]//Normal

OpenersExampleSubsection7(Spacer1)WorkingPrecision  (1)

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

data=Table[{x,x^3},{x,10}]

lm=LinearModelFit[data,{x,x^2},x,WorkingPrecision->50]

Obtain the fitted function:

lm["BestFit"]

Reduce the precision in property computations after the fitting:

lm["BestFit",WorkingPrecision->20]

OpenersExampleSection4(Spacer1)Applications  (6)

Fit the first 100 primes to a linear model:

lm=LinearModelFit[Array[Prime,100],x,x]

Visualize the fit:

Show[ListPlot[lm["Data"],PlotStyle->Orange],Plot[lm[x],{x,0,100}]]

The systematic trend in the residuals violates the assumption of independent normal errors:

ListPlot[lm["FitResiduals"]]

Fit a linear model of multiple variables:

data=Map[{#[[1]],#[[2]],#[[3]],1.2+(3.7+RandomReal[{-1,1}])#[[1]]-2#[[2]]+23.4#[[3]]}&,RandomReal[10,{100,3}]];

lm=LinearModelFit[data,{x,y,z},{x,y,z}]

Visually inspect the residuals by data point:

ListPlot[lm["FitResiduals"],Frame->True,PlotRange->All]

Plot the residuals against each predictor variable:

Table[ListPlot[Transpose[{data[[All,i]],lm["FitResiduals"]}],Frame->True,FrameLabel->{{x,y,z}[[i]],"Residual"}],{i,3}]//Row

Plot Cook's distances to diagnose leverage:

cd=lm["CookDistances"];

ListPlot[cd,Filling->0,Frame->True,AxesOrigin->{0,0},PlotRange->All,PlotLabel->"Cook's Distances"]

Find the positions of distances above a given cutoff value:

Position[cd,_?(#>.05&)]

Extract the associated data points:

Extract[data,%]

Use q-q plots to check the assumption of normal errors:

lm=LinearModelFit[RandomReal[10,{50,4}],{x,y,z},{x,y,z}]

Needs["StatisticalPlots`"]

Compare standardized residuals to standard normal values:

QuantilePlot[lm["StandardizedResiduals"],Table[InverseCDF[NormalDistribution[],q],{q,1/100,99/100,1/50}]]

Do the comparison with Studentized residuals:

QuantilePlot[lm["StudentizedResiduals"],Table[InverseCDF[NormalDistribution[],q],{q,1/100,99/100,1/50}]]

Simulate some data with a continuous and a nominal variable:

groups={"control","treatment 1","treatment 2","treatment 3"};
data=BlockRandom[SeedRandom[123];
Block[{vals,times,rand},
vals=RandomChoice[groups,100];
times=RandomInteger[10,100];
rand=RandomReal[1,100];
Transpose[{vals,times,(vals/.Thread[Rule[groups,{.16,.34,.57,1.1}]])-.05 times+rand}]]];

Fit an analysis of covariance model to the data:

lm=LinearModelFit[data,{treatment,time},{treatment,time},NominalVariables->treatment];

Obtain an analysis of variance table for the model:

lm["ANOVATable"]

Group the data by treatment:

grps=Drop[GatherBy[Sort[data],First],None,None,1];

Visualize the grouped data and associated curves:

Show[ListPlot[grps,PlotRange->All],Plot[Evaluate[Map[lm[#,t]&,groups]],{t,0,10},PlotLegends->groups]]

Use properties to compute additional results:

data=Flatten[Table[{x,y,z,1.2x-3.4y+10z+RandomReal[10]},{x,RandomReal[10,3]},{y,RandomReal[10,3]},{z,RandomReal[10,3]}],2];

lm=LinearModelFit[data,{x,y,z},{x,y,z}]

Extract the design matrix and residuals:

{desmat,resids}=lm[{"DesignMatrix","FitResiduals"}];

Compute White's heteroskedasticity-consistent covariance estimate:

(wc=With[{inv=Inverse[Transpose[desmat].desmat],xresid=resids*desmat},
inv.Transpose[xresid].xresid.inv])//MatrixForm

Compare with the covariance assuming homoskedasticity:

lm["CovarianceMatrix"]//MatrixForm

Compare standard errors based on the two covariance estimates:

Sqrt[Diagonal[wc]]

lm["ParameterErrors"]

Perform a Breusch–Pagan test:

data=Flatten[Table[{x,y,z,1.2x-3.4y+10z+RandomReal[10]},{x,RandomReal[10,3]},{y,RandomReal[10,3]},{z,RandomReal[10,3]}],2];

Fit a model:

lm1=LinearModelFit[data,{x,y,z},{x,y,z}]

Fit the squared errors to a model with the same predictors:

lm2=LinearModelFit[Block[{newdata=data},newdata[[All,-1]]=lm1["FitResiduals"]^2;newdata],{x,y,z},{x,y,z}]

Compute the Breusch–Pagan test statistic:

bp=With[{sqResids=lm1["FitResiduals"]^2},(Variance[sqResids](Length[data]-1)-Total[lm2["FitResiduals"]^2])/2/(Total[sqResids]/Length[data])^2]

Compute the p-value:

1-CDF[ChiSquareDistribution[Length[lm1["BestFitParameters"]]-1],bp]

OpenersExampleSection5(Spacer1)Properties & Relations  (9)

(RefLink[DesignMatrix, paclet:ref/DesignMatrix]) constructs the design matrix used by (RefLink[LinearModelFit, paclet:ref/LinearModelFit]):

data=Table[{i,RandomReal[]},{i,5}]

DesignMatrix[data,x,x]//MatrixForm

lm=LinearModelFit[data,x,x];

lm["DesignMatrix"]//MatrixForm

By default, (RefLink[LinearModelFit, paclet:ref/LinearModelFit]) and (RefLink[GeneralizedLinearModelFit, paclet:ref/GeneralizedLinearModelFit]) fit equivalent models:

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

LinearModelFit[data,x,x]

GeneralizedLinearModelFit[data,x,x]

(RefLink[LinearModelFit, paclet:ref/LinearModelFit]) fits linear models assuming normally distributed errors:

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

LinearModelFit[data,x^2,x]

(RefLink[NonlinearModelFit, paclet:ref/NonlinearModelFit]) fits nonlinear models assuming normally distributed errors:

NonlinearModelFit[data,a Exp[b x],{a,b},x]

(RefLink[Fit, paclet:ref/Fit]) and (RefLink[LinearModelFit, paclet:ref/LinearModelFit]) fit equivalent models:

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

Fit[data,{1,x^2},x]

lm=LinearModelFit[data,x^2,x]

(RefLink[LinearModelFit, paclet:ref/LinearModelFit]) allows for extraction of additional information about the fitting:

lm["FitResiduals"]

Fit a linear model to data:

data=Flatten[Table[{i,j,i+j+Exp[i-j]+RandomReal[2]},{i,5},{j,5}],1];

LinearModelFit[data,{x,y,Exp[x-y]},{x,y}]["BestFitParameters"]

Perform the same fitting using a design matrix and response vector:

dm=DesignMatrix[data,{x,y,Exp[x-y]},{x,y}];
resp=data[[All,-1]];

LinearModelFit[{dm,resp}]["BestFitParameters"]

Obtain the parameter estimates via (RefLink[LeastSquares, paclet:ref/LeastSquares]):

LeastSquares[dm,resp]

(RefLink[LinearModelFit, paclet:ref/LinearModelFit]) fits linear models:

data=Table[{i,i},{i,10}];

LinearModelFit[data,{x^2,Sin[x]},x]["BestFitParameters"]

(RefLink[FindFit, paclet:ref/FindFit]) gives parameter estimates for linear and nonlinear models:

FindFit[data,a+b x^2+c Sin[x],{a,b,c},x]

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

ts1=TimeSeries[];

ts1["Times"]

base={1,x,Exp[x]};

LinearModelFit[ts1,base,x]

Rescale the time stamps and fit again:

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

ts2["Times"]

LinearModelFit[ts2,base,x]

Find fit for the values:

LinearModelFit[ts1["Values"],base,x]

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

LinearModelFit[TemporalData[],{1,x,Exp[x]},x]

Do a simple linear model fit:

LinearModelFit[{{0,1},{1,0},{3,2},{5,4}},x,x]

%[2.3]

Do the same fit using a neural net with a single linear layer:

NetTrain[LinearLayer[],Rule@@@{{0,1},{1,0},{3,2},{5,4}}]

%[2.3]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[NonlinearModelFit, paclet:ref/NonlinearModelFit])  ▪  (RefLink[GeneralizedLinearModelFit, paclet:ref/GeneralizedLinearModelFit])  ▪  (RefLink[FittedModel, paclet:ref/FittedModel])  ▪  (RefLink[DesignMatrix, paclet:ref/DesignMatrix])  ▪  (RefLink[Fit, paclet:ref/Fit])  ▪  (RefLink[LeastSquares, paclet:ref/LeastSquares])  ▪  (RefLink[FindFit, paclet:ref/FindFit])  ▪  (RefLink[FindFormula, paclet:ref/FindFormula])  ▪  (RefLink[TimeSeriesModelFit, paclet:ref/TimeSeriesModelFit])  ▪  (RefLink[LinearLayer, paclet:ref/LinearLayer])}})}})

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

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Statistical Model Analysis, paclet:guide/StatisticalModelAnalysis])}, {▪(RefLinkPlain[Statistical Data Analysis, paclet:guide/Statistics])}, {▪(RefLinkPlain[Numerical Data, paclet:guide/NumericalData])}, {▪(RefLinkPlain[Life Sciences & Medicine: Data & Computation, paclet:guide/LifeSciencesAndMedicineDataAndComputation])}, {▪(RefLinkPlain[Scientific Data Analysis, paclet:guide/ScientificDataAnalysis])}, {▪(RefLinkPlain[Scientific Models, paclet:guide/ScientificModels])}, {▪(RefLinkPlain[Time Series Processing, paclet:guide/TimeSeries])}, {▪(RefLinkPlain[Financial & Economic Data, paclet:guide/FinancialAndEconomicData])}, {▪(RefLinkPlain[Financial Computation, paclet:guide/Finance])}})}})