Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


ContrVec.m

Go to the documentation of this file.
00001 function [err, Contr] = ContrVec(order, n, NF, group, dmat, Contr, FL, num_col)
00002 %
00003 %   [err,] = ContrVec.m ()
00004 %
00005 %Purpose:
00006 %   
00007 %   Obtain a vector for each contrast so that effect size is calculated in SumsOfSquares.m
00008 %   
00009 %Input Parameters:
00010 %   
00011 %   
00012 %   
00013 %Output Parameters:
00014 %   err : 0 No Problem
00015 %       : 1  Problems
00016 %   
00017 %   
00018 %      
00019 %Key Terms:
00020 %   
00021 %More Info :
00022 %   
00023 %   
00024 %   
00025 %
00026 %     Author : Gang Chen
00027 %     Date : Wed Dec 1 10:15:29 EST 2004
00028 %     SSCC/NIMH/ National Institutes of Health, Bethesda MD 20892
00029 
00030 
00031 %Define the function name for easy referencing
00032 FuncName = 'ContrVec.m';
00033 
00034 %Debug Flag
00035 DBG = 1;
00036 
00037 %initialize return variables
00038 err = 1;
00039 
00040 switch order
00041 
00042 case 1,   % dmat(:, num_col0+1:num_col0+num_col(1)) is the matrix for 1st order contrasts
00043 
00044    for (i = 1:1:Contr.ord1.tot),
00045       Contr.ord1.cnt(i).vec = zeros(1, n);  % n = ntot in anovan.m: total number of files, and no. of arrows in dmat
00046                 Contr.ord1.cnt(i).scalar = 0;
00047       for (j = 1:1:Contr.ord1.cnt(i).NT),   % for each term in a contrast
00048          first = 0;
00049          Contr.ord1.cnt(i).code(j).pos = 0;                     
00050                         shift = 1;   % Grand mean 
00051               for (k = 1:1:NF),
00052             if (Contr.ord1.cnt(i).code(j).str(k) >= 'a' & Contr.ord1.cnt(i).code(j).str(k) <= 'z'), 
00053                                    tmpv = 10 + Contr.ord1.cnt(i).code(j).str(k) - 'a';
00054                                 else tmpv = Contr.ord1.cnt(i).code(j).str(k) - '0'; end  % tmpv = level #
00055                                                 
00056                                 if (tmpv ~= 0), 
00057                     first = first + 1;  % the first non-zero index backward! For 1st-roder, it is the only nonzero index.
00058                               if (first == 1),
00059                                  Contr.ord1.cnt(i).idx1 = k;
00060 %                                     tmp = FL(k).N_level;
00061                     elseif (first > 1), 
00062                        fprintf('\nError in contrast coding: more than one non-zero index in 1st order constrasts!\n');
00063                        fprintf(2,'Halted: Ctrl+c to exit'); pause;
00064                               end  % if (first == 1)
00065                  end   % if (tmpv ~= 0)
00066          end   % for (k = 1:1:NF)
00067                         if (Contr.ord1.cnt(i).idx1 > 1),
00068                            for (k = 1:1:Contr.ord1.cnt(i).idx1-1),
00069                               shift = shift + FL(k).N_level;
00070                                 end                                     
00071                         end
00072                         if (Contr.ord1.cnt(i).code(j).str(Contr.ord1.cnt(i).idx1) >= 'a' & Contr.ord1.cnt(i).code(j).str(Contr.ord1.cnt(i).idx1) <= 'z'),
00073                            tmpv = 10 + Contr.ord1.cnt(i).code(j).str(Contr.ord1.cnt(i).idx1) - 'a';
00074                         else tmpv = Contr.ord1.cnt(i).code(j).str(Contr.ord1.cnt(i).idx1) - '0'; end
00075                                         
00076          Contr.ord1.cnt(i).code(j).pos = shift + tmpv; 
00077                         
00078 %        tmp = FL(Contr.ord1.cnt(i).idx1).N_level/n;
00079 %         Contr.ord1.cnt(i).scalar = tmp * Contr.ord1.cnt(i).coef*Contr.ord1.cnt(i).coef';              
00080 %         Contr.ord1.cnt(i).vec = Contr.ord1.cnt(i).vec + Contr.ord1.cnt(i).coef(j) * dmat(:, Contr.ord1.cnt(i).code(j).pos)';
00081                         
00082                         count=0;   % The part should be valid for both balanced and unbalanced designs
00083 %                       tmpstr = char (group{Contr.ord1.cnt(i).idx1});
00084          for (ll = 1:1:n) % Should have a more decent way to do this in a matrix fashion instead of a lenthy loop?
00085             tmpstr = char (group{Contr.ord1.cnt(i).idx1}(ll));
00086                                 if strcmp(tmpstr, FL(Contr.ord1.cnt(i).idx1).level(tmpv).expr)
00087                     count = count + 1;   % total number of occurences at tmpv-th level
00088                  end
00089          end
00090                         Contr.ord1.cnt(i).vec = Contr.ord1.cnt(i).vec + Contr.ord1.cnt(i).coef(j) * dmat(:, Contr.ord1.cnt(i).code(j).pos)'/count;                      
00091                         Contr.ord1.cnt(i).scalar = Contr.ord1.cnt(i).scalar + Contr.ord1.cnt(i).coef(j)*Contr.ord1.cnt(i).coef(j)/count;    % For variance coef: j-th term in i-th 1st-order contrast.                          
00092                                         
00093       end       % for (j = 1:1:Contr.ord1.cnt(i).NT)
00094 %      Contr.ord1.cnt(i).vec = Contr.ord1.cnt(i).vec*tmp;   % assuming balanced design!!!
00095    end   %for (i = 1:1:Contr1.tot)
00096 
00097 case 2,  % dmat(:, num_col0+num_col(1)+1:num_col0+num_col(1)+num_col(2)) is the matrix for 2nd order contrasts
00098 
00099    % when the 1st factor is collapsed 
00100    %   shift1 = (FL(1).N_level*(FL(2).N_level + FL(3).N_level + FL(4).N_level))*(str2num(Contr2.cnt(i).code(1).str(1)) == 0);
00101    % when the 2nd factor is collapsed 
00102    %   shift2 = (FL(2).N_level*(FL(3).N_level + FL(4).N_level))*(str2num(Contr2.cnt(i).code(1).str(2)) == 0);
00103    % when the 3rd factor is collapsed 
00104    %   shift3 = (FL(3).N_level*FL(4).N_level)*(str2num(Contr2.cnt(i).code(1).str(3)) == 0);
00105    %
00106    % when the 4th factor is collapsed 
00107    %   shift4 = FL(4).N_level*(str2num(Contr2.cnt(i).code(1).str(4)) == 0);
00108    %
00109    %   Contr2.cnt(i).shift = num_col0 + num_col(1) + 1 + shift1 + shift2 + shift3 + shift4;  % position shifting for the two collapsed indices
00110 
00111    shift = 1 + num_col(1);   % Grand mean plus factor means
00112    for (i = 1:1:Contr.ord2.tot),   
00113                  
00114    % for the two non-zero indices
00115         Contr.ord2.cnt(i).vec = zeros(1, n);  % n = ntot in anovan.m: total number of files, and no. of arrows in dmat
00116         Contr.ord2.cnt(i).scalar = 0;
00117         for (j = 1:1:Contr.ord2.cnt(i).NT),   % For each term in this 2nd-order contrast
00118       first = 0;
00119            Contr.ord2.cnt(i).code(j).pos = 0;
00120                 for (k = 1:1:NF),
00121          if (Contr.ord2.cnt(i).code(j).str(k) >= 'a' & Contr.ord2.cnt(i).code(j).str(k) <= 'z'), 
00122                            tmpv = 10 + Contr.ord2.cnt(i).code(j).str(k) - 'a';
00123                         else tmpv = Contr.ord2.cnt(i).code(j).str(k) - '0'; end
00124                                                 
00125                         if (tmpv ~= 0), 
00126             first = first + 1;  % the first non-zero index backward!
00127                         if (first == 1),
00128                          Contr.ord2.cnt(i).idx1 = k;
00129 %                               tmp = FL(k).N_level;
00130                       elseif (first == 2), Contr.ord2.cnt(i).idx2 = k; end
00131                    end
00132       end  %for (k = 1:1:NF)
00133                 sec_fctr = Contr.ord2.cnt(i).idx2;
00134       switch Contr.ord2.cnt(i).idx1
00135       case 1,   % 2nd-order contrasts: Ax
00136 %         sec_fctr = Contr.ord2.cnt(i).idx2;
00137                         if (Contr.ord2.cnt(i).code(j).str(1) >= 'a' & Contr.ord2.cnt(i).code(j).str(1) <= 'z'),
00138                            tmpv1 = 10 + Contr.ord2.cnt(i).code(j).str(1) - 'a';
00139                         else tmpv1 = Contr.ord2.cnt(i).code(j).str(1) - '0'; end
00140                         if (Contr.ord2.cnt(i).code(j).str(sec_fctr) >= 'a' & Contr.ord2.cnt(i).code(j).str(sec_fctr) <= 'z'),
00141                            tmpv2 = 10 + Contr.ord2.cnt(i).code(j).str(sec_fctr) - 'a';
00142          else tmpv2 = Contr.ord2.cnt(i).code(j).str(sec_fctr) - '0'; end % tmpv = level #       
00143                         
00144                         Contr.ord2.cnt(i).code(j).pos = shift + (tmpv1 - 1) * FL(sec_fctr).N_level + tmpv2;                     
00145                         if (sec_fctr > 2),
00146                         for (ll = 2:1:(sec_fctr-1)),  % shift over AB, AC, ...
00147                            Contr.ord2.cnt(i).code(j).pos = Contr.ord2.cnt(i).code(j).pos + FL(1).N_level*FL(ll).N_level;
00148                         end % for (ll = 2:1:(sec_fctr-1))
00149                         end % if (sec_fctr > 2)
00150                                                 
00151 %                       switch Contr.ord2.cnt(i).idx2
00152 %         case 2, 
00153 %            if (Contr.ord2.cnt(i).code(j).str(1) >= 'a' & Contr.ord2.cnt(i).code(j).str(1) <= 'z'),
00154 %                                  tmpv1 = 10 + Contr.ord2.cnt(i).code(j).str(1) - 'a';
00155 %            else tmpv1 = Contr.ord2.cnt(i).code(j).str(1) - '0'; end
00156 %                               if (Contr.ord2.cnt(i).code(j).str(2) >= 'a' & Contr.ord2.cnt(i).code(j).str(2) <= 'z'),
00157 %                                  tmpv2 = 10 + Contr.ord2.cnt(i).code(j).str(2) - 'a';
00158 %            else tmpv2 = Contr.ord2.cnt(i).code(j).str(2) - '0'; end % tmpv = level #
00159                                                                         
00160 %                               Contr.ord2.cnt(i).code(j).pos = shift + (tmpv1 - 1) * FL(2).N_level + tmpv2; % AB
00161 %         case 3, 
00162 %            if (Contr.ord2.cnt(i).code(j).str(1) >= 'a' & Contr.ord2.cnt(i).code(j).str(1) <= 'z'),
00163 %                                  tmpv1 = 10 + Contr.ord2.cnt(i).code(j).str(1) - 'a';
00164 %            else tmpv1 = Contr.ord2.cnt(i).code(j).str(1) - '0'; end
00165 %                               if (Contr.ord2.cnt(i).code(j).str(3) >= 'a' & Contr.ord2.cnt(i).code(j).str(3) <= 'z'),
00166 %                                  tmpv2 = 10 + Contr.ord2.cnt(i).code(j).str(3) - 'a';
00167 %            else tmpv2 = Contr.ord2.cnt(i).code(j).str(3) - '0'; end                                                                   
00168                                                                         
00169 %                               Contr.ord2.cnt(i).code(j).pos = shift + FL(1).N_level*FL(2).N_level+ ... 
00170 %               (tmpv1 - 1) * FL(3).N_level + tmpv2; % AC       
00171          
00172 %                       case 4,   % AD
00173 %                          if (Contr.ord2.cnt(i).code(j).str(1) >= 'a' & Contr.ord2.cnt(i).code(j).str(1) <= 'z'),
00174 %                                  tmpv1 = 10 + Contr.ord2.cnt(i).code(j).str(1) - 'a';
00175 %            else tmpv1 = Contr.ord2.cnt(i).code(j).str(1) - '0'; end
00176 %                               if (Contr.ord2.cnt(i).code(j).str(4) >= 'a' & Contr.ord2.cnt(i).code(j).str(4) <= 'z'),
00177 %                                  tmpv2 = 10 + Contr.ord2.cnt(i).code(j).str(4) - 'a';
00178 %            else tmpv2 = Contr.ord2.cnt(i).code(j).str(4) - '0'; end
00179                                 
00180 %                               Contr.ord2.cnt(i).code(j).pos = shift + FL(1).N_level*FL(2).N_level+ FL(1).N_level*FL(3).N_level+... 
00181 %               (tmpv1 - 1) * FL(4).N_level + tmpv2; % AD
00182 %             end                               
00183       case 2,  % 2nd-order contrasts Bx
00184 %         sec_fctr = Contr.ord2.cnt(i).idx2;
00185                         if (Contr.ord2.cnt(i).code(j).str(2) >= 'a' & Contr.ord2.cnt(i).code(j).str(2) <= 'z')
00186                            tmpv1 = 10 + Contr.ord2.cnt(i).code(j).str(2) - 'a';
00187                    else tmpv1 = Contr.ord2.cnt(i).code(j).str(2) - '0'; end
00188                         if (Contr.ord2.cnt(i).code(j).str(sec_fctr) >= 'a' & Contr.ord2.cnt(i).code(j).str(sec_fctr) <= 'z'),
00189                            tmpv2 = 10 + Contr.ord2.cnt(i).code(j).str(sec_fctr) - 'a';
00190                    else tmpv2 = Contr.ord2.cnt(i).code(j).str(sec_fctr) - '0'; end      
00191                         
00192                         Contr.ord2.cnt(i).code(j).pos = shift + (tmpv1 - 1) * FL(sec_fctr).N_level + tmpv2; 
00193                         for (ll = 2:1:NF), % shift over all those Ax's
00194                            Contr.ord2.cnt(i).code(j).pos = Contr.ord2.cnt(i).code(j).pos + FL(1).N_level*FL(ll).N_level;
00195                         end
00196                                                 
00197                         if (sec_fctr > 3),
00198                         for (ll = 3:1:(sec_fctr-1)),  % shift over Bx's
00199                            Contr.ord2.cnt(i).code(j).pos = Contr.ord2.cnt(i).code(j).pos + FL(2).N_level*FL(ll).N_level;
00200                         end % for (ll = 3:1:(sec_fctr-1))
00201                         end % if (sec_fctr > 3)                         
00202                         
00203 %                       if (Contr.ord2.cnt(i).idx2 == 3),
00204 %            if (Contr.ord2.cnt(i).code(j).str(2) >= 'a' & Contr.ord2.cnt(i).code(j).str(2) <= 'z'),
00205 %                          tmpv1 = 10 + Contr.ord2.cnt(i).code(j).str(2) - 'a';
00206 %                     else tmpv1 = Contr.ord2.cnt(i).code(j).str(2) - '0'; end
00207 %                               if (Contr.ord2.cnt(i).code(j).str(3) >= 'a' & Contr.ord2.cnt(i).code(j).str(3) <= 'z'),
00208 %                                  tmpv2 = 10 + Contr.ord2.cnt(i).code(j).str(3) - 'a';
00209 %                     else tmpv2 = Contr.ord2.cnt(i).code(j).str(3) - '0'; end  
00210                                                                         
00211 %                               if (NF == 3), Contr.ord2.cnt(i).code(j).pos = shift + FL(1).N_level*(FL(2).N_level + FL(3).N_level) + ...
00212 %                         (tmpv1 - 1) * FL(3).N_level + tmpv2; % BC
00213 %                               else Contr.ord2.cnt(i).code(j).pos = shift + FL(1).N_level*(FL(2).N_level + FL(3).N_level + FL(4).N_level) + ...
00214 %                         (tmpv1 - 1) * FL(3).N_level + tmpv2; % BC
00215 %                               end              
00216 %                     tmp = FL(2).N_level*FL(3).N_level/n; 
00217 %                       else fprintf('\nSomething is wrong in the contrast coding!\n'); fprintf(2,'Halted: Ctrl+c to exit'); pause; end
00218 
00219                 case 3,  % 2nd-order contrasts Cx
00220                    if (Contr.ord2.cnt(i).code(j).str(3) >= 'a' & Contr.ord2.cnt(i).code(j).str(3) <= 'z')
00221                            tmpv1 = 10 + Contr.ord2.cnt(i).code(j).str(3) - 'a';
00222                    else tmpv1 = Contr.ord2.cnt(i).code(j).str(3) - '0'; end
00223                         if (Contr.ord2.cnt(i).code(j).str(sec_fctr) >= 'a' & Contr.ord2.cnt(i).code(j).str(sec_fctr) <= 'z'),
00224                            tmpv2 = 10 + Contr.ord2.cnt(i).code(j).str(sec_fctr) - 'a';
00225                    else tmpv2 = Contr.ord2.cnt(i).code(j).str(sec_fctr) - '0'; end      
00226                         
00227                         Contr.ord2.cnt(i).code(j).pos = shift + (tmpv1 - 1) * FL(sec_fctr).N_level + tmpv2; 
00228                         for (ll = 2:1:NF), % shift over all those Ax's
00229                            Contr.ord2.cnt(i).code(j).pos = Contr.ord2.cnt(i).code(j).pos + FL(1).N_level*FL(ll).N_level;
00230                         end
00231                         
00232                         for (ll = 3:1:NF), % shift over all those Bx's
00233                            Contr.ord2.cnt(i).code(j).pos = Contr.ord2.cnt(i).code(j).pos + FL(2).N_level*FL(ll).N_level;
00234                         end
00235                                                 
00236                         if (sec_fctr > 4),
00237                         for (ll = 4:1:(sec_fctr-1)),  % shift over Bx's
00238                            Contr.ord2.cnt(i).code(j).pos = Contr.ord2.cnt(i).code(j).pos + FL(3).N_level*FL(ll).N_level;
00239                         end % for (ll = 4:1:(sec_fctr-1))
00240                         end % if (sec_fctr > 4)
00241                         
00242                 case 4,  % 2nd-order contrasts Dx
00243                    if (Contr.ord2.cnt(i).code(j).str(4) >= 'a' & Contr.ord2.cnt(i).code(j).str(4) <= 'z')
00244                            tmpv1 = 10 + Contr.ord2.cnt(i).code(j).str(4) - 'a';
00245                    else tmpv1 = Contr.ord2.cnt(i).code(j).str(4) - '0'; end
00246                         if (Contr.ord2.cnt(i).code(j).str(sec_fctr) >= 'a' & Contr.ord2.cnt(i).code(j).str(sec_fctr) <= 'z'),
00247                            tmpv2 = 10 + Contr.ord2.cnt(i).code(j).str(sec_fctr) - 'a';
00248                    else tmpv2 = Contr.ord2.cnt(i).code(j).str(sec_fctr) - '0'; end      
00249                         
00250                         Contr.ord2.cnt(i).code(j).pos = shift + (tmpv1 - 1) * FL(sec_fctr).N_level + tmpv2; 
00251                         for (ll = 2:1:NF), % shift over all those Ax's
00252                            Contr.ord2.cnt(i).code(j).pos = Contr.ord2.cnt(i).code(j).pos + FL(1).N_level*FL(ll).N_level;
00253                         end
00254                         
00255                         for (ll = 3:1:NF), % shift over all those Bx's
00256                            Contr.ord2.cnt(i).code(j).pos = Contr.ord2.cnt(i).code(j).pos + FL(2).N_level*FL(ll).N_level;
00257                         end
00258                         
00259                         for (ll = 4:1:NF), % shift over all those Cx's
00260                            Contr.ord2.cnt(i).code(j).pos = Contr.ord2.cnt(i).code(j).pos + FL(3).N_level*FL(ll).N_level;
00261                         end
00262                                                 
00263                         if (sec_fctr > 5),
00264                         for (ll = 5:1:(sec_fctr-1)),  % shift over Bx's
00265                            Contr.ord2.cnt(i).code(j).pos = Contr.ord2.cnt(i).code(j).pos + FL(4).N_level*FL(ll).N_level;
00266                         end % for (ll = 5:1:(sec_fctr-1))
00267                         end % if (sec_fctr > 5)
00268                                 
00269                         
00270 %                       fprintf('\nSomething is wrong in the contrast coding!\n');
00271 %                  fprintf(2,'Halted: Ctrl+c to exit'); pause;                  
00272                 end  %switch Contr.ord2.cnt(i).idx1
00273                 
00274                 count = 0;
00275                 for (ll = 1:1:n)
00276                         tmpstr1 = char (group{Contr.ord2.cnt(i).idx1}(ll));
00277                         tmpstr2 = char (group{Contr.ord2.cnt(i).idx2}(ll));                     
00278                         if strcmp(tmpstr1, FL(Contr.ord2.cnt(i).idx1).level(tmpv1).expr) & strcmp(tmpstr2, FL(Contr.ord2.cnt(i).idx2).level(tmpv2).expr)
00279                            count = count + 1;   % total number of occurences at tmpv-th level
00280                         end     
00281                 end
00282                 Contr.ord2.cnt(i).vec = Contr.ord2.cnt(i).vec + Contr.ord2.cnt(i).coef(j) * dmat(:, Contr.ord2.cnt(i).code(j).pos)'/count;                      
00283                 Contr.ord2.cnt(i).scalar = Contr.ord2.cnt(i).scalar + Contr.ord2.cnt(i).coef(j)*Contr.ord2.cnt(i).coef(j)/count;    % For variance coef: j-th term in i-th 1st-order contrast.          
00284 
00285 %               Contr.ord2.cnt(i).scalar = tmp * Contr.ord2.cnt(i).coef*Contr.ord2.cnt(i).coef';                
00286 %               Contr.ord2.cnt(i).vec = Contr.ord2.cnt(i).vec + Contr.ord2.cnt(i).coef(j) * dmat(:, Contr.ord2.cnt(i).code(j).pos)';                    
00287    end   %for (j = 1:1:Contr.ord2.cnt(i).NT),
00288 %       Contr.ord2.cnt(i).vec = Contr.ord2.cnt(i).vec*tmp;   % assuming balanced design!!!
00289    end   %for (i = 1:1:Contr2.tot)
00290                         
00291 case 3,
00292 
00293    shift = 1 + num_col(1) + num_col(2);   % skip grand mean, factor means and 2nd-roder terms
00294    for (i = 1:1:Contr.ord3.tot),   
00295    % for the  non-zero indices
00296            Contr.ord3.cnt(i).vec = zeros(1, n);  % n = ntot in anovan.m: total number of files, and no. of arrows in dmat
00297            Contr.ord3.cnt(i).scalar = 0;
00298                 for (j = 1:1:Contr.ord3.cnt(i).NT),   % for each term in a contrast
00299          first = 0;
00300                    Contr.ord3.cnt(i).code(j).pos = 0;
00301                         
00302                    for (k = 1:1:NF),
00303             if (Contr.ord3.cnt(i).code(j).str(k) >= 'a' & Contr.ord3.cnt(i).code(j).str(k) <= 'z'), 
00304                                    tmpv = 10 + Contr.ord3.cnt(i).code(j).str(k) - 'a';
00305                            else tmpv = Contr.ord3.cnt(i).code(j).str(k) - '0'; end
00306                         
00307                            if (tmpv ~= 0),  
00308                     first = first + 1;  % the first non-zero index backward!
00309                          % if (first == 1), tmp = str2num(Contr3.cnt(i).code(j).str(k)) - 1;      % (level# - 1) for the first collapsed index                  
00310                                    % elseif (first == 2), Contr3.cnt(i).code(j).shift = Contr3.cnt(i).code(j).shift + tmp * FL(k).N_level str2num(Contr3.cnt(i).code(j).str(k);
00311                                    if (first == 1),
00312                                       Contr.ord3.cnt(i).idx1 = k;
00313                                            %Contr3.cnt(i).code(j).pos = Contr3.cnt(i).shift + str2num(Contr3.cnt(i).code(j).str(k)) - 1; 
00314 %                                          tmp = FL(k).N_level;
00315                          elseif (first == 2), 
00316                                       Contr.ord3.cnt(i).idx2 = k;
00317                                            %Contr3.cnt(i).code(j).pos = Contr3.cnt(i).code(j).pos + (str2num(Contr3.cnt(i).code(j).str(k)) - 1) * tmp;
00318                             %else fprintf('\nError in contrast coding: more than two non-zero indices!\n');
00319                             %   fprintf(2,'Halted: Ctrl+c to exit'); pause;
00320                                    end
00321                                    if (first == 3), Contr.ord3.cnt(i).idx3 = k; end
00322                       end
00323               end  % for (k = 1:1:NF)
00324                    switch Contr.ord3.cnt(i).idx1
00325                    case 1,
00326                            switch Contr.ord3.cnt(i).idx2
00327                                    case 2,
00328                                            switch Contr.ord3.cnt(i).idx3
00329                                                    case 3, % ABC
00330                                                         
00331                                                         if (Contr.ord3.cnt(i).code(j).str(1) >= 'a' & Contr.ord3.cnt(i).code(j).str(1) <= 'z'),
00332                                                                 tmpv1 = 10 + Contr.ord3.cnt(i).code(j).str(1) - 'a';
00333                                               else tmpv1 = Contr.ord3.cnt(i).code(j).str(1) - '0'; end
00334                                                         if (Contr.ord3.cnt(i).code(j).str(2) >= 'a' & Contr.ord3.cnt(i).code(j).str(2) <= 'z'),
00335                                                            tmpv2 = 10 + Contr.ord3.cnt(i).code(j).str(2) - 'a';
00336                                               else tmpv2 = Contr.ord3.cnt(i).code(j).str(2) - '0'; end
00337                                                         if (Contr.ord3.cnt(i).code(j).str(3) >= 'a' & Contr.ord3.cnt(i).code(j).str(3) <= 'z'),
00338                                                            tmpv3 = 10 + Contr.ord3.cnt(i).code(j).str(3) - 'a';
00339                                               else tmpv3 = Contr.ord3.cnt(i).code(j).str(3) - '0'; end
00340                                                         
00341                                                         Contr.ord3.cnt(i).code(j).pos = shift + (tmpv1 - 1) * FL(2).N_level * FL(3).N_level + ...
00342                                                  (tmpv2 - 1) * FL(3).N_level + tmpv3; % ABC
00343 %                                                       tmp = FL(1).N_level*FL(2).N_level*FL(3).N_level/n;
00344                                                         
00345                                                         case 4, % ABD
00346                                                         
00347                                                         if (Contr.ord3.cnt(i).code(j).str(1) >= 'a' & Contr.ord3.cnt(i).code(j).str(1) <= 'z'),
00348                                                                 tmpv1 = 10 + Contr.ord3.cnt(i).code(j).str(1) - 'a';
00349                                               else tmpv1 = Contr.ord3.cnt(i).code(j).str(1) - '0'; end
00350                                                         if (Contr.ord3.cnt(i).code(j).str(2) >= 'a' & Contr.ord3.cnt(i).code(j).str(2) <= 'z'),
00351                                                            tmpv2 = 10 + Contr.ord3.cnt(i).code(j).str(2) - 'a';
00352                                               else tmpv2 = Contr.ord3.cnt(i).code(j).str(2) - '0'; end
00353                                                         if (Contr.ord3.cnt(i).code(j).str(4) >= 'a' & Contr.ord3.cnt(i).code(j).str(4) <= 'z'),
00354                                                            tmpv3 = 10 + Contr.ord3.cnt(i).code(j).str(4) - 'a';
00355                                               else tmpv3 = Contr.ord3.cnt(i).code(j).str(4) - '0'; end
00356                                                         
00357                                                         % shift the columns for ABC and part of ABD
00358                                                         Contr.ord3.cnt(i).code(j).pos = shift + FL(1).N_level * FL(2).N_level * FL(3).N_level + ...
00359                                                            (tmpv1 - 1) * FL(2).N_level * FL(4).N_level + (tmpv2 - 1) * FL(4).N_level + tmpv3; % ABD
00360 %                                                          tmp = FL(1).N_level*FL(2).N_level*FL(4).N_level/n;
00361                      
00362                                                         case 5, % ABE
00363                                                         
00364                                                         if (Contr.ord3.cnt(i).code(j).str(1) >= 'a' & Contr.ord3.cnt(i).code(j).str(1) <= 'z'),
00365                                                                 tmpv1 = 10 + Contr.ord3.cnt(i).code(j).str(1) - 'a';
00366                                               else tmpv1 = Contr.ord3.cnt(i).code(j).str(1) - '0'; end
00367                                                         if (Contr.ord3.cnt(i).code(j).str(2) >= 'a' & Contr.ord3.cnt(i).code(j).str(2) <= 'z'),
00368                                                            tmpv2 = 10 + Contr.ord3.cnt(i).code(j).str(2) - 'a';
00369                                               else tmpv2 = Contr.ord3.cnt(i).code(j).str(2) - '0'; end
00370                                                         if (Contr.ord3.cnt(i).code(j).str(5) >= 'a' & Contr.ord3.cnt(i).code(j).str(5) <= 'z'),
00371                                                            tmpv3 = 10 + Contr.ord3.cnt(i).code(j).str(5) - 'a';
00372                                               else tmpv3 = Contr.ord3.cnt(i).code(j).str(5) - '0'; end
00373                                                         
00374                                                         % shift the columns for ABC, ABD and part of ABE
00375                                                         Contr.ord3.cnt(i).code(j).pos = shift + FL(1).N_level * FL(2).N_level * FL(3).N_level + ...
00376                                                            + FL(1).N_level * FL(2).N_level * FL(4).N_level + ...
00377                                                                 (tmpv1 - 1) * FL(2).N_level * FL(5).N_level + (tmpv2 - 1) * FL(5).N_level + tmpv3; % ABE
00378 
00379                                                 end   % switch Contr.ord3.cnt(i).idx3
00380                                         case 3, 
00381                                            if (Contr.ord3.cnt(i).idx3 == 4),  % ACD
00382                                                    if (Contr.ord3.cnt(i).code(j).str(1) >= 'a' & Contr.ord3.cnt(i).code(j).str(1) <= 'z'),
00383                                                                 tmpv1 = 10 + Contr.ord3.cnt(i).code(j).str(1) - 'a';
00384                                               else tmpv1 = Contr.ord3.cnt(i).code(j).str(1) - '0'; end
00385                                                         if (Contr.ord3.cnt(i).code(j).str(3) >= 'a' & Contr.ord3.cnt(i).code(j).str(3) <= 'z'),
00386                                                            tmpv2 = 10 + Contr.ord3.cnt(i).code(j).str(3) - 'a';
00387                                               else tmpv2 = Contr.ord3.cnt(i).code(j).str(3) - '0'; end
00388                                                         if (Contr.ord3.cnt(i).code(j).str(4) >= 'a' & Contr.ord3.cnt(i).code(j).str(4) <= 'z'),
00389                                                            tmpv3 = 10 + Contr.ord3.cnt(i).code(j).str(4) - 'a';
00390                                               else tmpv3 = Contr.ord3.cnt(i).code(j).str(4) - '0'; end
00391                                                         
00392                                                         Contr.ord3.cnt(i).code(j).pos = shift + FL(1).N_level * FL(2).N_level * FL(3).N_level + FL(1).N_level * FL(2).N_level * FL(4).N_level + ...
00393                                                            FL(1).N_level * FL(2).N_level * FL(5).N_level + (tmpv1 - 1) * FL(3).N_level * FL(4).N_level + (tmpv2 - 1) * FL(4).N_level + tmpv3; % ACD
00394 %                                                       tmp = FL(1).N_level*FL(3).N_level*FL(4).N_level/n;
00395                                                 else fprintf('\nSomething is wrong in the contrast coding!\n'); fprintf(2,'Halted: Ctrl+c to exit'); pause;             
00396                                                 end
00397                                         case 4, fprintf('\nSomething is wrong in the contrast coding!\n'); fprintf(2,'Halted: Ctrl+c to exit'); pause;                                  
00398                                 end                             
00399                         case 2,
00400                            switch Contr.ord3.cnt(i).idx2
00401                                    case 3, 
00402                                            switch Contr.ord3.cnt(i).idx3 
00403                                                    
00404                                                         case 4,  % BCD
00405                                                         if (Contr.ord3.cnt(i).code(j).str(2) >= 'a' & Contr.ord3.cnt(i).code(j).str(2) <= 'z'),
00406                                                                 tmpv1 = 10 + Contr.ord3.cnt(i).code(j).str(2) - 'a';
00407                                               else tmpv1 = Contr.ord3.cnt(i).code(j).str(2) - '0'; end
00408                                                         if (Contr.ord3.cnt(i).code(j).str(3) >= 'a' & Contr.ord3.cnt(i).code(j).str(3) <= 'z'),
00409                                                            tmpv2 = 10 + Contr.ord3.cnt(i).code(j).str(3) - 'a';
00410                                               else tmpv2 = Contr.ord3.cnt(i).code(j).str(3) - '0'; end
00411                                                         if (Contr.ord3.cnt(i).code(j).str(4) >= 'a' & Contr.ord3.cnt(i).code(j).str(4) <= 'z'),
00412                                                            tmpv3 = 10 + Contr.ord3.cnt(i).code(j).str(4) - 'a';
00413                                               else tmpv3 = Contr.ord3.cnt(i).code(j).str(4) - '0'; end
00414                                                         
00415                                                         Contr.ord3.cnt(i).code(j).pos = shift + FL(1).N_level*FL(2).N_level*FL(3).N_level + FL(1).N_level*FL(2).N_level*FL(4).N_level + ...
00416                                                       FL(1).N_level * FL(2).N_level * FL(5).N_level + FL(1).N_level*FL(3).N_level*FL(4).N_level + FL(1).N_level * FL(3).N_level * FL(5).N_level + ...
00417                                                                 FL(1).N_level * FL(4).N_level * FL(5).N_level + (tmpv1 - 1) * FL(3).N_level * FL(4).N_level + (tmpv2 - 1)* FL(4).N_level + tmpv3; 
00418                                                                 
00419                                                         case 5, % BCE
00420                                                         if (Contr.ord3.cnt(i).code(j).str(2) >= 'a' & Contr.ord3.cnt(i).code(j).str(2) <= 'z'),
00421                                                                 tmpv1 = 10 + Contr.ord3.cnt(i).code(j).str(2) - 'a';
00422                                               else tmpv1 = Contr.ord3.cnt(i).code(j).str(2) - '0'; end
00423                                                         if (Contr.ord3.cnt(i).code(j).str(3) >= 'a' & Contr.ord3.cnt(i).code(j).str(3) <= 'z'),
00424                                                            tmpv2 = 10 + Contr.ord3.cnt(i).code(j).str(3) - 'a';
00425                                               else tmpv2 = Contr.ord3.cnt(i).code(j).str(3) - '0'; end
00426                                                         if (Contr.ord3.cnt(i).code(j).str(5) >= 'a' & Contr.ord3.cnt(i).code(j).str(5) <= 'z'),
00427                                                            tmpv3 = 10 + Contr.ord3.cnt(i).code(j).str(5) - 'a';
00428                                               else tmpv3 = Contr.ord3.cnt(i).code(j).str(5) - '0'; end
00429                                                         
00430                                                         Contr.ord3.cnt(i).code(j).pos = shift + FL(1).N_level*FL(2).N_level*FL(3).N_level + FL(1).N_level*FL(2).N_level*FL(4).N_level + ...
00431                                                       FL(1).N_level*FL(2).N_level*FL(5).N_level + FL(1).N_level*FL(3).N_level*FL(4).N_level + ...
00432                                                                 FL(1).N_level*FL(3).N_level*FL(5).N_level + FL(1).N_level*FL(4).N_level*FL(5).N_level + FL(2).N_level * FL(3).N_level * FL(4).N_level + ...
00433                                                                 (tmpv1 - 1) * FL(3).N_level * FL(5).N_level + (tmpv2 - 1)* FL(5).N_level + tmpv3;       
00434                                                 
00435                                         end     % switch Contr.ord3.cnt(i).idx3
00436                                         
00437                                         case 4, % Do I want BDE here?
00438                                            if (Contr.ord3.cnt(i).idx3 == 5),
00439                                                    if (Contr.ord3.cnt(i).code(j).str(2) >= 'a' & Contr.ord3.cnt(i).code(j).str(2) <= 'z'),
00440                                                                 tmpv1 = 10 + Contr.ord3.cnt(i).code(j).str(2) - 'a';
00441                                               else tmpv1 = Contr.ord3.cnt(i).code(j).str(2) - '0'; end
00442                                                         if (Contr.ord3.cnt(i).code(j).str(4) >= 'a' & Contr.ord3.cnt(i).code(j).str(4) <= 'z'),
00443                                                            tmpv2 = 10 + Contr.ord3.cnt(i).code(j).str(4) - 'a';
00444                                               else tmpv2 = Contr.ord3.cnt(i).code(j).str(4) - '0'; end
00445                                                         if (Contr.ord3.cnt(i).code(j).str(5) >= 'a' & Contr.ord3.cnt(i).code(j).str(4) <= 'z'),
00446                                                            tmpv3 = 10 + Contr.ord3.cnt(i).code(j).str(5) - 'a';
00447                                               else tmpv3 = Contr.ord3.cnt(i).code(j).str(5) - '0'; end
00448                                                         
00449                                                         Contr.ord3.cnt(i).code(j).pos = shift + FL(1).N_level*FL(2).N_level*FL(3).N_level + FL(1).N_level*FL(2).N_level*FL(4).N_level + ...
00450                                                          FL(1).N_level*FL(2).N_level*FL(5).N_level + FL(1).N_level*FL(3).N_level*FL(4).N_level + ...
00451                                                                    FL(1).N_level*FL(3).N_level*FL(5).N_level + FL(1).N_level*FL(4).N_level*FL(5).N_level + ...
00452                                                                         FL(2).N_level*FL(3).N_level*FL(4).N_level + FL(2).N_level*FL(3).N_level*FL(5).N_level + ...
00453                                                                         (tmpv1 - 1) * FL(4).N_level * FL(5).N_level + (tmpv2 - 1)* FL(5).N_level + tmpv3;
00454                                                 else fprintf('\nSomething is wrong in the contrast coding!\n'); fprintf(2,'Halted: Ctrl+c to exit'); pause;     end
00455                                         
00456                                 end     % switch Contr.ord3.cnt(i).idx2
00457                         case 3,  % Do I want CDE here?
00458                            if (Contr.ord3.cnt(i).idx1 == 3 & Contr.ord3.cnt(i).idx2 == 4 & Contr.ord3.cnt(i).idx3 == 5),
00459                                    if (Contr.ord3.cnt(i).code(j).str(3) >= 'a' & Contr.ord3.cnt(i).code(j).str(3) <= 'z'),
00460                                                 tmpv1 = 10 + Contr.ord3.cnt(i).code(j).str(3) - 'a';
00461                                         else tmpv1 = Contr.ord3.cnt(i).code(j).str(2) - '0'; end
00462                                         if (Contr.ord3.cnt(i).code(j).str(4) >= 'a' & Contr.ord3.cnt(i).code(j).str(4) <= 'z'),
00463                                            tmpv2 = 10 + Contr.ord3.cnt(i).code(j).str(4) - 'a';
00464                                         else tmpv2 = Contr.ord3.cnt(i).code(j).str(4) - '0'; end
00465                                         if (Contr.ord3.cnt(i).code(j).str(5) >= 'a' & Contr.ord3.cnt(i).code(j).str(4) <= 'z'),
00466                                            tmpv3 = 10 + Contr.ord3.cnt(i).code(j).str(5) - 'a';
00467                                         else tmpv3 = Contr.ord3.cnt(i).code(j).str(5) - '0'; end
00468                                                         
00469                                         Contr.ord3.cnt(i).code(j).pos = shift + FL(1).N_level*FL(2).N_level*FL(3).N_level + FL(1).N_level*FL(2).N_level*FL(4).N_level + ...
00470                                            FL(1).N_level*FL(2).N_level*FL(5).N_level + FL(1).N_level*FL(3).N_level*FL(4).N_level + ...
00471                                            FL(1).N_level*FL(3).N_level*FL(5).N_level + FL(1).N_level*FL(4).N_level*FL(5).N_level + ...
00472                                                 FL(2).N_level*FL(3).N_level*FL(4).N_level + FL(2).N_level*FL(3).N_level*FL(5).N_level + ...
00473                                                         + FL(2).N_level*FL(4).N_level*FL(5).N_level + (tmpv1 - 1) * FL(4).N_level * FL(5).N_level + (tmpv2 - 1)* FL(5).N_level + tmpv3;
00474                                 else fprintf('\nSomething is wrong in the contrast coding!\n'); fprintf(2,'Halted: Ctrl+c to exit'); pause;     end
00475                                                                 
00476                         case 4,
00477                            fprintf('\nSomething is wrong in the contrast coding!\n');
00478                       fprintf(2,'Halted: Ctrl+c to exit'); pause;                       
00479                    end   % switch Contr.ord3.cnt(i).idx1
00480                         
00481                         count = 0;
00482                    for (ll = 1:1:n)  % Should have a more decent way to do this in a matrix fashion instead of a lenthy loop?
00483                       tmpstr1 = char (group{Contr.ord3.cnt(i).idx1}(ll));
00484                                 tmpstr2 = char (group{Contr.ord3.cnt(i).idx2}(ll));
00485                                 tmpstr3 = char (group{Contr.ord3.cnt(i).idx3}(ll));
00486                                 if strcmp(tmpstr1, FL(Contr.ord3.cnt(i).idx1).level(tmpv1).expr) & strcmp(tmpstr2, FL(Contr.ord3.cnt(i).idx2).level(tmpv2).expr) ...
00487                                    & strcmp(tmpstr3, FL(Contr.ord3.cnt(i).idx3).level(tmpv3).expr)
00488                               count = count + 1;   % total number of occurences at tmpv-th level
00489                            end  
00490                         end
00491                    Contr.ord3.cnt(i).vec = Contr.ord3.cnt(i).vec + Contr.ord3.cnt(i).coef(j) * dmat(:, Contr.ord3.cnt(i).code(j).pos)'/count;                   
00492                    Contr.ord3.cnt(i).scalar = Contr.ord3.cnt(i).scalar + Contr.ord3.cnt(i).coef(j)*Contr.ord3.cnt(i).coef(j)/count;    % For variance coef: j-th term in i-th 3rd-order contrast.       
00493                         
00494 %                  Contr.ord3.cnt(i).scalar = tmp * Contr.ord3.cnt(i).coef*Contr.ord3.cnt(i).coef';             
00495 %                  Contr.ord3.cnt(i).vec = Contr.ord3.cnt(i).vec + Contr.ord3.cnt(i).coef(j) * dmat(:, Contr.ord3.cnt(i).code(j).pos)';                 
00496       end       % for (j = 1:1:Contr.ord3.cnt(i).NT)
00497 %          Contr.ord3.cnt(i).vec = Contr.ord3.cnt(i).vec*tmp;   % assuming balanced design!!!
00498    end   %for (i = 1:1:Contr3.tot)
00499 
00500 case 4,
00501 
00502    shift = 1 + num_col(1) + num_col(2) + num_col(3);   % skip grand mean, factor means and 2nd-roder terms
00503    for (i = 1:1:Contr.ord4.tot),   
00504    % for the  non-zero indices
00505            Contr.ord4.cnt(i).vec = zeros(1, n);  % n = ntot in anovan.m: total number of input files, and no. of arrows in dmat
00506            Contr.ord4.cnt(i).scalar = 0;
00507                 for (j = 1:1:Contr.ord4.cnt(i).NT),   % for each term in a contrast
00508          first = 0;
00509                    Contr.ord4.cnt(i).code(j).pos = 0;
00510                         
00511                    for (k = 1:1:NF),
00512             if (Contr.ord4.cnt(i).code(j).str(k) >= 'a' & Contr.ord4.cnt(i).code(j).str(k) <= 'z'), 
00513                                    tmpv = 10 + Contr.ord4.cnt(i).code(j).str(k) - 'a';
00514                            else tmpv = Contr.ord4.cnt(i).code(j).str(k) - '0'; end
00515                         
00516                            if (tmpv ~= 0),  
00517                     first = first + 1;  % the first non-zero index 
00518                                         % Maybe I should replace all idx with idx() in *.m and Contr.ord4.cnt(i).idx(first) = k when first ~= 0 later?
00519                                    switch first
00520                                         case 1,
00521                                       Contr.ord4.cnt(i).idx1 = k;
00522                          case 2, 
00523                                       Contr.ord4.cnt(i).idx2 = k;
00524                                    case 3,
00525                                       Contr.ord4.cnt(i).idx3 = k; 
00526                                         case 4,
00527                                            Contr.ord4.cnt(i).idx4 = k;
00528                                         end             
00529                       end  % if (tmpv ~= 0)
00530               end  % for (k = 1:1:NF)
00531                    switch Contr.ord4.cnt(i).idx1
00532                    case 1,
00533                            switch Contr.ord4.cnt(i).idx2
00534                                 case 2,
00535                                    switch Contr.ord4.cnt(i).idx3
00536                                         case 3, 
00537                                                 switch Contr.ord4.cnt(i).idx4
00538                                                 case 4, % ABCD                          
00539                                                         
00540                                                         if (Contr.ord4.cnt(i).code(j).str(1) >= 'a' & Contr.ord4.cnt(i).code(j).str(1) <= 'z'),
00541                                                                 tmpv1 = 10 + Contr.ord4.cnt(i).code(j).str(1) - 'a';
00542                                               else tmpv1 = Contr.ord4.cnt(i).code(j).str(1) - '0'; end
00543                                                         if (Contr.ord4.cnt(i).code(j).str(2) >= 'a' & Contr.ord4.cnt(i).code(j).str(2) <= 'z'),
00544                                                            tmpv2 = 10 + Contr.ord4.cnt(i).code(j).str(2) - 'a';
00545                                               else tmpv2 = Contr.ord4.cnt(i).code(j).str(2) - '0'; end
00546                                                         if (Contr.ord4.cnt(i).code(j).str(3) >= 'a' & Contr.ord4.cnt(i).code(j).str(3) <= 'z'),
00547                                                            tmpv3 = 10 + Contr.ord4.cnt(i).code(j).str(3) - 'a';
00548                                               else tmpv3 = Contr.ord4.cnt(i).code(j).str(3) - '0'; end
00549                                                         if (Contr.ord4.cnt(i).code(j).str(4) >= 'a' & Contr.ord4.cnt(i).code(j).str(4) <= 'z'),
00550                                                            tmpv4 = 10 + Contr.ord4.cnt(i).code(j).str(4) - 'a';
00551                                               else tmpv4 = Contr.ord4.cnt(i).code(j).str(4) - '0'; end
00552                                                         
00553                                                         Contr.ord4.cnt(i).code(j).pos = shift + (tmpv1 - 1) * FL(2).N_level * FL(3).N_level * FL(4).N_level + ...
00554                                                  (tmpv2 - 1) * FL(3).N_level * FL(4).N_level + (tmpv3 - 1) * FL(4).N_level + tmpv4; 
00555 
00556                                                 case 5, % ABCE
00557                                                    if (Contr.ord4.cnt(i).code(j).str(1) >= 'a' & Contr.ord4.cnt(i).code(j).str(1) <= 'z'),
00558                                                                 tmpv1 = 10 + Contr.ord4.cnt(i).code(j).str(1) - 'a';
00559                                               else tmpv1 = Contr.ord4.cnt(i).code(j).str(1) - '0'; end
00560                                                         if (Contr.ord4.cnt(i).code(j).str(2) >= 'a' & Contr.ord4.cnt(i).code(j).str(2) <= 'z'),
00561                                                            tmpv2 = 10 + Contr.ord4.cnt(i).code(j).str(2) - 'a';
00562                                               else tmpv2 = Contr.ord4.cnt(i).code(j).str(2) - '0'; end
00563                                                         if (Contr.ord4.cnt(i).code(j).str(3) >= 'a' & Contr.ord4.cnt(i).code(j).str(3) <= 'z'),
00564                                                            tmpv3 = 10 + Contr.ord4.cnt(i).code(j).str(3) - 'a';
00565                                               else tmpv3 = Contr.ord4.cnt(i).code(j).str(3) - '0'; end
00566                                                         if (Contr.ord4.cnt(i).code(j).str(5) >= 'a' & Contr.ord4.cnt(i).code(j).str(5) <= 'z'),
00567                                                            tmpv4 = 10 + Contr.ord4.cnt(i).code(j).str(5) - 'a';
00568                                               else tmpv4 = Contr.ord4.cnt(i).code(j).str(5) - '0'; end                                                  
00569                                                         
00570                                                         Contr.ord4.cnt(i).code(j).pos = shift + FL(1).N_level * FL(2).N_level * FL(3).N_level * FL(4).N_level + ...
00571                                                  (tmpv1 - 1) * FL(2).N_level * FL(3).N_level * FL(5).N_level + (tmpv2 - 1) * FL(3).N_level * FL(5).N_level + ...
00572                                                                 (tmpv3 - 1) * FL(5).N_level + tmpv4; % ABCD
00573                                                 end  % switch Contr.ord4.cnt(i).idx4
00574                                         case 4,
00575                                            if (Contr.ord4.cnt(i).idx4 == 5)
00576                                                    if (Contr.ord4.cnt(i).code(j).str(1) >= 'a' & Contr.ord4.cnt(i).code(j).str(1) <= 'z'),
00577                                                                 tmpv1 = 10 + Contr.ord4.cnt(i).code(j).str(1) - 'a';
00578                                               else tmpv1 = Contr.ord4.cnt(i).code(j).str(1) - '0'; end
00579                                                         if (Contr.ord4.cnt(i).code(j).str(2) >= 'a' & Contr.ord4.cnt(i).code(j).str(2) <= 'z'),
00580                                                            tmpv2 = 10 + Contr.ord4.cnt(i).code(j).str(2) - 'a';
00581                                               else tmpv2 = Contr.ord4.cnt(i).code(j).str(2) - '0'; end
00582                                                         if (Contr.ord4.cnt(i).code(j).str(4) >= 'a' & Contr.ord4.cnt(i).code(j).str(4) <= 'z'),
00583                                                            tmpv3 = 10 + Contr.ord4.cnt(i).code(j).str(4) - 'a';
00584                                               else tmpv3 = Contr.ord4.cnt(i).code(j).str(4) - '0'; end
00585                                                         if (Contr.ord4.cnt(i).code(j).str(5) >= 'a' & Contr.ord4.cnt(i).code(j).str(5) <= 'z'),
00586                                                            tmpv4 = 10 + Contr.ord4.cnt(i).code(j).str(5) - 'a';
00587                                               else tmpv4 = Contr.ord4.cnt(i).code(j).str(5) - '0'; end                                                  
00588                                                         
00589                                                         Contr.ord4.cnt(i).code(j).pos = shift + FL(1).N_level * FL(2).N_level * FL(3).N_level * FL(4).N_level + ...
00590                                                  FL(1).N_level * FL(2).N_level * FL(3).N_level * FL(5).N_level + ...
00591                                                                 (tmpv1 - 1) * FL(2).N_level * FL(4).N_level * FL(5).N_level + (tmpv2 - 1) * FL(4).N_level * FL(5).N_level + ...
00592                                                                 (tmpv3 - 1) * FL(5).N_level + tmpv4; % ABCD
00593                                                 else fprintf('\nSomething is wrong in the contrast coding!\n'); fprintf(2,'Halted: Ctrl+c to exit'); pause;     end  % if (Contr.ord4.cnt(i).idx4 == 5)
00594                                         end     % switch Contr.ord4.cnt(i).idx3
00595                                 case 3,
00596                                    if (Contr.ord4.cnt(i).idx3 == 4 &  Contr.ord4.cnt(i).idx4 == 5), % ACDE
00597                                                    if (Contr.ord4.cnt(i).code(j).str(1) >= 'a' & Contr.ord4.cnt(i).code(j).str(1) <= 'z'),
00598                                                                 tmpv1 = 10 + Contr.ord4.cnt(i).code(j).str(1) - 'a';
00599                                               else tmpv1 = Contr.ord4.cnt(i).code(j).str(1) - '0'; end
00600                                                         if (Contr.ord4.cnt(i).code(j).str(3) >= 'a' & Contr.ord4.cnt(i).code(j).str(3) <= 'z'),
00601                                                            tmpv2 = 10 + Contr.ord4.cnt(i).code(j).str(3) - 'a';
00602                                               else tmpv2 = Contr.ord4.cnt(i).code(j).str(3) - '0'; end
00603                                                         if (Contr.ord4.cnt(i).code(j).str(4) >= 'a' & Contr.ord4.cnt(i).code(j).str(4) <= 'z'),
00604                                                            tmpv3 = 10 + Contr.ord4.cnt(i).code(j).str(4) - 'a';
00605                                               else tmpv3 = Contr.ord4.cnt(i).code(j).str(4) - '0'; end
00606                                                         if (Contr.ord4.cnt(i).code(j).str(5) >= 'a' & Contr.ord4.cnt(i).code(j).str(5) <= 'z'),
00607                                                            tmpv4 = 10 + Contr.ord4.cnt(i).code(j).str(5) - 'a';
00608                                               else tmpv4 = Contr.ord4.cnt(i).code(j).str(5) - '0'; end                                                  
00609                                                         
00610                                                         Contr.ord4.cnt(i).code(j).pos = shift + FL(1).N_level * FL(2).N_level * FL(3).N_level * FL(4).N_level + ...
00611                                                  FL(1).N_level * FL(2).N_level * FL(3).N_level * FL(5).N_level + FL(1).N_level * FL(2).N_level * FL(4).N_level * FL(5).N_level + ...
00612                                                                 (tmpv1 - 1) * FL(3).N_level * FL(4).N_level * FL(5).N_level + (tmpv2 - 1) * FL(4).N_level * FL(5).N_level + ...
00613                                                                 (tmpv3 - 1) * FL(5).N_level + tmpv4; % ABCD
00614                                         else fprintf('\nSomething is wrong in the contrast coding!\n'); fprintf(2,'Halted: Ctrl+c to exit'); pause;     end                     
00615                                 end  % switch Contr.ord4.cnt(i).idx2
00616                         case 2,
00617                            if (Contr.ord4.cnt(i).idx2 == 3 & Contr.ord4.cnt(i).idx3 == 4 & Contr.ord4.cnt(i).idx4 == 5),  % BCDE
00618                                                    if (Contr.ord4.cnt(i).code(j).str(2) >= 'a' & Contr.ord4.cnt(i).code(j).str(2) <= 'z'),
00619                                                                 tmpv1 = 10 + Contr.ord4.cnt(i).code(j).str(2) - 'a';
00620                                               else tmpv1 = Contr.ord4.cnt(i).code(j).str(2) - '0'; end
00621                                                         if (Contr.ord4.cnt(i).code(j).str(3) >= 'a' & Contr.ord4.cnt(i).code(j).str(3) <= 'z'),
00622                                                            tmpv2 = 10 + Contr.ord4.cnt(i).code(j).str(3) - 'a';
00623                                               else tmpv2 = Contr.ord4.cnt(i).code(j).str(3) - '0'; end
00624                                                         if (Contr.ord4.cnt(i).code(j).str(4) >= 'a' & Contr.ord4.cnt(i).code(j).str(4) <= 'z'),
00625                                                            tmpv3 = 10 + Contr.ord4.cnt(i).code(j).str(4) - 'a';
00626                                               else tmpv3 = Contr.ord4.cnt(i).code(j).str(4) - '0'; end
00627                                                         if (Contr.ord4.cnt(i).code(j).str(5) >= 'a' & Contr.ord4.cnt(i).code(j).str(5) <= 'z'),
00628                                                            tmpv4 = 10 + Contr.ord4.cnt(i).code(j).str(5) - 'a';
00629                                               else tmpv4 = Contr.ord4.cnt(i).code(j).str(5) - '0'; end                                                  
00630                                                         
00631                                                         Contr.ord4.cnt(i).code(j).pos = shift + FL(1).N_level * FL(2).N_level * FL(3).N_level * FL(4).N_level + ...
00632                                                  FL(1).N_level * FL(2).N_level * FL(3).N_level * FL(5).N_level + FL(1).N_level * FL(2).N_level * FL(4).N_level * FL(5).N_level + ...
00633                                                                 FL(1).N_level * FL(3).N_level * FL(4).N_level * FL(5).N_level + (tmpv1 - 1) * FL(3).N_level * FL(4).N_level * FL(5).N_level + ...
00634                                                                 (tmpv2 - 1) * FL(4).N_level * FL(5).N_level + (tmpv3 - 1) * FL(5).N_level + tmpv4; % ABCD
00635                                 else fprintf('\nSomething is wrong in the contrast coding!\n'); fprintf(2,'Halted: Ctrl+c to exit'); pause;     end                                                             
00636                         case {3,4,}
00637                            fprintf('\nSomething is wrong in the contrast coding!\n');
00638                       fprintf(2,'Halted: Ctrl+c to exit'); pause;                       
00639                    end   % switch Contr.ord4.cnt(i).idx1
00640                         
00641                         count = 0;
00642                    for (ll = 1:1:n)  % Should have a more decent way to do this in a matrix fashion instead of a lenthy loop?
00643                       tmpstr1 = char (group{Contr.ord4.cnt(i).idx1}(ll));
00644                                 tmpstr2 = char (group{Contr.ord4.cnt(i).idx2}(ll));
00645                                 tmpstr3 = char (group{Contr.ord4.cnt(i).idx3}(ll));
00646                                 tmpstr4 = char (group{Contr.ord4.cnt(i).idx4}(ll));
00647                                 if strcmp(tmpstr1, FL(Contr.ord4.cnt(i).idx1).level(tmpv1).expr) & strcmp(tmpstr2, FL(Contr.ord4.cnt(i).idx2).level(tmpv2).expr) ...
00648                                    & strcmp(tmpstr3, FL(Contr.ord4.cnt(i).idx3).level(tmpv3).expr) & strcmp(tmpstr4, FL(Contr.ord4.cnt(i).idx4).level(tmpv4).expr)
00649                               count = count + 1;   % total number of occurences at tmpv-th level
00650                            end  
00651                         end % for (ll = 1:1:n)
00652                    Contr.ord4.cnt(i).vec = Contr.ord4.cnt(i).vec + Contr.ord4.cnt(i).coef(j) * dmat(:, Contr.ord4.cnt(i).code(j).pos)'/count;                   
00653                    Contr.ord4.cnt(i).scalar = Contr.ord4.cnt(i).scalar + Contr.ord4.cnt(i).coef(j)*Contr.ord4.cnt(i).coef(j)/count;    % For variance coef: j-th term in i-th 4th-order contrast.                               
00654       end       % for (j = 1:1:Contr.ord4.cnt(i).NT)
00655    end   %for (i = 1:1:Contr4.tot)
00656 
00657 end % switch order
00658 
00659 err = 0;
00660 return;
 

Powered by Plone

This site conforms to the following standards: