function [Emean,SE,Elow,Eup,Qw,df,P]=mean_effect(R,SV);
% [Emean,Elow,Eup]=mean_effect(R,W)
% returns the weighted mean effect size Emean and its 95% confidence limits
% [Elow,Eup], where the weights include the among-study variance if it is
% significant at P<0.05;
% Inputs: R = effect sizes from individual studies; SV = sampling
% variances of effect sizes.
W=1./SV; % weights are inverse of sampling variance
SW = sum(W); % sum of weights
df = length(R)-1;
Qw = Q(R,W); % homogeneity statistic - weighted sum of squares
P = 1 - chi2cdf(Qw,df); % prob. of seeing Qw if group is homogeneous
if P<.05
S2b = ( Qw - df )/(SW - W'*W/SW); % between-study variance
W = ( W.^-1 + S2b ).^-1; % change weights to include between-study variance
SW = sum(W);
end
Emean = R'*W/SW; % mean effect size
SE = SW^-.5; % standard error of Emean
Elow = Emean - 1.96*SE; % lower confidence limit
Eup = Emean + 1.96*SE; % upper confidence limit