% Testxyplot.m   Feb. 2005, revised Feb. 2006 L Braile
% Test and plot the xyplot least squares straight
% line function with sample data, use Middleton's xyplot function
% to perform an analysis of variance on the x-y data.
x = [1 2 3 4 5 6 7 8 9]'; % ' makes x a column vector
y = [1.5 1.8 2.0 3.6 4.1 6.8 6.4 4.0 9.4]'; % ' makes y a column vector
[a,yest,sst,rr,F] = xyplot(x,y);
fstat1 = finv(0.95,1,length(x)-2); % Calculate and print F statistic
% from tables to compare with F value from the lsq fit, 0.95 prob.
% If f value > fstat1 (from tables), the fit is significant at 95% level
% (You would observe values greater than fstat only 5% 
% of the time by chance.)
% plot the data and least squares line
fprintf('fstat1 = %g\n', fstat1	);
fprintf('If F value > fstat1, fit is significant at 95 percent level \n\n')
P1 = fcdf(F,1,length(x)-2);
P = 1.0 - P1;
fprintf('P = %g\n', P);
fprintf('Probability that a set of random numbers would have\n')
fprintf('an F value as large as the calculated F value\n')
figure
plot(x,y,'ro','markersize',12,'linewidth',3) % Plot the data
set(gca,'fontsize',16,'linewidth',2)
hold on
xlabel('x-values','fontsize',16)
ylabel('y-values','fontsize',16)
title('Plot of sample data and least squares straight line fit','fontsize',16)
yt = feval('sline',x,a(2),a(1)); % Calculate the fitted line
plot(x,yt,'k-','linewidth',3) % Plot the fitted line
axis([0 10 0 10]); % Set axis limits for plot
hold off