How to obtain Std of Coefficients from Curve Fitting

조회 수: 45 (최근 30일)
George
George 2012년 4월 2일
답변: laurent jalabert 2021년 3월 14일
Dear folkers, I want to obtain standard deviation of coefficients after using curve fitting. but I couldn't find information from help documents. how can I get it? thanks!!
ex.: the general model is: f(x) = a*x +b Coefficients: a = 1.5 (-1 3) b = 2 (0.5 4.5) now, how do i get the "std" of "a" and "std" of "b"
thank you
  댓글 수: 1
George
George 2012년 4월 2일
if the general model is nonlinear, for example:
General model:
f(x) = (b-a)./(1+((x/x0).^k)) +a
Coefficients (with 95% confidence bounds):
a = 3.281 (2.625, 3.938)
b = 0.2708 (-0.1386, 0.6803)
k = 20.24 (-6.81, 47.3)
x0 = 13.51 (12.48, 14.54)
in this case, how can I obtain standard deviation or standard error, and convergence history? thank you!

댓글을 달려면 로그인하십시오.

채택된 답변

Richard Willey
Richard Willey 2012년 4월 2일
Hi George
Conveniently, 12a also has a function call NonLinearModel
%%Generate some data
X = 2* pi*rand(100,1);
X = sortrows(X);
Y = 9 + 7*sin(1*X + 3) + randn(100,1);
Generate a fit
myFit = NonLinearModel.fit(X,Y, 'y ~ b0 + b1*sin(b2*x1 + b3)', [9, 7, 1, 3])
Here's the output
myFit =
Nonlinear regression model:
y ~ b0 + b1*sin(b2*x1 + b3)
Estimated Coefficients:
Estimate SE tStat pValue
b0 8.9014 0.094189 94.506 1.5635e-96
b1 6.8951 0.13773 50.06 1.3538e-70
b2 1.0018 0.011212 89.356 3.1924e-94
b3 3.0188 0.038947 77.511 2.2541e-88
The one thing that you won't get is convergence history. If you need a complete description of the path that the solvers are following you're probably better off using Optimization Toolbox rather than Stats.
  댓글 수: 2
George
George 2012년 4월 2일
Hi Richard, thank you again.
I was trying to use NonLinearModel.fit, but it gives me error:
%%
load carbig
X = [Horsepower,Weight];
y = MPG;
modelfun = @(b,x)b(1) + b(2)*x(:,1).^b(3) + ...
b(4)*x(:,2).^b(5);
beta0 = [-50 500 -1 500 -1];
mdl = NonLinearModel.fit(X,y,modelfun,beta0)
??? Undefined variable "NonLinearModel" or class "NonLinearModel.fit".
I installed Stats tool box (11a)? do you know this is the reason (giving error) or not?
thank you!
Richard Willey
Richard Willey 2012년 4월 2일
LinearModel and NonLinearModel are new in 12a.
Prior to 12a, you can use nlinfit to perform the same analysis.

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Tom Lane
Tom Lane 2012년 4월 2일
편집: Tom Lane 2018년 5월 6일
You can get more information when you invoke the fit command:
[obj,gof,opt] = fit(...)
This gives the fitted obj, goodness-of-fit statistics, and optimization info.
The Curve Fitting output is aimed at confidence intervals rather than standard errors. The confidence intervals are roughly the estimated coefficient plus or minus two standard errors. If you have the Statistics Toolbox then you can find the confidence level you'd need to get intervals that are plus or minus one standard error, then pass that level into the confint method. Something like this:
level = 2*tcdf(-1,gof.dfe)
% confint(obj,level) <- this original is incorrect
confint(obj,1-level) %<- corrected
  댓글 수: 4
Pavel Kolesnichenko
Pavel Kolesnichenko 2018년 3월 30일
Hi Tom. I am also curious, why did you put -1 in tcdf function. Also, I reckon it should be
level = 1 - 2*tcdf(-1,gof.dfe)
Tom Lane
Tom Lane 2018년 5월 6일
The 1 comes from wanting 1 standard error. The negative sign is to get the level associated with 1 standard error below zero. The multiplication by 2 is to include the values beyond 2 standard error above the mean, by symmetry. You are right, to get a confidence level you should subtract from 1. I will try to correct that.

댓글을 달려면 로그인하십시오.


Richard Willey
Richard Willey 2012년 4월 2일
The 12a release of Statistics Toolbox has some very nice new capabilities for regression analysis.
%%Generate some data
X = linspace(1,100, 50);
X = X';
Y = 5*X + 50;
Y = Y + 20*randn(50,1);
%%Generate a fit
myFit = LinearModel.fit(X,Y)
The object that is generated by LinearModel includes the Standard Error as part of the default display.
myFit = LinearModel.fit(X,Y)
myFit =
Linear regression model:
y ~ 1 + x1
Estimated Coefficients:
Estimate SE tStat pValue
(Intercept) 63.499 7.0973 8.9469 8.4899e-12
x1 4.8452 0.12171 39.809 2.0192e-38
Number of observations: 50, Error degrees of freedom: 48
Root Mean Squared Error: 25.1
R-squared: 0.971, Adjusted R-Squared 0.97
F-statistic vs. constant model: 1.58e+03, p-value = 2.02e-38
Please note:
This same information is available in earlier versions of the product. For example, the second output from regress is "bint" which are the confidence intervals for the regression coefficients.
However, I think that the display capabilities for the LinearModel objects are a big improvement over what came before.
  댓글 수: 2
George
George 2012년 4월 2일
Hi Richard, thank you.
this seems for linear model. if my model is nonlinear, then how do I obtain find this information again?
again, thank you very much!
ex.:
General model:
f(x) = (b-a)./(1+((x/x0).^k)) +a
Coefficients (with 95% confidence bounds):
a = 3.281 (2.625, 3.938)
b = 0.2708 (-0.1386, 0.6803)
k = 20.24 (-6.81, 47.3)
x0 = 13.51 (12.48, 14.54)
Goodness of fit:
SSE: 6.448
R-square: 0.8444
Adjusted R-square: 0.8152
RMSE: 0.6348
George
George 2012년 4월 3일
Thank you for your help, Richard.

댓글을 달려면 로그인하십시오.


laurent jalabert
laurent jalabert 2021년 3월 14일

카테고리

Help CenterFile Exchange에서 Multiple Linear Regression에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by