Regression error data
Afficher commentaires plus anciens
Hi after plotting the regression line and inserting the error I have noticed that it doesn't seem to have an error on it i.e. I want the equation to be in:
y = ax±b + c±d
format rather than
y = ax±c
I would also like to display the rsquare value of the fit. How would I be able to do this?
Thank you in advance
Réponse acceptée
Plus de réponses (1)
Wayne King
le 3 Nov 2011
Hi, the simple linear regression model is
y = beta0 + beta1*x+epsilon
where epsilon is the error.
But when you fit the model, you only fit the beta0 (intercept) and beta1 (slope) terms, so you fit a model of the form
yhat = \hat{beta0}+\hat{beta1}*x
I've used \hat{} to designate estimates.
You can output the rsquared value as below.
load carsmall
x1 = Weight;
y = MPG;
X = [ones(size(x1)) x1];
[b,bint,r,rint,stats] = regress(y,X);
rsquared = stats(1)
The fitted model is:
yhat = b(1)+b(2)*x1;
plot(x1,y,'b*');
plot(x1,yhat,'r-.');
The errors, residuals, are in the r variable.
1 commentaire
Suguru
le 3 Nov 2011
Catégories
En savoir plus sur Linear Predictive Coding dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!