%% Load data.

close all; clear; clc

%-----------------------------------------------
% Specify the name of the COMPASS root directory
dataPath='/path/to/COMPASS/repository/';
%-----------------------------------------------
addpath(genpath([dataPath 'Scripts/']))

[~, txtData, allData]=xlsread([dataPath 'Data/COMPASS_SceneInfo.xlsx']); 
header=txtData(1,:); sceneInfo=cell2table(allData(2:end,:),'VariableNames',header);

[~, txtData, allData]=xlsread([dataPath 'Data/COMPASS_ValenceRatings.xlsx']);
header=txtData(1,:); valRatings_table=cell2table(allData(2:end,:),'VariableNames',header);
valRatings=table2array(valRatings_table(:,2:end-1));

[~, txtData, allData]=xlsread([dataPath 'Data/COMPASS_ArousalRatings.xlsx']);
header=txtData(1,:); arousRatings_table=cell2table(allData(2:end,:),'VariableNames',header);
arousRatings=table2array(arousRatings_table(:,2:end-1));

[~, txtData, allData]=xlsread([dataPath 'Data/COMPASS_ValenceRatingsByAffect.xlsx']);
header=txtData(1,:); rmVal=cell2table(allData(2:end,:),'VariableNames',header);

[~, txtData, allData]=xlsread([dataPath 'Data/COMPASS_ArousalRatingsByAffect.xlsx']);
header=txtData(1,:); rmArous=cell2table(allData(2:end,:),'VariableNames',header);

[~, txtData, allData]=xlsread([dataPath 'Data/COMPASS_ValenceRTs.xlsx']);
header=txtData(1,:); valRTs_table=cell2table(allData(2:end,:),'VariableNames',header);
valRTs=table2array(valRTs_table(:,2:end-1));

[~, txtData, allData]=xlsread([dataPath 'Data/COMPASS_ArousalRTs.xlsx']);
header=txtData(1,:); arousRTs_table=cell2table(allData(2:end,:),'VariableNames',header);
arousRTs=table2array(arousRTs_table(:,2:end-1));

%% Prepare data.

% Exclude bad trials (<150 ms or >4000 ms).

exclValTrials=valRTs>4000 | valRTs<150;
exclArousTrials=arousRTs>4000 | arousRTs<150;

fprintf('Excluded %d (%.1f%%) valence ratings \n',sum(sum(exclValTrials)),...
    sum(sum(exclValTrials))/numel(exclValTrials)*100) 
fprintf('Excluded %d (%.1f%%) arousal ratings \n\n',sum(sum(exclArousTrials)),...
    sum(sum(exclArousTrials))/numel(exclArousTrials)*100) 

valRatings(logical(exclValTrials))=NaN; 
arousRatings(logical(exclArousTrials))=NaN; 

%% Calculate summary statistics of scene-wise valence and arousal ratings by participant gender.

images=sceneInfo.ImageFile;
imageNames=sceneInfo.ImageName;

clearvars meanRatingsWomen meanRatingsMen genderDiff
meanRatingsWomen.Image=images;
meanRatingsWomen=struct2table(meanRatingsWomen);
meanRatingsMen=meanRatingsWomen;
genderDiff=meanRatingsWomen;

ind=valRatings_table.Gender=='1';
meanRatingsMen.ValenceMean=nanmean(valRatings(ind,:))';
meanRatingsMen.ValenceSD=nanstd(valRatings(ind,:))';	
meanRatingsMen.ArousalMean=nanmean(arousRatings(ind,:))';	
meanRatingsMen.ArousalSD=nanstd(arousRatings(ind,:))';	
meanRatingsMen.NumValRatings=sum(~isnan(valRatings(ind,:)))';	
meanRatingsMen.NumArousRatings=sum(~isnan(arousRatings(ind,:)))';

ind2=valRatings_table.Gender=='2';
meanRatingsWomen.ValenceMean=nanmean(valRatings(ind2,:))';
meanRatingsWomen.ValenceSD=nanstd(valRatings(ind2,:))';	
meanRatingsWomen.ArousalMean=nanmean(arousRatings(ind2,:))';	
meanRatingsWomen.ArousalSD=nanstd(arousRatings(ind2,:))';	
meanRatingsWomen.NumValRatings=sum(~isnan(valRatings(ind2,:)))';	
meanRatingsWomen.NumArousRatings=sum(~isnan(arousRatings(ind2,:)))';

for ii=1:numel(images)
    [~,p,~,~]=ttest2(valRatings(ind,ii),valRatings(ind2,ii));
    d=cohensD(valRatings(ind,ii),valRatings(ind2,ii));
    genderDiff.ValSexD(ii,1)=d;genderDiff.ValSexPval(ii,1)=p;
    [~,p,~,~]=ttest2(arousRatings(ind,ii),arousRatings(ind2,ii));
    d=cohensD(arousRatings(ind,ii),arousRatings(ind2,ii));
    genderDiff.ArousSexD(ii,1)=d;genderDiff.ArousSexPval(ii,1)=p;
end

%% Make Figure 5. 
%  The relation between COMPASS valence (1 = unpleasant, 9 = pleasant) and arousal 
%  (1 = low, 9 = high) ratings by participant gender.

lineWidth=1.5;fontSize=15;screenSize=get(0,'ScreenSize');
socColor=[1 .6 .1];nonSocColor=[.1 .6 1];errorColor=[.8 .8 .8];
socInd=strcmp(sceneInfo.SocialContent,'Social');

f=figure('color','w','units','normalized','Position',screenSize);
subplot(1,2,1);hold on
l1=line([1 9],[5 5],'LineWidth',lineWidth,'Color',[.4 .4 .4]);
l2=line([5 5],[1 9],'LineWidth',lineWidth,'Color',[.4 .4 .4]);
semSoc=meanRatingsMen.ValenceSD(socInd)./sqrt(meanRatingsMen.NumValRatings(socInd));
semNonsoc=meanRatingsMen.ValenceSD(~socInd)./sqrt(meanRatingsMen.NumValRatings(~socInd));
e1=errorbar(meanRatingsMen.ValenceMean(socInd),meanRatingsMen.ArousalMean(socInd),...
    semSoc,'o','horizontal','MarkerEdgeColor','none',...
    'Color',errorColor,'MarkerFaceColor',socColor,'DisplayName','Social');
