title: Sign of Cohen's d is unaffected by reversing order of factor levels in R
body: <p>I'm using Cohen's d (implemented using <code>cohen.d()</code> from the <code>effsize</code> package) as a measure of effect size in my dependent variable between two levels of a factor. </p>
  
  <p>My code looks like this: <code>cohen.d(d, f)</code> where <code>d</code> is a vector of numeric values and <code>f</code> is a factor with two levels: "A" and "B".</p>
  
  <p>Based on my understanding, the sign of Cohen's d is dependent on the order of means (i.e. factor levels) entered into the formula. However, my <code>cohen.d()</code> command returns a negative value (and negative CIs), even if I reverse the order of levels in <code>f</code>.</p>
  
  <p>Here is a reproducible example:</p>
  
  <pre><code>library('effsize')
  # Load in Chickweight data
  a=ChickWeight
  
  # Cohens d requires two levels in factor f, so take the first two available in Diet
  a=a[a$Diet==c(1,2),]
  a$Diet=a$Diet[ , drop=T]
  
  # Compute cohen's d with default order of Diet
  d1 = a$weight
  f1 = a$Diet
  cohen1 = cohen.d(d1,f1)
  
  # Re-order levels of Diet
  a$Diet = relevel(a$Diet, ref=2)
  
  # Re-compute cohen's d
  d2 = a$weight
  f2 = a$Diet
  cohen2 = cohen.d(d2,f2)
  
  # Compare values
  cohen1
  cohen2 
  </code></pre>
  
  <p>Can anyone explain why this is the case, and/or if I'm doing something wrong?</p>
  
  <p>Thanks in advance for any advice!</p>