%Lesson 3 - Math 151 %first read in data from a file % load b:fatdead.dat % which contains data on fat intake and % artherosclerosis death rate in Norway during % World War two (vectors are f, d and y for years) %then read in a command file that is %this file of commands for MATLAB %by first telling MATLAB to use the b: drive % !b: %then telling it to run lesson3 % lesson3 %where lesson3.m is a file on your %floppy in the b: drive who,pause !c: plot(y,f,'+w') title('fat intake versus year'),pause plot(y,d,'+w') title('death rate versus year'),pause plot(y,f,'+w', y,d,'og') title('both versus year'),pause plot(f,d,'+w') title('fat intake versus death rate'),pause %Now compute the regression line and plot it c=polyfit(f,d,1),pause m=[min(f) max(f)],pause x=polyval(c,m),pause plot(f,d,'+',m,x),pause % Now compute the Sum of the Square Errors for Regression SSR % and the Total Sum of Square Errors TSS % and from this compute RSquared as SSR/TSS %First compute the linear estimates for death rates % for the fat intakes in the vector f - call these dhat dmean=mean(d) dhat=polyval(c,f) SSR=sum((dhat-dmean).^2),pause TSS=sum((d-dmean).^2),pause RSquared=SSR/TSS,pause R=sqrt(RSquared),pause % Now compute the correlation coefficient and see that % it gives R corrcoef(f,d), pause