Friday, January 10, 2014

Calculating effect sizes using the compute.es mes() function

I wanted to make a table of effect sizes for a series of comparisons among three groups.  I use the package compute.es to do this. If you have a lot of comparisons, it'd probably be easier to do a loop, but this is what I have for now.  Of course you can modify this so you are only comparing two groups as well, or compare more than three groups.




library(compute.es)

#Sample data on which to test the code.

group1<-c(0,1,2,2,3,5,2)
group2<-c(2,4,6,5,7,8,9)
group3<-c(2,3,4,5,6,7,8)

#Calculate the necessary mean, standard deviation, and sample size for all three datasets.
#You could have your data in columns, too; this is just how I set up the sample data.

m1<-mean(group1)
sd1<-sd(
group1)
l1<-length(
group1)

m2<-mean(group2)
sd2<-sd(
group2)
l2<-length(
group2)

m3<-mean(group3)
sd3<-sd(
group3)
l3<-length(
group3


#The objects you've created will be used as follows:
#mes(meanA, meanB, standarddeviationA, standarddeviationB, samplesizeA, samplesizeB)

mes(m1,m2,sd1,sd2,l1,l2) #compares data1 and data2
mes(m1,m3,sd1,sd3,l1,l3) #compares data1 and data3
mes(m2,m3,sd2,sd3,l2,l3) #compares data2 and data3

Results for the last comparision (2 vs. 3) look like this:


    EFFECT SIZE CALCULATION (FOR SINGLE INPUT)

Mean Differences ES: 
 
 d [ 95 %CI] = 0.37 [ -0.8 , 1.55 ] 
  var(d) = 0.29 
  p-value(d) = 0.5 
  U3(d) = 64.6 % 
  CLES(d) = 60.44 % 
  Cliff's Delta = 0.21 
 
 g [ 95 %CI] = 0.35 [ -0.75 , 1.45 ] 
  var(g) = 0.25 
  p-value(g) = 0.5 
  U3(g) = 63.71 % 
  CLES(g) = 59.79 % 
 
 Correlation ES: 
 
 r [ 95 %CI] = 0.18 [ -0.44 , 0.69 ] 
  var(r) = 0.07 
  p-value(r) = 0.55 
 
 z [ 95 %CI] = 0.19 [ -0.47 , 0.84 ] 
  var(z) = 0.09 
  p-value(z) = 0.55 
 
 Odds Ratio ES: 
 
 OR [ 95 %CI] = 1.97 [ 0.23 , 16.61 ] 
  p-value(OR) = 0.5 
 
 Log OR [ 95 %CI] = 0.68 [ -1.45 , 2.81 ] 
  var(lOR) = 0.96 
  p-value(Log OR) = 0.5 
 
 Other: 
 
 NNT = 4.79 
 Total N = 14
 



For my application, I used Cohen's d (the first entry, highlighted in bold above).  For additional information on effect sizes (not just Cohen's d), Cohen (1992) is a very useful reference.

No comments:

Post a Comment

Comments and suggestions welcome.