With results from fitlm, how does one disentangle the linear regression's slope? I'm simply trying to plot the regression over the data. (I expect this'll be an easy answer; thank you in advance.)
MATLAB: Obtaining slope from fitlm results
fitlmlinear regressionplotslopeStatistics and Machine Learning Toolbox
Related Solutions
Follow through the documentation -- click on the mdl active link of the LHS output variable in the Description section which will take you to the Output Arguments section. Then click on the Linear model link that takes to the description of the LinearModel class and associated methods. There, there is an explanation of the displayed output.
Also, to use the model, there's link to Predict or Simulate Responses to New Data as an example on the fitlm page.
In short, there are three possible ways...
- predict
- random
- feval
which are all illustrated at the above example.
For some reason TMW did not implement the linear model class in the Statistics TB similarly to the Curve Fitting TB fit object, such that simply invoking the object with arguments returns a predicted value for those inputs. Why not is anybody's guess; just another one of the cases where the development teams seem disjointed and leave inconsistent user interfaces.
All in all, the CF TB is more convenient in that manner; the Stat TB implementation will provide the additional statistical information that you much compute on your own with CF TB ... which to use depends on what your output needs are (and which TB'es you have installed, of course).
ADDENDUM
The model is of form
MPG ~ 1 + Weight + Acceleration ~ Intercept + Weight + Acceleration
so from the output table you've got the coefficients of the fit are the Estimate for each of the three terms. The other columns are the estimate of error of that coefficient and the t-statstic for testing the hypothesis the coefficient could be zero and the probability of randomly having that particular value. That stuff is what is in a standard statistics text on regression and is somewhat outside the scope of Matlab other than to tell you what the terms are as far as more definition. But, through the other links, there is some description in the example on interpretation given in other comment below.
Again, if you are just wanting a fit and to compute some additional newer values for estimates, the Curve Fitting TB cfit is somewhat simpler to use in that manner. Why TMW insists on having all these overlapping functionalities that have so wildly inconsistent interfaces remains a major mystery (well, not so much a mystery but aggravation).
The other functions are the ways to use the model; didn't really have to do with what the printed output table means...
There is only a single regressor and a response variable so despite the comment in the code, this is NOT multiple regression (well, ok, technically it is but for the degenerate case of Nregressors==1).
The above code is identically(*) the same in result as would be
bQTc2 = polyfit(AFall(4,:)',AFall(1,:)',1); % fit QTc=bQTc2(1)*RR + bQTc2(2) <--> y=mx+b
%plot linear regression response against RR
scatter(AFall(4,:), polyval(bQTc2,AFall(4,:)),'xr') % put QTc_hat on plot as well...
All regress is doing is solving for the same coefficients of slope, interecept using a more general routine to do so but there's no data for more coefficients. polyfit supplies the needed column of ones to solve for the intercept term automagically whereas in regress, being a general routine, you have to supply the variables including the intercept term explicitly.
See
doc regressdoc polyfit
for details.
One can only presume that since there are at least four variables (rows) in the original array that possibly the original code did, in fact, try to regress the dependent variable on more than just the one variable; hence the comments and use of regress. It would appear that if so, the results weren't promising enough to have kept and the developer just pruned the additional variable(s) from the fitting expression and didn't modify the comments to match.
() Identical excepting the order of the coefficients is reversed; |*polyfit| returns coefficients for
p(x)=p(1)*x^n + p(2)*x^(n−1) + ... + p(n)*x + p(n+1)
whereas the model matrix as written above for regress has the column of ones for the intercept first so that will be the first coefficient returned; iow, the order of bQTc2 values is reversed between the two formulations. That is taken care of as I wrote it as polyval is written as the boon companion of its brother and expects the coefficient array in the above order. NB: the explicit evaluation expression the original author wrote is reversed sense in keeping with the model as specified.
Best Answer