e2=errorbar(meanRatingsMen.ValenceMean(~socInd),meanRatingsMen.ArousalMean(~socInd),...
    semNonsoc,'o','horizontal','MarkerEdgeColor','none',...
    'Color',errorColor,'MarkerFaceColor',nonSocColor,'DisplayName','Nonsocial');
semSoc=meanRatingsMen.ArousalSD(socInd)./sqrt(meanRatingsMen.NumArousRatings(socInd));
semNonsoc=meanRatingsMen.ArousalSD(~socInd)./sqrt(meanRatingsMen.NumArousRatings(~socInd));
errorbar(meanRatingsMen.ValenceMean(socInd),meanRatingsMen.ArousalMean(socInd),...
    semSoc,'o','vertical','MarkerEdgeColor','none',...
    'Color',errorColor,'MarkerFaceColor',socColor);
errorbar(meanRatingsMen.ValenceMean(~socInd),meanRatingsMen.ArousalMean(~socInd),...
    semNonsoc,'o','vertical','MarkerEdgeColor','none',...
    'Color',errorColor,'MarkerFaceColor',nonSocColor);
xlim([1 9]);ylim([1 9]);box on;grid on; axis square
set(gca,'XTick',[1:9],'YTick',[1:9],'LineWidth',lineWidth,'FontSize',fontSize)
xlabel('Valence');ylabel('Arousal'); 
title([{'Mean Valence & Arousal Ratings'};{'Men'}]);l=legend([e1 e2]);

subplot(1,2,2);hold on
l1=line([1 9],[5 5],'LineWidth',lineWidth,'Color',[.4 .4 .4]);
l2=line([5 5],[1 9],'LineWidth',lineWidth,'Color',[.4 .4 .4]);
semSoc=meanRatingsWomen.ValenceSD(socInd)./sqrt(meanRatingsWomen.NumValRatings(socInd));
semNonsoc=meanRatingsWomen.ValenceSD(~socInd)./sqrt(meanRatingsWomen.NumValRatings(~socInd));
e1=errorbar(meanRatingsWomen.ValenceMean(socInd),meanRatingsWomen.ArousalMean(socInd),...
    semSoc,'o','horizontal','MarkerEdgeColor','none',...
    'Color',errorColor,'MarkerFaceColor',socColor,'DisplayName','Social');
e2=errorbar(meanRatingsWomen.ValenceMean(~socInd),meanRatingsWomen.ArousalMean(~socInd),...
    semNonsoc,'o','horizontal','MarkerEdgeColor','none',...
    'Color',errorColor,'MarkerFaceColor',nonSocColor,'DisplayName','Nonsocial');
semSoc=meanRatingsWomen.ArousalSD(socInd)./sqrt(meanRatingsWomen.NumArousRatings(socInd));
semNonsoc=meanRatingsWomen.ArousalSD(~socInd)./sqrt(meanRatingsWomen.NumArousRatings(~socInd));
errorbar(meanRatingsWomen.ValenceMean(socInd),meanRatingsWomen.ArousalMean(socInd),...
    semSoc,'o','vertical','MarkerEdgeColor','none',...
    'Color',errorColor,'MarkerFaceColor',socColor);
errorbar(meanRatingsWomen.ValenceMean(~socInd),meanRatingsWomen.ArousalMean(~socInd),...
    semNonsoc,'o','vertical','MarkerEdgeColor','none',...
    'Color',errorColor,'MarkerFaceColor',nonSocColor);
xlim([1 9]);ylim([1 9]);box on;grid on; axis square
set(gca,'XTick',[1:9],'YTick',[1:9],'LineWidth',lineWidth,'FontSize',fontSize)
xlabel('Valence');ylabel('Arousal'); 
title([{'Mean Valence & Arousal Ratings'};{'Women'}]);l=legend([e1 e2]);

%% Make Table 3.
%  Valence and arousal ratings by participant gender.

valCat=unique(sceneInfo.Valence);
socCat=unique(sceneInfo.SocialContent);
arousCat=unique(sceneInfo.Arousal);

fprintf('Valence\t\t\t\t\t\tArousal \n')
fprintf('\t\tMen\t\tWomen\t\tMen\t\tWomen \n')

for ii=1:numel(valCat)
    ind=valRatings_table.Gender=='1';
    ind2=strcmp(sceneInfo.Valence,valCat{ii});
    temp=valRatings(ind,ind2);
    meanValM=nanmean(reshape(temp,1,numel(temp)));
    stdValM=nanstd(reshape(temp,1,numel(temp)));
    temp=arousRatings(ind,ind2);
    meanArousM=nanmean(reshape(temp,1,numel(temp)));
    stdArousM=nanstd(reshape(temp,1,numel(temp)));
    
    ind=valRatings_table.Gender=='2';
    temp=valRatings(ind,ind2);
    meanValW=nanmean(reshape(temp,1,numel(temp)));
    stdValW=nanstd(reshape(temp,1,numel(temp)));
    temp=arousRatings(ind,ind2);
    meanArousW=nanmean(reshape(temp,1,numel(temp)));
    stdArousW=nanstd(reshape(temp,1,numel(temp)));
    
    fprintf('%s     %.2f (%.2f)     %.2f (%.2f)      %.2f (%.2f)    %.2f (%.2f) \n',valCat{ii},...
        meanValM,stdValM,meanValW,stdValW,meanArousM,stdArousM,meanArousW,stdArousW)
end
fprintf('\n');

for ii=2:-1:1
    ind=valRatings_table.Gender=='1';
    ind2=strcmp(sceneInfo.SocialContent,socCat{ii});
    temp=valRatings(ind,ind2);
    meanValM=nanmean(reshape(temp,1,numel(temp)));
    stdValM=nanstd(reshape(temp,1,numel(temp)));
    temp=arousRatings(ind,ind2);
    meanArousM=nanmean(reshape(temp,1,numel(temp)));
    stdArousM=nanstd(reshape(temp,1,numel(temp)));
    
    ind=valRatings_table.Gender=='2';
    temp=valRatings(ind,ind2);
    meanValW=nanmean(reshape(temp,1,numel(temp)));
    stdValW=nanstd(reshape(temp,1,numel(temp)));
    temp=arousRatings(ind,ind2);
    meanArousW=nanmean(reshape(temp,1,numel(temp)));
    stdArousW=nanstd(reshape(temp,1,numel(temp)));
    
    fprintf('%s     %.2f (%.2f)     %.2f (%.2f)      %.2f (%.2f)    %.2f (%.2f) \n',socCat{ii},...
        meanValM,stdValM,meanValW,stdValW,meanArousM,stdArousM,meanArousW,stdArousW)
