plotols.m (1150B)
1 function []=plotols(y,x,z,names); 2 % plotols.m 3 % 4 % Plots the partial correlation between y and x, controlling for z. 5 % 6 % Creates a plot using the names 'names' instead of plot symbols in the 7 % graph. Works best if names are only two or three characters long. 8 9 if z==[]; 10 plotname(x,y,names); 11 else; 12 13 N=length(y); 14 if z(:,1)~=ones(N,1); z=[ones(N,1) z]; end; 15 Mz=eye(N)-z*inv(z'*z)*z'; 16 uy=Mz*y; 17 ux=Mz*x; 18 19 xx=x; 20 yy=y; % Save originals 21 22 x=ux; 23 y=uy; 24 25 if length(names)==1; 26 plot(x,y,names); % e.g. names='o' 27 else; 28 29 scalef=.10; 30 minx=min(minnan(x)); 31 maxx=max(maxnan(x)); 32 miny=min(minnan(y)); 33 maxy=max(maxnan(y)); 34 distx=maxx-minx; 35 disty=maxy-miny; 36 minx=minx-scalef*distx; 37 maxx=maxx+scalef*distx; 38 miny=miny-scalef*disty; 39 maxy=maxy+scalef*disty; 40 axis([minx maxx miny maxy]); 41 for i=1:size(y,2); 42 text(x,y(:,i),names,'FontSize',8,'Color',[0 1 0]); 43 end; 44 h=gca; 45 set(h,'Box','on'); 46 end; 47 48 hold on; 49 50 [b tstat sigma2 vcv rsq]=lstiny(y,[ones(length(x),1) x]); 51 se = b(2)/tstat(2); 52 fprintf('Coeff = %7.3f\n',b(2)); 53 fprintf('StdErr= %7.3f\n',se); 54 fprintf(' R2 = %7.2f\n',rsq); 55 56 yfit=[ones(length(x),1) x]*b; 57 plot(x,yfit,'-'); 58 59 60 end;