0001 function [ t, df, pval ] = SurfStatPlot( x, y, M, g, varargin );
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 y=double(y);
0027
0028 if nargin<3 | isempty(M)
0029 M=1;
0030 else
0031 if isnumeric(M)
0032 M=1+term(M);
0033 end
0034 end
0035 if nargin<4 | isempty(g)
0036 G=1;
0037 else
0038 G=term(g);
0039 end
0040
0041 X=term(x);
0042 XG=X+G+X*G;
0043 slm=SurfStatLinMod(y,M+XG);
0044 Yhat=slm.X*slm.coef;
0045 XGmat=double(XG);
0046 Yhatadj=XGmat*pinv(XGmat)*Yhat;
0047 c=mean(y)-mean(Yhatadj);
0048 Yhatadj=Yhatadj+c;
0049 Yadj=Yhatadj+y-Yhat;
0050
0051 nx=size(X,2);
0052 ng=size(G,2);
0053 x=double(X)*((1:nx)');
0054 g=double(G)*((1:ng)');
0055
0056 if nx==1
0057 if ng==1
0058 iu=[find(x==min(x)); find(x==max(x))];
0059 plot(x(iu),Yhatadj(iu),'-r',x,Yadj,'.b',varargin{:});
0060 slm=SurfStatT(slm,x);
0061 if isfield(slm,'dfs')
0062 slm.df=slm.dfs;
0063 end
0064 pval=stat_threshold(0,1,0,slm.df,[10 abs(slm.t)],[],[],[],[],[],[],0);
0065 pval=pval(2)*2;
0066 xlabel([inputname(1) ...
0067 ': T = ' num2str(round(slm.t*100)/100) ...
0068 ', df = ' num2str(round(slm.df*10)/10) ...
0069 ', P = ' num2str(round(pval*1000)/1000)]);
0070 else
0071 hs=zeros(1,ng);
0072 for j=1:ng
0073 i=(g==j);
0074 xi=x(i);
0075 Yhatadji=Yhatadj(i);
0076 iu=[find(xi==min(xi)); find(xi==max(xi))];
0077 h=plot(xi(iu),Yhatadji(iu),'-',xi,Yadj(i),'.',varargin{:});
0078 set(h(2),'Color',get(h(1),'Color'));
0079 hs(j)=h(1);
0080 if j==1
0081 hold all;
0082 end
0083 end
0084 hold off;
0085 legend(hs,char(G));
0086 slm0=SurfStatLinMod(y,M+X+G);
0087 slm=SurfStatF(slm,slm0);
0088 pval=stat_threshold(0,1,0,slm.df,[10 slm.t],[],[],[],[],[],[],0);
0089 pval=pval(2);
0090 xlabel([inputname(1) ' * ' inputname(4) ...
0091 ': F = ' num2str(round(slm.t*100)/100) ...
0092 ', df = ' num2str(slm.df(1)) ',' num2str(slm.df(2)) ...
0093 ', P = ' num2str(round(pval*1000)/1000)]);
0094 end
0095 else
0096 if ng==1
0097 [xu,iu]=unique(x);
0098 plot(xu,Yhatadj(iu),'-r',x,Yadj,'.b',varargin{:});
0099 slm0=SurfStatLinMod(y,M);
0100 str='';
0101 else
0102 hs=zeros(1,ng);
0103 for j=1:ng
0104 i=(g==j);
0105 xi=x(i);
0106 Yhatadji=Yhatadj(i);
0107 [xu,iu]=unique(xi);
0108 h=plot(xu,Yhatadji(iu),'-',xi,Yadj(i),'.',varargin{:});
0109 set(h(2),'Color',get(h(1),'Color'));
0110 hs(j)=h(1);
0111 if j==1
0112 hold all;
0113 end
0114 end
0115 hold off;
0116 legend(hs,char(G));
0117 slm0=SurfStatLinMod(y,M+X+G);
0118 str=[' * ' inputname(4)];
0119 end
0120 xlim([0.5 nx+0.5]);
0121 set(gca,'XTick',(1:nx)');
0122 set(gca,'XTickLabel',strvcat(char(X)));
0123 slm=SurfStatF(slm,slm0);
0124 pval=stat_threshold(0,1,0,slm.df,[10 slm.t],[],[],[],[],[],[],0);
0125 pval=pval(2);
0126 xlabel([inputname(1) str ...
0127 ': F = ' num2str(round(slm.t*100)/100) ...
0128 ', df = ' num2str(slm.df(1)) ',' num2str(slm.df(2)) ...
0129 ', P = ' num2str(round(pval*1000)/1000)]);
0130 end
0131 if nargin<3 | prod(size(M))==1
0132 ylabel(inputname(2));
0133 else
0134 ylabel([inputname(2) ' adjusted for ' inputname(3)]);
0135 end
0136 t=slm.t;
0137 df=slm.df;
0138 set(gcf,'PaperPosition',[0.25 2.5 6 4.5]);
0139
0140 return
0141 end