end
fprintf('\n');


for ii=1:numel(valCat)
    for jj=2:-1:1
    ind=valRatings_table.Gender=='1';
    ind2=strcmp(sceneInfo.Valence,valCat{ii}) & strcmp(sceneInfo.SocialContent,socCat{jj});
    temp=valRatings(ind,ind2);
    meanValM=nanmean(reshape(temp,1,numel(temp)));
    stdValM=nanstd(reshape(temp,1,numel(temp)));
    temp=arousRatings(ind,ind2);
    meanArousM=nanmean(reshape(temp,1,numel(temp)));
    stdArousM=nanstd(reshape(temp,1,numel(temp)));
    
    ind=valRatings_table.Gender=='2';
    temp=valRatings(ind,ind2);
    meanValW=nanmean(reshape(temp,1,numel(temp)));
    stdValW=nanstd(reshape(temp,1,numel(temp)));
    temp=arousRatings(ind,ind2);
    meanArousW=nanmean(reshape(temp,1,numel(temp)));
    stdArousW=nanstd(reshape(temp,1,numel(temp)));
    
    fprintf('%s %s     %.2f (%.2f)     %.2f (%.2f)      %.2f (%.2f)    %.2f (%.2f) \n',...
        valCat{ii},socCat{jj},meanValM,stdValM,meanValW,stdValW,meanArousM,...
        stdArousM,meanArousW,stdArousW)
    end
    fprintf('\n');
end
fprintf('\n');


for ii=1:numel(valCat)
    for jj=1:numel(arousCat)
    ind=valRatings_table.Gender=='1';
    ind2=strcmp(sceneInfo.Valence,valCat{ii}) & strcmp(sceneInfo.Arousal,arousCat{jj});
    temp=valRatings(ind,ind2);
    meanValM=nanmean(reshape(temp,1,numel(temp)));
    stdValM=nanstd(reshape(temp,1,numel(temp)));
    temp=arousRatings(ind,ind2);
    meanArousM=nanmean(reshape(temp,1,numel(temp)));
    stdArousM=nanstd(reshape(temp,1,numel(temp)));
    
    ind=valRatings_table.Gender=='2';
    temp=valRatings(ind,ind2);
    meanValW=nanmean(reshape(temp,1,numel(temp)));
    stdValW=nanstd(reshape(temp,1,numel(temp)));
    temp=arousRatings(ind,ind2);
    meanArousW=nanmean(reshape(temp,1,numel(temp)));
    stdArousW=nanstd(reshape(temp,1,numel(temp)));
    
    fprintf('%s %s     %.2f (%.2f)     %.2f (%.2f)      %.2f (%.2f)    %.2f (%.2f) \n',...
        valCat{ii},arousCat{jj},meanValM,stdValM,meanValW,stdValW,meanArousM,...
        stdArousM,meanArousW,stdArousW)
    end
    fprintf('\n');
end
fprintf('\n');


for ii=1:numel(valCat)
    for jj=1:numel(arousCat)
        for hh=2:-1:1
            ind=valRatings_table.Gender=='1';
            ind2=strcmp(sceneInfo.Valence,valCat{ii}) & ...
                strcmp(sceneInfo.Arousal,arousCat{jj}) ...
                & strcmp(sceneInfo.SocialContent,socCat{hh});
            temp=valRatings(ind,ind2);
            meanValM=nanmean(reshape(temp,1,numel(temp)));
            stdValM=nanstd(reshape(temp,1,numel(temp)));
            temp=arousRatings(ind,ind2);
            meanArousM=nanmean(reshape(temp,1,numel(temp)));
            stdArousM=nanstd(reshape(temp,1,numel(temp)));
            
            ind=valRatings_table.Gender=='2';
            temp=valRatings(ind,ind2);
            meanValW=nanmean(reshape(temp,1,numel(temp)));
            stdValW=nanstd(reshape(temp,1,numel(temp)));
            temp=arousRatings(ind,ind2);
            meanArousW=nanmean(reshape(temp,1,numel(temp)));
            stdArousW=nanstd(reshape(temp,1,numel(temp)));
            
            fprintf('%s %s %s     %.2f (%.2f)     %.2f (%.2f)      %.2f (%.2f)    %.2f (%.2f) \n',...
                valCat{ii},arousCat{jj},socCat{hh},meanValM,stdValM,meanValW,stdValW,...
                meanArousM,stdArousM,meanArousW,stdArousW)
        end
    end
    fprintf('\n');
end
fprintf('\n');

%% Make Figure 6. 
%  Mean valence (top panels) and arousal (bottom panels) ratings for each affective 
%  scene category by participant gender (lower arousal = low to moderate; higher 
%  arousal = moderate to high).

figure('color','w');
subplot(1,2,1);hold on; ind=rmVal.Gender=='1';
e1=errorbar([1 2 3],[nanmean(rmVal.NegHighS(ind)) nanmean(rmVal.NeuMidS(ind)) ...
    nanmean(rmVal.PosHighS(ind))],[sem(rmVal.NegHighS(ind)) sem(rmVal.NeuMidS(ind))...
     sem(rmVal.PosHighS(ind))],'LineWidth',lineWidth,'Color',socColor,'Marker','o',...
    'MarkerEdgeColor',socColor,'MarkerFaceColor',socColor,'DisplayName',...
    'Social Higher Arousal');hold on
e2=errorbar([1 2 3],[nanmean(rmVal.NegMidS(ind)) nanmean(rmVal.NeuLowS(ind)) ...
    nanmean(rmVal.PosMidS(ind))],[sem(rmVal.NegMidS(ind)) sem(rmVal.NeuLowS(ind))...
    sem(rmVal.PosMidS(ind))],'LineWidth',lineWidth,'Color',socColor,'Marker','^',...
    'MarkerEdgeColor',socColor,'MarkerFaceColor',socColor,'DisplayName',...
    'Social Lower Arousal','LineStyle','--');
