##### Citations
Title Text Both

## Effect size for comparison of 2 numeric groups

There is increasing emphasis on effect size recently. This is because P value only indicates whether difference between 2 groups is likely to be by chance or not. Hence, even small difference can also have highly significant P value when the sample size is very large. The effect size, on the other hand, indicates how large is the difference between 2 groups, considering the variation in 2 groups. Most commonly used effect size is Cohen's D, which is absolute difference in the means divided by pooled standard deviation. Following functions can be used to calculate Cohen's D:

Code:

> cohens_d = function(x, y) {
lx <- length(x)
ly <- length(y)
return(cohens_d_means(mean(x), mean(y), sd(x), sd(y), lx, ly))
}

> cohens_d_means = function(m1,m2, s1, s2, n1, n2) {
lx <- n1- 1
ly <- n2- 1
md  <- abs(m1-m2)
csd <- lx * s1^2 + ly * s2^2
csd <- csd/(lx + ly)
csd <- sqrt(csd)

cd  <- md/csd
cd
}

> cohens_d_numfac = function(vnum, vfac){
if(length(levels(vfac))>2) cat('\nOnly difference between first 2 levels will be tested.\n')
dd = data.frame(vnum, vfac)
out = split(vnum, vfac)
cohens_d(out[[1]], out[[2]])
}

In our case:

> with(bwdf, cohens_d_numfac(age, low))
[1] 0.2571421

Cohen's D values of 0.33 to 0.66 are generally considered moderately large. Smaller values indicate small effect size (as in our example), while larger values indicate large effect sizes.