# sol_hw6 - CE 335 Solutions to Homework 6 5 x =[0 2 4 6 9 11...

This preview shows pages 1–3. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CE 335 Solutions to Homework 6 5) x = [0 2 4 6 9 11 12 15 17 19]'; y = [5 6 7 6 9 8 7 10 12 12]'; X = [ones(numel(x), 1) x]; b = X \ y; >> b = 4.85154 0.35247 %intercept and slope, respectively %standard error rss = sumsq(y - X*b); %residual sum of squares se = sqrt(rss / (numel(y) - 2)); >> 1.0650 %correlation coefficient r = corrcoef(x, y); >> 0.91477 %plot plot(x, y, 's', x, X*b); grid on xlabel('x'); ylabel('y'); legend('data', 'regression line') axis([min(x) - 1 max(x) + 1 min(y) - 1 max(y) + 1]) %repeat with regression of x on y X = [ones(numel(y), 1) y]; b = X \ x; >> -9.9676 2.3741 rss = sumsq(x - X*b); %residual sum of squares se = sqrt(rss / (numel(x) - 2)); >> 2.7640 %r stays the same if we switch x and y (cf. Eq. 13.21) plot(x, y, 's', X*b, y); grid on xlabel('x'); ylabel('y'); legend('data', 'regression line') axis([min(x) - 1 max(x) + 1 min(y) - 1 max(y) + 1]) Comparing the two plots, we see that the two regression lines are different! This is because the first line minimizes the sum of squares of errors in predicting the y values given the x values, whereas the...
View Full Document

{[ snackBarMessage ]}

### Page1 / 4

sol_hw6 - CE 335 Solutions to Homework 6 5 x =[0 2 4 6 9 11...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online