0001
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
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069 function specGRP=bin_op_specGRP(specGRP,op,groupA,binA,groupB,binB,neo_bindesc)
0070
0071 if nargin<7,
0072 neo_bindesc=[];
0073 end
0074
0075 if strcmpi(groupA,groupB),
0076 error('groupA and groupB are the same (%s). For within-subject difference waves use bin_dif.m.',groupA);
0077 end
0078
0079 if strcmpi(op,'A-B') || strcmpi(op,'B-A'),
0080 op_sign='-';
0081 elseif strcmpi(op,'(A+B)/n')
0082 op_sign='+';
0083 else
0084 error('Argument "op" must be ''A-B'',''B-A'',or ''(A+B)/n''.');
0085 end
0086
0087 n_chans=length(specGRP.chanlocs);
0088 n_freqs=length(specGRP.freqs);
0089 n_binsGRP=length(specGRP.bin_info);
0090 neo_bin=n_binsGRP+1;
0091 n_groups=length(specGRP.group_desc);
0092 grpA_id=0;
0093 grpB_id=0;
0094 for a=1:n_groups,
0095 if strcmpi(specGRP.group_desc{a},groupA),
0096 if grpA_id,
0097 error('groupA (%s) matches multiple group descriptors in this specGRP variable.',groupA);
0098 else
0099 grpA_id=a;
0100 end
0101 elseif strcmpi(specGRP.group_desc{a},groupB),
0102 if grpB_id,
0103 error('groupB (%s) matches multiple group descriptors in this specGRP variable.',groupB);
0104 else
0105 grpB_id=a;
0106 end
0107 end
0108 end
0109 if ~grpA_id,
0110 error('groupA (%s) not found in this specGRP variable. Enter "headinfo_spec(specGRP)" to see possible names.',groupA);
0111 end
0112 if ~grpB_id,
0113 error('groupB (%s) not found in this specGRP variable. Enter "headinfo_spec(specGRP)" to see possible names.',groupB);
0114 end
0115
0116 load(specGRP.specGND_fnames{grpA_id},'-MAT');
0117 n_subA=specGND.sub_ct;
0118 load(specGRP.specGND_fnames{grpB_id},'-MAT');
0119 n_subB=specGND.sub_ct;
0120 if isempty(neo_bindesc),
0121 if op_sign=='-',
0122 specGRP.bin_info(neo_bin).bindesc=sprintf('%s, Bin %d%c%s, Bin %d',groupA,binA, ...
0123 op_sign,groupB,binB);
0124 else
0125 specGRP.bin_info(neo_bin).bindesc=sprintf('((%d*%s, Bin %d)%c(%d*%s, Bin %d))/%d', ...
0126 n_subA,groupA,binA,op_sign,n_subB,groupB,binB,n_subA+n_subB);
0127 end
0128 else
0129 specGRP.bin_info(neo_bin).bindesc=neo_bindesc;
0130 end
0131 specGRP.bin_info(neo_bin).groupA=grpA_id;
0132 specGRP.bin_info(neo_bin).groupB=grpB_id;
0133 specGRP.bin_info(neo_bin).source_binA=binA;
0134 specGRP.bin_info(neo_bin).source_binB=binB;
0135
0136
0137
0138 if strcmpi(op,'(A+B)/n'),
0139 all_subs=zeros(n_chans,n_freqs,n_subA+n_subB);
0140 specGRP.dif(neo_bin)=0;
0141 else
0142 sums=zeros(n_chans,n_freqs,2);
0143 means=sums;
0144 ss=sums;
0145 specGRP.dif(neo_bin)=1;
0146 end
0147 bins=[binA binB];
0148 n_subs=[0 0];
0149
0150
0151 for grp=1:2,
0152
0153 load(specGRP.specGND_fnames{grp},'-MAT');
0154 if bins(grp)>length(specGND.bindesc)
0155 error('The specGND variable from %s only has %d bins but you''re trying to import Bin %d.', ...
0156 specGRP.specGND_fnames{grp},length(specGND.bindesc),bins(grp));
0157 end
0158
0159
0160 use_chans=zeros(1,length(specGND.chanlocs));
0161 for c=1:length(specGND.chanlocs),
0162 for d=1:n_chans,
0163 if strcmpi(specGND.chanlocs(c).labels,specGRP.chanlocs(d).labels),
0164 use_chans(c)=1;
0165 break;
0166 end
0167 end
0168 end
0169 use_chans=find(use_chans);
0170 if ~isequal(specGND.chanlocs(use_chans),specGRP.chanlocs),
0171 error('The channel location information in the specGND variable from file %s differs from that in the specGRP variable.', ...
0172 specGRP.specGND_fnames{grp});
0173 end
0174
0175
0176 use_subs=find(specGND.indiv_bin_ct(:,bins(grp)))';
0177 n_subs(grp)=length(use_subs);
0178 if grp==1,
0179
0180 specGRP.bin_info(neo_bin).n_subsA=n_subs(grp);
0181 else
0182
0183 specGRP.bin_info(neo_bin).n_subsB=n_subs(grp);
0184 end
0185
0186
0187 indiv_bin_ct{grp}=specGND.indiv_bin_ct(:,bins(grp));
0188 indiv_bin_raw_ct{grp}=specGND.indiv_bin_raw_ct(:,bins(grp));
0189
0190 data=squeeze(specGND.indiv_pow_dB(use_chans,:,bins(grp),use_subs));
0191
0192
0193 if length(size(data))~=3,
0194 error('Contributing power spectra from file %s have only one participant, time point, and/or channel. I can''t deal with that.', ...
0195 specGRP.specGND_fnames{grp});
0196 end
0197
0198 if strcmpi(op,'(A+B)/n'),
0199 if grp==1,
0200 all_subs(:,:,1:n_subs(grp))=data;
0201 else
0202 all_subs(:,:,n_subs(1)+1:end)=data;
0203 end
0204 else
0205 sums(:,:,grp)=sum(data,3);
0206 means(:,:,grp)=sums(:,:,grp)/n_subs(grp);
0207 ss(:,:,grp)=sum(data.^2,3)-(squeeze(sums(:,:,grp)).^2)/n_subs(grp);
0208 end
0209 end
0210 specGRP.bin_info(neo_bin).op=op;
0211
0212 for a=1:n_groups,
0213 n_subs_grp=length(specGRP.indiv_subnames{a});
0214 if a==grpA_id,
0215 specGRP.indiv_bin_ct{a}(1:n_subs_grp,neo_bin)=indiv_bin_ct{1};
0216 specGRP.indiv_bin_raw_ct{a}(1:n_subs_grp,neo_bin)=indiv_bin_raw_ct{1};
0217 elseif a==grpB_id,
0218 specGRP.indiv_bin_ct{a}(1:n_subs_grp,neo_bin)=indiv_bin_ct{2};
0219 specGRP.indiv_bin_raw_ct{a}(1:n_subs_grp,neo_bin)=indiv_bin_raw_ct{2};
0220 else
0221 specGRP.indiv_bin_ct{a}(1:n_subs_grp,neo_bin)=zeros(1:n_subs,1);
0222 specGRP.indiv_bin_raw_ct{a}(1:n_subs_grp,neo_bin)=zeros(1:n_subs,1);
0223 end
0224 end
0225
0226
0227 if strcmpi(op,'A-B'),
0228 specGRP.grands_pow_dB(:,:,neo_bin)=means(:,:,1)-means(:,:,2);
0229 elseif strcmpi(op,'B-A'),
0230 specGRP.grands_pow_dB(:,:,neo_bin)=means(:,:,2)-means(:,:,1);
0231 else
0232
0233
0234 [p_values, t_scores, mn, stder]=fast_t1(all_subs,0,0);
0235 specGRP.grands_pow_dB(:,:,neo_bin)=mn;
0236 specGRP.grands_pow_dB_t(:,:,neo_bin)=t_scores;
0237 specGRP.grands_pow_dB_stder(:,:,neo_bin)=stder;
0238 end
0239
0240 if ~strcmpi(op,'(A+B)/n'),
0241
0242 ssP=(ss(:,:,1)+ss(:,:,2))/(sum(n_subs)-2);
0243 specGRP.grands_pow_dB_stder(:,:,neo_bin)=sqrt( ssP*sum(n_subs)/(n_subs(1)*n_subs(2)) );
0244
0245 specGRP.grands_pow_dB_t=specGRP.grands_pow_dB./specGRP.grands_pow_dB_stder;
0246 end
0247
0248 fprintf('<<New bin successfully created>>\n');
0249 fprintf('Bin %d: %s\n',neo_bin,specGRP.bin_info(neo_bin).bindesc);
0250 hist_cmd=sprintf('specGRP=bin_op_specGRP(specGRP,''%s'',''%s'',%d,''%s'',%d,''%s'');', ...
0251 op,groupA,binA,groupB,binB,specGRP.bin_info(neo_bin).bindesc);
0252 specGRP.history{length(specGRP.history)+1}=hist_cmd;
0253 specGRP.saved='no';
0254