Error in the intercept
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I think this might be a dumb question, but how do you find the error of the intercept for a straigh line graph that I have fittded using polyfit? and polyval. I got the error for the slope by doing something like this.
[p2,s2] = polyfit(A2,B2,1);
[f2,delta] = polyval(p2,x,s2);
deltaf2=s2.normr/sqrt(s2.df);
C2=deltaf2^2*inv(s2.R)*inv(s2.R)';
deltap2=sqrt(diag(C2));
ok
3 Kommentare
Ganessen Moothooveeren
am 14 Mär. 2013
you used this to find error in slope but which variable is the error in slope??..is it deltaf2?? [p2,s2] = polyfit(A2,B2,1); [f2,delta] = polyval(p2,x,s2); deltaf2=s2.normr/sqrt(s2.df); C2=deltaf2^2*inv(s2.R)*inv(s2.R)'; deltap2=sqrt(diag(C2));
Akzeptierte Antwort
Adam Parry
am 4 Jul. 2012
1 Kommentar
Star Strider
am 4 Jul. 2012
I believe both 'nlinfit' and 'lsqcurvefit' can give you the information you need to give to 'nlparci' to calculate the parameter confidence intervals. The principal difference between 'nlinfit' and 'lsqcurvefit' is that 'lsqcurvefit' allows parameter constraints. Both will give you either the covariance matrix or the jacobian as well as the other results that 'nlparci' can use as arguments.
You don't have to alter 'nlparci' to get the standard errors, since 'nlinfit' gives you the ability to calculate those from the 'COVB' matrix it returns. You already calculated the standard errors as 'deltap2' from the covariance matrix you calculated as 'C2' in your original code. I used your results to calculate the 'CI95' matrix.
Weitere Antworten (1)
Star Strider
am 3 Jul. 2012
Not dumb at all. The problem is that if you want confidence limits on the estimated parameters, the 'polyfit' and 'polyval' functions won't get you there.
If you have the Statistics or Optimization Toolboxes, you can fit your model with 'lsqcurvefit' or 'nlinfit' respectively, then use 'nlparci' to get the confidence limits on the parameters. (Use 'nlpredci' to get confidence limits on the fitted data.)
If you don't have access the these, 'lscov' will likely give you what you need to calculate the confidence intervals yourself.
3 Kommentare
Star Strider
am 3 Jul. 2012
Bearbeitet: Star Strider
am 3 Jul. 2012
You didn't do anything wrong that I can see. When I ran 'lscov' on it (with simulated data), it produced the same covariance matrix you calculated. If anything, you didn't go far enough. The 95% confidence limits are ±1.96*SE, so with respect to your code they would be:
CI95 = [p2-1.96*deltap2 p2+1.96*deltap2];
and of course unless the 'CI95' interval for a parameter included zero, the parameter belongs in the model. Use 'norminv' to get critical values for other confidence intervals.
Other than that, using 'inv' is generally frowned upon because of condition concerns. The '\' operator avoids these because it does the division directly.
It took a bit of experimenting, but an alternate way of calculating C2 that uses '\' and avoids 'inv' is:
C2 = deltaf2^2 * (s2.R'*s2.R)\eye(2);
That's the only improvement I can think of.
Siehe auch
Kategorien
Mehr zu Matrix Indexing 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!