Regression error data
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Akzeptierte Antwort
Wayne King
am 3 Nov. 2011
Let
y = a(:,2);
x1 = a(:,1);
I'm assuming the 2nd column is the dependent variable and the first column is your predictor, independent variable.
Then,
X = [ones(size(x1)) x1];
[b,bint,r,rint,stats] = regress(y,X);
rsquared = stats(1) % this is the R-squared
% plot the data and the fit
yhat = b(1)+b(2)*x1;
plot(x1,y,'b*');
plot(x1,yhat,'r-.');
3 Kommentare
Wayne King
am 3 Nov. 2011
The errors are the residuals. But just so you understand, the errors here are y-yhat, the actual data values- fitted value.
Weitere Antworten (1)
Wayne King
am 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.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!