e3=errorbar([1 2 3],[nanmean(rmVal.NegHighN(ind)) nanmean(rmVal.NeuMidN(ind)) ...
    nanmean(rmVal.PosHighN(ind))],[sem(rmVal.NegHighN(ind)) sem(rmVal.NeuMidN(ind))...
    sem(rmVal.PosHighN(ind))],'LineWidth',lineWidth,'Color',nonSocColor,'Marker','o',...
    'MarkerEdgeColor',nonSocColor,'MarkerFaceColor',nonSocColor,'DisplayName',...
    'Nonsocial Higher Arousal');
e4=errorbar([1 2 3],[nanmean(rmVal.NegMidN(ind)) nanmean(rmVal.NeuLowN(ind)) ...
    nanmean(rmVal.PosMidN(ind))],[sem(rmVal.NegMidN(ind)) sem(rmVal.NeuLowN(ind))...
    sem(rmVal.PosMidN(ind))],'LineWidth',lineWidth,'Color',nonSocColor,'Marker','^',...
    'MarkerEdgeColor',nonSocColor,'MarkerFaceColor',nonSocColor,'DisplayName',...
    'Nonsocial Lower Arousal','LineStyle','--');
set(gca,'FontSize',fontSize,'LineWidth',lineWidth,'XTick',[1 2 3],'XTickLabel',valCat)
xlim([0 4]);ylim([1 9]);axis square; box on;l=legend([e1 e2 e3 e4]);
ylabel('Mean valence ratings');xlabel('Scene valence');title('Male Participants')

subplot(1,2,2);hold on;ind=rmVal.Gender=='2';
e1=errorbar([1 2 3],[nanmean(rmVal.NegHighS(ind)) nanmean(rmVal.NeuMidS(ind)) ...
    nanmean(rmVal.PosHighS(ind))],[sem(rmVal.NegHighS(ind)) sem(rmVal.NeuMidS(ind))...
    sem(rmVal.PosHighS(ind))],'LineWidth',lineWidth,'Color',socColor,'Marker','o',...
    'MarkerEdgeColor',socColor,'MarkerFaceColor',socColor,'DisplayName',...
    'Social Higher Arousal');hold on
e2=errorbar([1 2 3],[nanmean(rmVal.NegMidS(ind)) nanmean(rmVal.NeuLowS(ind)) ...
    nanmean(rmVal.PosMidS(ind))],[sem(rmVal.NegMidS(ind)) sem(rmVal.NeuLowS(ind)) ...
    sem(rmVal.PosMidS(ind))],'LineWidth',lineWidth,'Color',socColor,'Marker','^',...
    'MarkerEdgeColor',socColor,'MarkerFaceColor',socColor,'DisplayName',...
    'Social Lower Arousal','LineStyle','--');
e3=errorbar([1 2 3],[nanmean(rmVal.NegHighN(ind)) nanmean(rmVal.NeuMidN(ind)) ...
    nanmean(rmVal.PosHighN(ind))],[sem(rmVal.NegHighN(ind)) sem(rmVal.NeuMidN(ind)) ...
    sem(rmVal.PosHighN(ind))],'LineWidth',lineWidth,'Color',nonSocColor,'Marker','o',...
    'MarkerEdgeColor',nonSocColor,'MarkerFaceColor',nonSocColor,'DisplayName',...
    'Nonsocial Higher Arousal');
e4=errorbar([1 2 3],[nanmean(rmVal.NegMidN(ind)) nanmean(rmVal.NeuLowN(ind)) ...
    nanmean(rmVal.PosMidN(ind))],[sem(rmVal.NegMidN(ind)) sem(rmVal.NeuLowN(ind)) ...
    sem(rmVal.PosMidN(ind))],'LineWidth',lineWidth,'Color',nonSocColor,'Marker','^',...
    'MarkerEdgeColor',nonSocColor,'MarkerFaceColor',nonSocColor,'DisplayName',...
    'Nonsocial Lower Arousal','LineStyle','--');
set(gca,'FontSize',fontSize,'LineWidth',lineWidth,'XTick',[1 2 3],'XTickLabel',valCat)
xlim([0 4]);ylim([1 9]);axis square; box on;l=legend([e1 e2 e3 e4]);
ylabel('Mean valence ratings');xlabel('Scene valence');title('Female Participants')

figure('color','w');
subplot(1,2,1);hold on;ind=rmArous.Gender=='1';
e1=errorbar([1 2 3],[nanmean(rmArous.NegHighS(ind)) nanmean(rmArous.NeuMidS(ind)) ...
    nanmean(rmArous.PosHighS(ind))],[sem(rmArous.NegHighS(ind)) sem(rmArous.NeuMidS(ind))...
    sem(rmArous.PosHighS(ind))],'LineWidth',lineWidth,'Color',socColor,'Marker','o',...
    'MarkerEdgeColor',socColor,'MarkerFaceColor',socColor,'DisplayName','Social Higher Arousal');
e2=errorbar([1 2 3],[nanmean(rmArous.NegMidS(ind)) nanmean(rmArous.NeuLowS(ind)) ...
    nanmean(rmArous.PosMidS(ind))],[sem(rmArous.NegMidS(ind)) sem(rmArous.NeuLowS(ind))...
    sem(rmArous.PosMidS(ind))],'LineWidth',lineWidth,'Color',socColor,'Marker','^',...
    'MarkerEdgeColor',socColor,'MarkerFaceColor',socColor,'DisplayName',...
    'Social Lower Arousal','LineStyle','--');
e3=errorbar([1 2 3],[nanmean(rmArous.NegHighN(ind)) nanmean(rmArous.NeuMidN(ind)) ...
    nanmean(rmArous.PosHighN(ind))],[sem(rmArous.NegHighN(ind)) sem(rmArous.NeuMidN(ind)) ...
    sem(rmArous.PosHighN(ind))],'LineWidth',lineWidth,'Color',nonSocColor,'Marker','o',...
    'MarkerEdgeColor',nonSocColor,'MarkerFaceColor',nonSocColor,'DisplayName',...
    'Nonsocial Higher Arousal');
e4=errorbar([1 2 3],[nanmean(rmArous.NegMidN(ind)) nanmean(rmArous.NeuLowN(ind)) ...
    nanmean(rmArous.PosMidN(ind))],[sem(rmArous.NegMidN(ind)) sem(rmArous.NeuLowN(ind))...
    sem(rmArous.PosMidN(ind))],'LineWidth',lineWidth,'Color',nonSocColor,'Marker','^',...
    'MarkerEdgeColor',nonSocColor,'MarkerFaceColor',nonSocColor,'DisplayName',...
    'Nonsocial Lower Arousal','LineStyle','--');
