


bin_op_specGRP() - Computes the difference between the power spectra from
two bins or the mean of the power spectra from two bins of
a specGRP variable and stores the resultant values as a
new bin in the specGRP variable.
Usage:
>> specGRP=bin_op_specGRP(specGRP,op,groupA,binA,groupB,binB,neo_bindesc);
Required Inputs:
specGRP - A specGRP structure variable. You can create a specGRP variable
from files of specGND variables (i.e., *.specGND files)
using specGNDs2specGRP.m. See MATLABmk documentation
for detailed information about the format of a specGRP variable.
op - [string] One of the following three "bin operators":
'A-B' = new bin will be the difference wave produced by
subtracting the bin from Group B from the bin from
Group A. Grand average t-scores are based on
independent samples t-statistics.
'B-A' = new bin will be the difference wave produced by
subtracting the bin from Group A from the bin from
Group B. Grand average t-scores are based on two
independent samples t-statistics.
'(A+B)/n'= new bin will be the mean of the bins from Group
A and B. The means will be weighted by the
number of participants in each bin. Thus the
results are equivalent to what you would derive
if all participants were in the same group.
Grand average t-scores are based on one sample
t-statistics.
groupA - [string] The group descriptor for Group A (e.g., 'patients')
Use the function headinfo_spec.m to see what groups are available.
binA - [integer] A bin index from Group A's specGND variable. Note this is
NOT a bin in the specGRP variable. Use the function headinfo_spec.m on
Group A's specGND variable to see what bins are available
groupB - [string] Same as groupA but for Group B.
binB - [integer] Same as binA but for Group B.
Optional Inputs:
neo_bindesc - [string] The bin descriptor for the new bin being
created. {default: '$, Bin #-$$ Bin ##', where # is the
value of binA, ## is the value of binB, $ is Group A's
descriptor, and $$ is Group B's descriptor}
Examples:
-The following command creates a new bin in the specGRP variable that
contains the power spectra for Bin 3 in the Female group minus that of
Bin 3 in the Male group:
>>specGRP=bin_op_specGRP(specGRP,'A-B','Female',3,'Male',3,'Female-Male (Eyes Closed-Open)');
-The following command creates a new bin in the specGRP variable that
contains the weighted average of the power spectra in Bin 3 of the Female
and Male group.
>>specGRP=bin_op_specGRP(specGRP,'(A+B)/n','Female',3,'Male',3,'Female+Male
(Eyes Closed-Open)');
Author:
David Groppe
Kutaslab, 12/2010

0001 % bin_op_specGRP() - Computes the difference between the power spectra from 0002 % two bins or the mean of the power spectra from two bins of 0003 % a specGRP variable and stores the resultant values as a 0004 % new bin in the specGRP variable. 0005 % 0006 % Usage: 0007 % >> specGRP=bin_op_specGRP(specGRP,op,groupA,binA,groupB,binB,neo_bindesc); 0008 % 0009 % Required Inputs: 0010 % specGRP - A specGRP structure variable. You can create a specGRP variable 0011 % from files of specGND variables (i.e., *.specGND files) 0012 % using specGNDs2specGRP.m. See MATLABmk documentation 0013 % for detailed information about the format of a specGRP variable. 0014 % op - [string] One of the following three "bin operators": 0015 % 'A-B' = new bin will be the difference wave produced by 0016 % subtracting the bin from Group B from the bin from 0017 % Group A. Grand average t-scores are based on 0018 % independent samples t-statistics. 0019 % 'B-A' = new bin will be the difference wave produced by 0020 % subtracting the bin from Group A from the bin from 0021 % Group B. Grand average t-scores are based on two 0022 % independent samples t-statistics. 0023 % '(A+B)/n'= new bin will be the mean of the bins from Group 0024 % A and B. The means will be weighted by the 0025 % number of participants in each bin. Thus the 0026 % results are equivalent to what you would derive 0027 % if all participants were in the same group. 0028 % Grand average t-scores are based on one sample 0029 % t-statistics. 0030 % groupA - [string] The group descriptor for Group A (e.g., 'patients') 0031 % Use the function headinfo_spec.m to see what groups are available. 0032 % binA - [integer] A bin index from Group A's specGND variable. Note this is 0033 % NOT a bin in the specGRP variable. Use the function headinfo_spec.m on 0034 % Group A's specGND variable to see what bins are available 0035 % groupB - [string] Same as groupA but for Group B. 0036 % binB - [integer] Same as binA but for Group B. 0037 % 0038 % Optional Inputs: 0039 % neo_bindesc - [string] The bin descriptor for the new bin being 0040 % created. {default: '$, Bin #-$$ Bin ##', where # is the 0041 % value of binA, ## is the value of binB, $ is Group A's 0042 % descriptor, and $$ is Group B's descriptor} 0043 % 0044 % 0045 % Examples: 0046 % -The following command creates a new bin in the specGRP variable that 0047 % contains the power spectra for Bin 3 in the Female group minus that of 0048 % Bin 3 in the Male group: 0049 % >>specGRP=bin_op_specGRP(specGRP,'A-B','Female',3,'Male',3,'Female-Male (Eyes Closed-Open)'); 0050 % 0051 % -The following command creates a new bin in the specGRP variable that 0052 % contains the weighted average of the power spectra in Bin 3 of the Female 0053 % and Male group. 0054 % >>specGRP=bin_op_specGRP(specGRP,'(A+B)/n','Female',3,'Male',3,'Female+Male 0055 % (Eyes Closed-Open)'); 0056 % 0057 % 0058 % Author: 0059 % David Groppe 0060 % Kutaslab, 12/2010 0061 0062 %%%%%%%%%%%%%%%% REVISION LOG %%%%%%%%%%%%%%%%% 0063 % ?/?/2010-?? 0064 0065 %%%%%%%%%%%%%%%% FUTURE WORK %%%%%%%%%%%%%%%%% 0066 % - add verblevel? 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 %preallocate memory 0138 if strcmpi(op,'(A+B)/n'), 0139 all_subs=zeros(n_chans,n_freqs,n_subA+n_subB); %third dimension is participant 0140 specGRP.dif(neo_bin)=0; 0141 else 0142 sums=zeros(n_chans,n_freqs,2); %third dimension is group (1=A, 2=B) 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 %get data from Group A & B 0151 for grp=1:2, 0152 % 1=A, 2=B 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 %get the set of channels to use 0160 use_chans=zeros(1,length(specGND.chanlocs)); 0161 for c=1:length(specGND.chanlocs), 0162 for d=1:n_chans, %n_chans is the number of channels in the specGRP variable 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 %get the set of subjects to use 0176 use_subs=find(specGND.indiv_bin_ct(:,bins(grp)))'; 0177 n_subs(grp)=length(use_subs); 0178 if grp==1, 0179 % # of participants who contributed to this bin from Group A 0180 specGRP.bin_info(neo_bin).n_subsA=n_subs(grp); 0181 else 0182 % # of participants who contributed to this bin from Group B 0183 specGRP.bin_info(neo_bin).n_subsB=n_subs(grp); 0184 end 0185 0186 %get individual participant trial counts 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 %make sure squeezed data has proper dimensions 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 %new power spectra 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 % weighted mean of both bins (the right thing to do for a one-sample 0233 % t-test) 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 %pooled sum of squares 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 %t-score 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