How to do weighted least square rgression?

19 Ansichten (letzte 30 Tage)
Pooneh Shah Malekpoor
Pooneh Shah Malekpoor am 6 Okt. 2023
Kommentiert: Torsten am 1 Dez. 2023
Hello
I want to fit an exponential curve to my data using MatLab. Could you please guide me how can I write a code to fit this through weighted least square reression? The weight matrix is as follows. I could not find any instruction or sample code to do so!
weight=[18.5204555170429; 24.8007492441765; 21.4204953742493; 12.0007299687922; 5.17482448096073;2.24987321147564]
x=[1.5;4.5;7.5;10.5;13.5;16.5]
y=[0.466132177250491;0.307694759285704;0.477550022494737;0.489169081512968;0.439027124884140;0.306938063199741]
Thanks

Antworten (1)

Star Strider
Star Strider am 6 Okt. 2023
Bearbeitet: Star Strider am 6 Okt. 2023
One option is to use fitlm
weight=[18.5204555170429; 24.8007492441765; 21.4204953742493; 12.0007299687922; 5.17482448096073;2.24987321147564];
x=[1.5;4.5;7.5;10.5;13.5;16.5];
y=[0.466132177250491;0.307694759285704;0.477550022494737;0.489169081512968;0.439027124884140;0.306938063199741];
mdl = fitlm(x,y, 'Weights',weight)
mdl =
Linear regression model: y ~ 1 + x1 Estimated Coefficients: Estimate SE tStat pValue _________ _________ ______ ________ (Intercept) 0.39951 0.07398 5.4003 0.005691 x1 0.0031898 0.0099772 0.3197 0.76519 Number of observations: 6, Error degrees of freedom: 4 Root Mean Squared Error: 0.353 R-squared: 0.0249, Adjusted R-Squared: -0.219 F-statistic vs. constant model: 0.102, p-value = 0.765
figure
plot(mdl)
grid
I assume that you want to do a linear regression, since you did not mention a nonllinear model of any sort.
.
  6 Kommentare
Shiba shankar
Shiba shankar am 1 Dez. 2023
how to know then,any steps to know
Torsten
Torsten am 1 Dez. 2023
The explanations given here might help:

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by