set(gca,'FontSize',fontSize,'LineWidth',lineWidth,'XTick',[1 2 3],'XTickLabel',valCat)
xlim([0 4]);ylim([1 9]);axis square; box on;l=legend([e1 e2 e3 e4]);
ylabel('Mean arousal ratings');xlabel('Scene valence');title('Male Participants')

subplot(1,2,2);hold on;ind=rmArous.Gender=='2';
e1=errorbar([1 2 3],[nanmean(rmArous.NegHighS(ind)) nanmean(rmArous.NeuMidS(ind)) ...
    nanmean(rmArous.PosHighS(ind))],[sem(rmArous.NegHighS(ind)) sem(rmArous.NeuMidS(ind)) ...
    sem(rmArous.PosHighS(ind))],'LineWidth',lineWidth,'Color',socColor,'Marker','o',...
    'MarkerEdgeColor',socColor,'MarkerFaceColor',socColor,'DisplayName',...
   'Social Higher Arousal');
e2=errorbar([1 2 3],[nanmean(rmArous.NegMidS(ind)) nanmean(rmArous.NeuLowS(ind)) ...
    nanmean(rmArous.PosMidS(ind))],[sem(rmArous.NegMidS(ind)) sem(rmArous.NeuLowS(ind))...
    sem(rmArous.PosMidS(ind))],'LineWidth',lineWidth,'Color',socColor,'Marker','^',...
    'MarkerEdgeColor',socColor,'MarkerFaceColor',socColor,'DisplayName',...
    'Social Lower Arousal','LineStyle','--');
e3=errorbar([1 2 3],[nanmean(rmArous.NegHighN(ind)) nanmean(rmArous.NeuMidN(ind)) ...
    nanmean(rmArous.PosHighN(ind))],[sem(rmArous.NegHighN(ind)) sem(rmArous.NeuMidN(ind)) ...
    sem(rmArous.PosHighN(ind))],'LineWidth',lineWidth,'Color',nonSocColor,'Marker','o',...
    'MarkerEdgeColor',nonSocColor,'MarkerFaceColor',nonSocColor,'DisplayName',...
    'Nonsocial Higher Arousal');
e4=errorbar([1 2 3],[nanmean(rmArous.NegMidN(ind)) nanmean(rmArous.NeuLowN(ind)) ...
    nanmean(rmArous.PosMidN(ind))],[sem(rmArous.NegMidN(ind)) sem(rmArous.NeuLowN(ind))...
    sem(rmArous.PosMidN(ind))],'LineWidth',lineWidth,'Color',nonSocColor,'Marker','^',...
    'MarkerEdgeColor',nonSocColor,'MarkerFaceColor',nonSocColor,'DisplayName',...
    'Nonsocial Lower Arousal','LineStyle','--');
set(gca,'FontSize',fontSize,'LineWidth',lineWidth,'XTick',[1 2 3],'XTickLabel',valCat)
xlim([0 4]);ylim([1 9]);axis square; box on;l=legend([e1 e2 e3 e4]);
ylabel('Mean arousal ratings');xlabel('Scene valence');title('Female Participants')

%% Gender differences in valence and arousal ratings by scene content.

fprintf('Scene content: Scantily dressed women\n')
corrAlpha=0.05/300; % Bonferroni-corrected alpha
ind1 = strcmp(sceneInfo.Gender,'female') | strcmp(sceneInfo.Gender,'both');
ind2 = strcmp(sceneInfo.Valence,'Positive') | strcmp(sceneInfo.Valence,'Neutral');
ind3 = genderDiff.ValSexPval<corrAlpha & genderDiff.ValSexD > 0;
ind4 = ~strcmp(sceneInfo.ImageFile,'scene2234r.jpg') & ...
    ~strcmp(sceneInfo.ImageFile,'scene8137.jpg');ind=ind1.*ind2.*ind3.*ind4;

valM=valRatings(valRatings_table.Gender=='1',logical(ind));
valW=valRatings(valRatings_table.Gender=='2',logical(ind));
arousM=arousRatings(arousRatings_table.Gender=='1',logical(ind));
arousW=arousRatings(arousRatings_table.Gender=='2',logical(ind));

fprintf('Valence Men M = %.2f, SD = %.2f; Women M = %.2f, SD = %.2f \n',...
    nanmean(nanmean(valM,2)),nanstd(nanmean(valM,2)),...
    nanmean(nanmean(valW,2)),nanstd(nanmean(valW,2)))
fprintf('Arousal Men M = %.2f, SD = %.2f; Women M = %.2f, SD = %.2f \n',...
    nanmean(nanmean(arousM,2)),nanstd(nanmean(arousM,2)),...
    nanmean(nanmean(arousW,2)),nanstd(nanmean(arousW,2)))

fprintf('Valence ratings\n')
[~,p,~,stats]=ttest2(nanmean(valM,2),nanmean(valW,2));
d=cohensD(nanmean(valM,2),nanmean(valW,2));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d);
fprintf('Arousal ratings\n')
[~,p,~,stats]=ttest2(nanmean(arousM,2),nanmean(arousW,2));
d=cohensD(nanmean(arousM,2),nanmean(arousW,2));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n\n',stats.df,stats.tstat,p,d);


fprintf('Scene content: Scantily dressed men\n')
ind1 = strcmp(sceneInfo.Gender,'male') | strcmp(sceneInfo.Gender,'both');
ind2 = strcmp(sceneInfo.Valence,'Positive') | strcmp(sceneInfo.Valence,'Neutral');
ind3 = genderDiff.ValSexPval<corrAlpha & genderDiff.ValSexD < 0;
ind4 = ~strcmp(sceneInfo.ImageFile,'scene296.jpg') & ~strcmp(sceneInfo.ImageFile,'scene266.jpg')...
    & ~strcmp(sceneInfo.ImageFile,'scene1154.jpg') & ~strcmp(sceneInfo.ImageFile,'scene2189r.jpg')...
    & ~strcmp(sceneInfo.ImageFile,'scene2225r.jpg');ind=ind1.*ind2.*ind3.*ind4;

