reverse-shooting

Matlab scripts for reverse shooting
Log | Files | Refs | README

plotreg.m (996B)


      1 function []=plotreg(x,y,names,justprint,fsize,color);
      2 
      3 % plotreg.m
      4 %    
      5 %   Plots y vs x together with a regression line, and allows the user to
      6 %   place a box containing the coefficient, se, and r2.
      7 
      8 clf;
      9 if exist('fsize')~=1; fsize=8; end;
     10 if exist('color')~=1; color=[0 .4 0]; end;
     11 
     12 if exist('names')~=0;
     13   if size(names,1)==1;
     14     plot(x,y,names);
     15   else;
     16     plotname(x,y,names,fsize,color);
     17   end;
     18 else;
     19   plot(x,y);
     20 end;
     21 
     22 
     23 if exist('justprint')==0;
     24    justprint=0;
     25 end; 
     26 
     27 
     28 hold on;
     29 
     30 data=packr([y x]);
     31 y=data(:,1);
     32 x=data;
     33 x(:,1)=[];
     34 
     35 
     36 [b tstat sigma2 vcv rsq]=lstiny(y,[ones(length(x),1) x]);
     37 se = b(2)/tstat(2);
     38 bstr=sprintf('OLS Slope = %7.3f\n',b(2));
     39 sstr=sprintf(' Std. Err.    = %7.3f\n',se);
     40 rstr=sprintf('        R^2      = %7.2f\n',rsq);
     41 
     42 yfit=[ones(length(x),1) x]*b;
     43 [xmin,imin]=min(x);
     44 [xmax,imax]=max(x);
     45 plot([xmin xmax],yfit([imin imax]),'-');
     46 
     47 if justprint;
     48    disp(bstr); disp(sstr); disp(rstr);
     49 else;
     50    putstr(bstr);
     51    putstr(sstr);
     52    putstr(rstr);
     53 end;
     54 
     55 hold off;