valM=valRatings(valRatings_table.Gender=='1',logical(ind));
valW=valRatings(valRatings_table.Gender=='2',logical(ind));
arousM=arousRatings(arousRatings_table.Gender=='1',logical(ind));
arousW=arousRatings(arousRatings_table.Gender=='2',logical(ind));

fprintf('Valence Men M = %.2f, SD = %.2f; Women M = %.2f, SD = %.2f \n',...
    nanmean(nanmean(valM,2)),nanstd(nanmean(valM,2)),...
    nanmean(nanmean(valW,2)),nanstd(nanmean(valW,2)))
fprintf('Arousal Men M = %.2f, SD = %.2f; Women M = %.2f, SD = %.2f \n\n',...
    nanmean(nanmean(arousM,2)),nanstd(nanmean(arousM,2)),...
    nanmean(nanmean(arousW,2)),nanstd(nanmean(arousW,2)))

fprintf('Valence ratings\n')
[~,p,~,stats]=ttest2(nanmean(valM,2),nanmean(valW,2));
d=cohensD(nanmean(valM,2),nanmean(valW,2));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d);
fprintf('Arousal ratings\n')
[~,p,~,stats]=ttest2(nanmean(arousM,2),nanmean(arousW,2));
d=cohensD(nanmean(arousM,2),nanmean(arousW,2));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n\n',stats.df,stats.tstat,p,d);


fprintf('Scene content: Children & animals\n')
ind1 = strcmp(sceneInfo.Children,'yes') | strcmp(sceneInfo.Animal,'nonthreatening');
ind2 = strcmp(sceneInfo.Valence,'Positive') | strcmp(sceneInfo.Valence,'Neutral');
ind3 = genderDiff.ValSexPval<corrAlpha & genderDiff.ValSexD < 0; ind=ind1.*ind2.*ind3;
valM=valRatings(valRatings_table.Gender=='1',logical(ind));
valW=valRatings(valRatings_table.Gender=='2',logical(ind));
arousM=arousRatings(arousRatings_table.Gender=='1',logical(ind));
arousW=arousRatings(arousRatings_table.Gender=='2',logical(ind));

fprintf('Valence Men M = %.2f, SD = %.2f; Women M = %.2f, SD = %.2f \n',...
    nanmean(nanmean(valM,2)),nanstd(nanmean(valM,2)),...
    nanmean(nanmean(valW,2)),nanstd(nanmean(valW,2)))
fprintf('Arousal Men M = %.2f, SD = %.2f; Women M = %.2f, SD = %.2f \n\n',...
    nanmean(nanmean(arousM,2)),nanstd(nanmean(arousM,2)),...
    nanmean(nanmean(arousW,2)),nanstd(nanmean(arousW,2)))

fprintf('Valence ratings\n')
[~,p,~,stats]=ttest2(nanmean(valM,2),nanmean(valW,2));
d=cohensD(nanmean(valM,2),nanmean(valW,2));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d);
fprintf('Arousal ratings\n')
[~,p,~,stats]=ttest2(nanmean(arousM,2),nanmean(arousW,2));
d=cohensD(nanmean(arousM,2),nanmean(arousW,2));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n\n',stats.df,stats.tstat,p,d);


fprintf('Scene content: High-arousal unpleasant scenes\n')
ind1 = strcmp(sceneInfo.Arousal,'High') | strcmp(sceneInfo.Arousal,'Mid');
ind2 = strcmp(sceneInfo.Valence,'Negative');
ind3 = genderDiff.ValSexPval<corrAlpha & genderDiff.ValSexD > 0;ind=ind1.*ind2.*ind3;
valM=valRatings(valRatings_table.Gender=='1',logical(ind));
valW=valRatings(valRatings_table.Gender=='2',logical(ind));
arousM=arousRatings(arousRatings_table.Gender=='1',logical(ind));
arousW=arousRatings(arousRatings_table.Gender=='2',logical(ind));

fprintf('Valence Men M = %.2f, SD = %.2f; Women M = %.2f, SD = %.2f \n',...
    nanmean(nanmean(valM,2)),nanstd(nanmean(valM,2)),...
    nanmean(nanmean(valW,2)),nanstd(nanmean(valW,2)))
fprintf('Arousal Men M = %.2f, SD = %.2f; Women M = %.2f, SD = %.2f \n\n',...
    nanmean(nanmean(arousM,2)),nanstd(nanmean(arousM,2)),...
    nanmean(nanmean(arousW,2)),nanstd(nanmean(arousW,2)))

fprintf('Valence ratings\n')
[~,p,~,stats]=ttest2(nanmean(valM,2),nanmean(valW,2));
d=cohensD(nanmean(valM,2),nanmean(valW,2));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d);
fprintf('Arousal ratings\n')
[~,p,~,stats]=ttest2(nanmean(arousM,2),nanmean(arousW,2));
d=cohensD(nanmean(arousM,2),nanmean(arousW,2));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n\n',stats.df,stats.tstat,p,d);

%% Make Table S2.
% Gender differences in valence and arousal ratings by affective category.

% Valence x Arousal x Social Content
vars=rmVal.Properties.VariableNames;
fprintf('Valence ratings\n\n')
for ii=2:13
    [~,p,~,stats]=ttest2(rmVal.(vars{ii})(rmVal.Gender=='1'),...
        rmVal.(vars{ii})(rmVal.Gender=='2'));
    d=cohensD(rmVal.(vars{ii})(rmVal.Gender=='1'),rmVal.(vars{ii})(rmVal.Gender=='2'));
    fprintf('%s t(%d)=%.2f, p=%.3f, d=%.3f \n',vars{ii},stats.df,stats.tstat,p,d)
end

fprintf('\nArousal ratings\n\n')
for ii=2:13
    [~,p,~,stats]=ttest2(rmArous.(vars{ii})(rmArous.Gender=='1'),...
        rmArous.(vars{ii})(rmArous.Gender=='2'));
    d=cohensD(rmArous.(vars{ii})(rmArous.Gender=='1'),rmArous.(vars{ii})(rmArous.Gender=='2'));
    fprintf('%s t(%d)=%.2f, p=%.3f, d=%.3f \n',vars{ii},stats.df,stats.tstat,p,d)
end

% Valence x Arousal (Valence ratings)
fprintf('\nValence ratings\n')
NegHigh=nanmean([rmVal.NegHighS rmVal.NegHighN],2);
NegMid=nanmean([rmVal.NegMidN rmVal.NegMidS],2);
NeuLow=nanmean([rmVal.NeuLowN rmVal.NeuLowS],2);
NeuMid=nanmean([rmVal.NeuMidN rmVal.NeuMidS],2);
PosHigh=nanmean([rmVal.PosHighN rmVal.PosHighS],2);
PosMid=nanmean([rmVal.PosMidN rmVal.PosMidS],2);

fprintf('\nNegHigh\n')
[~,p,~,stats]=ttest2(NegHigh(rmVal.Gender=='1'),NegHigh(rmVal.Gender=='2'));
d=cohensD(NegHigh(rmVal.Gender=='1'),NegHigh(rmVal.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nNegMid\n')
[~,p,~,stats]=ttest2(NegMid(rmVal.Gender=='1'),NegMid(rmVal.Gender=='2'));
d=cohensD(NegMid(rmVal.Gender=='1'),NegMid(rmVal.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nNeuLow\n')
[~,p,~,stats]=ttest2(NeuLow(rmVal.Gender=='1'),NeuLow(rmVal.Gender=='2'));
d=cohensD(NeuLow(rmVal.Gender=='1'),NeuLow(rmVal.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nNeuMid\n')
[~,p,~,stats]=ttest2(NeuMid(rmVal.Gender=='1'),NeuMid(rmVal.Gender=='2'));
d=cohensD(NeuMid(rmVal.Gender=='1'),NeuMid(rmVal.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nPosHigh\n')
[~,p,~,stats]=ttest2(PosHigh(rmVal.Gender=='1'),PosHigh(rmVal.Gender=='2'));
d=cohensD(PosHigh(rmVal.Gender=='1'),PosHigh(rmVal.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nPosMid\n')
[~,p,~,stats]=ttest2(PosMid(rmVal.Gender=='1'),PosMid(rmVal.Gender=='2'));
d=cohensD(PosMid(rmVal.Gender=='1'),PosMid(rmVal.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)

% Valence x Arousal (Arousal ratings)

fprintf('\nArousal ratings\n')
NegHigh=nanmean([rmArous.NegHighS rmArous.NegHighN],2);
NegMid=nanmean([rmArous.NegMidN rmArous.NegMidS],2);
NeuLow=nanmean([rmArous.NeuLowN rmArous.NeuLowS],2);
NeuMid=nanmean([rmArous.NeuMidN rmArous.NeuMidS],2);
PosHigh=nanmean([rmArous.PosHighN rmArous.PosHighS],2);
PosMid=nanmean([rmArous.PosMidN rmArous.PosMidS],2);

fprintf('\nNegHigh\n')
[~,p,~,stats]=ttest2(NegHigh(rmArous.Gender=='1'),NegHigh(rmArous.Gender=='2'));
d=cohensD(NegHigh(rmArous.Gender=='1'),NegHigh(rmArous.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nNegMid\n')
[~,p,~,stats]=ttest2(NegMid(rmArous.Gender=='1'),NegMid(rmArous.Gender=='2'));
d=cohensD(NegMid(rmArous.Gender=='1'),NegMid(rmArous.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nNeuLow\n')
[~,p,~,stats]=ttest2(NeuLow(rmArous.Gender=='1'),NeuLow(rmArous.Gender=='2'));
d=cohensD(NeuLow(rmArous.Gender=='1'),NeuLow(rmArous.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nNeuMid\n')
[~,p,~,stats]=ttest2(NeuMid(rmArous.Gender=='1'),NeuMid(rmArous.Gender=='2'));
d=cohensD(NeuMid(rmArous.Gender=='1'),NeuMid(rmArous.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nPosHigh\n')
[~,p,~,stats]=ttest2(PosHigh(rmArous.Gender=='1'),PosHigh(rmArous.Gender=='2'));
d=cohensD(PosHigh(rmArous.Gender=='1'),PosHigh(rmArous.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nPosMid\n')
[~,p,~,stats]=ttest2(PosMid(rmArous.Gender=='1'),PosMid(rmArous.Gender=='2'));
d=cohensD(PosMid(rmArous.Gender=='1'),PosMid(rmArous.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)

% Valence x Social Content (Valence ratings)

fprintf('\nValence ratings\n')
NegS=nanmean([rmVal.NegHighS rmVal.NegMidS],2);
NegN=nanmean([rmVal.NegMidN rmVal.NegHighN],2);
NeuS=nanmean([rmVal.NeuMidS rmVal.NeuLowS],2);
NeuN=nanmean([rmVal.NeuMidN rmVal.NeuLowN],2);
PosS=nanmean([rmVal.PosMidS rmVal.PosHighS],2);
PosN=nanmean([rmVal.PosMidN rmVal.PosHighN],2);

fprintf('\nNegSocial\n')
[~,p,~,stats]=ttest2(NegS(rmVal.Gender=='1'),NegS(rmVal.Gender=='2'));
d=cohensD(NegS(rmVal.Gender=='1'),NegS(rmVal.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nNegNonsocial\n')
[~,p,~,stats]=ttest2(NegN(rmVal.Gender=='1'),NegN(rmVal.Gender=='2'));
d=cohensD(NegN(rmVal.Gender=='1'),NegN(rmVal.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nNeuSocial\n')
[~,p,~,stats]=ttest2(NeuS(rmVal.Gender=='1'),NeuS(rmVal.Gender=='2'));
d=cohensD(NeuS(rmVal.Gender=='1'),NeuS(rmVal.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nNeuNonsocial\n')
[~,p,~,stats]=ttest2(NeuN(rmVal.Gender=='1'),NeuN(rmVal.Gender=='2'));
d=cohensD(NeuN(rmVal.Gender=='1'),NeuN(rmVal.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nPosSocial\n')
[~,p,~,stats]=ttest2(PosS(rmVal.Gender=='1'),PosS(rmVal.Gender=='2'));
d=cohensD(PosS(rmVal.Gender=='1'),PosS(rmVal.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nPosNonsocial\n')
[~,p,~,stats]=ttest2(PosN(rmVal.Gender=='1'),PosN(rmVal.Gender=='2'));
d=cohensD(PosN(rmVal.Gender=='1'),PosN(rmVal.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)

% Valence x Social Content (Arousal ratings)

fprintf('\nArousal ratings\n')
NegS=nanmean([rmArous.NegHighS rmArous.NegMidS],2);
NegN=nanmean([rmArous.NegMidN rmArous.NegHighN],2);
NeuS=nanmean([rmArous.NeuMidS rmArous.NeuLowS],2);
NeuN=nanmean([rmArous.NeuMidN rmArous.NeuLowN],2);
PosS=nanmean([rmArous.PosMidS rmArous.PosHighS],2);
PosN=nanmean([rmArous.PosMidN rmArous.PosHighN],2);

fprintf('\nNegSocial\n')
[~,p,~,stats]=ttest2(NegS(rmArous.Gender=='1'),NegS(rmArous.Gender=='2'));
d=cohensD(NegS(rmArous.Gender=='1'),NegS(rmArous.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nNegNonsocial\n')
[~,p,~,stats]=ttest2(NegN(rmArous.Gender=='1'),NegN(rmArous.Gender=='2'));
d=cohensD(NegN(rmArous.Gender=='1'),NegN(rmArous.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nNeuSocial\n')
[~,p,~,stats]=ttest2(NeuS(rmArous.Gender=='1'),NeuS(rmArous.Gender=='2'));
d=cohensD(NeuS(rmArous.Gender=='1'),NeuS(rmArous.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nNeuNonsocial\n')
[~,p,~,stats]=ttest2(NeuN(rmArous.Gender=='1'),NeuN(rmArous.Gender=='2'));
d=cohensD(NeuN(rmArous.Gender=='1'),NeuN(rmArous.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nPosSocial\n')
[~,p,~,stats]=ttest2(PosS(rmArous.Gender=='1'),PosS(rmArous.Gender=='2'));
d=cohensD(PosS(rmArous.Gender=='1'),PosS(rmArous.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nPosNonsocial\n')
[~,p,~,stats]=ttest2(PosN(rmArous.Gender=='1'),PosN(rmArous.Gender=='2'));
d=cohensD(PosN(rmArous.Gender=='1'),PosN(rmArous.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)

% Social Content

fprintf('\nValence ratings\n')
soc=nanmean([rmVal.NegHighS rmVal.NegMidS rmVal.NeuMidS rmVal.NeuLowS ...
    rmVal.PosMidS rmVal.PosHighS],2);
nonsoc=nanmean([rmVal.NegMidN rmVal.NegHighN rmVal.NeuMidN rmVal.NeuLowN ...
    rmVal.PosMidN rmVal.PosHighN],2);

fprintf('\nSocial\n')
[~,p,~,stats]=ttest2(soc(rmVal.Gender=='1'),soc(rmVal.Gender=='2'));
d=cohensD(soc(rmVal.Gender=='1'),soc(rmVal.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nNonsocial\n')
[~,p,~,stats]=ttest2(nonsoc(rmVal.Gender=='1'),nonsoc(rmVal.Gender=='2'));
d=cohensD(nonsoc(rmVal.Gender=='1'),nonsoc(rmVal.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)

fprintf('\nArousal ratings\n')
soc=nanmean([rmArous.NegHighS rmArous.NegMidS rmArous.NeuMidS rmArous.NeuLowS ...
    rmArous.PosMidS rmArous.PosHighS],2);
nonsoc=nanmean([rmArous.NegMidN rmArous.NegHighN rmArous.NeuMidN rmArous.NeuLowN ...
    rmArous.PosMidN rmArous.PosHighN],2);

fprintf('\nSocial\n')
[~,p,~,stats]=ttest2(soc(rmArous.Gender=='1'),soc(rmArous.Gender=='2'));
d=cohensD(soc(rmArous.Gender=='1'),soc(rmArous.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nNonsocial\n')
[~,p,~,stats]=ttest2(nonsoc(rmArous.Gender=='1'),nonsoc(rmArous.Gender=='2'));
d=cohensD(nonsoc(rmArous.Gender=='1'),nonsoc(rmArous.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)

% Valence

fprintf('\nValence ratings\n')
Neg=nanmean([rmVal.NegHighS rmVal.NegMidS rmVal.NegMidN rmVal.NegHighN],2);
Neu=nanmean([rmVal.NeuMidS rmVal.NeuLowS rmVal.NeuMidN rmVal.NeuLowN],2);
Pos=nanmean([rmVal.PosMidS rmVal.PosHighS rmVal.PosMidN rmVal.PosHighN],2);

fprintf('\nNeg\n')
[~,p,~,stats]=ttest2(Neg(rmVal.Gender=='1'),Neg(rmVal.Gender=='2'));
d=cohensD(Neg(rmVal.Gender=='1'),Neg(rmVal.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nNeu\n')
[~,p,~,stats]=ttest2(Neu(rmVal.Gender=='1'),Neu(rmVal.Gender=='2'));
d=cohensD(Neu(rmVal.Gender=='1'),Neu(rmVal.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nPos\n')
[~,p,~,stats]=ttest2(Pos(rmVal.Gender=='1'),Pos(rmVal.Gender=='2'));
d=cohensD(Pos(rmVal.Gender=='1'),Pos(rmVal.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)

fprintf('\nArousal ratings\n')
Neg=nanmean([rmArous.NegHighS rmArous.NegMidS rmArous.NegMidN rmArous.NegHighN],2);
Neu=nanmean([rmArous.NeuMidS rmArous.NeuLowS rmArous.NeuMidN rmArous.NeuLowN],2);
Pos=nanmean([rmArous.PosMidS rmArous.PosHighS rmArous.PosMidN rmArous.PosHighN],2);

fprintf('\nNeg\n')
[~,p,~,stats]=ttest2(Neg(rmArous.Gender=='1'),Neg(rmArous.Gender=='2'));
d=cohensD(Neg(rmArous.Gender=='1'),Neg(rmArous.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nNeu\n')
[~,p,~,stats]=ttest2(Neu(rmArous.Gender=='1'),Neu(rmArous.Gender=='2'));
d=cohensD(Neu(rmArous.Gender=='1'),Neu(rmArous.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
fprintf('\nPos\n')
[~,p,~,stats]=ttest2(Pos(rmArous.Gender=='1'),Pos(rmArous.Gender=='2'));
d=cohensD(Pos(rmArous.Gender=='1'),Pos(rmArous.Gender=='2'));
fprintf('t(%d)=%.2f, p=%.3f, d=%.3f \n',stats.df,stats.tstat,p,d)
