Reputation: 1651
I get the below error when trying to compute effect size using cohen.d function in psych. Please see example data below.
library(psych)
x <- c(1, 2, 3, 4, 5, 6, 7, 8)
y <- c(1, 1, 1, 1, 2, 2, 2, 2)
xy <- data.frame(x,y)
names(xy) <- c("x", "group")
CohensD <- cohen.d(xy, "group", alpha=.05)
Error in .rowNamesDF<-
(x, value = value) : invalid 'row.names' length
Upvotes: 1
Views: 1669
Reputation: 9
You should use the effsize package, instead of psych.
install.packages("effsize")
library(effsize)
Then use the cohen.d of the effsize.
x <- c(1, 2, 3, 4, 5, 6, 7, 8)
y <- c(1, 1, 1, 1, 2, 2, 2, 2)
cohen.d(x,y)
Upvotes: -1
Reputation: 1230
That is indeed a bug that I introduced when adding Mahalabonis distances to cohen.d. The fix is available in psych_1.9.12.21 which is available on my server. You can install it from there:
install.packages("psych",repos="http://personality-project.org/r",type="source")
I will release this patched version to CRAN once it comes back up next week. In the interim, if you don't want the patched version, just use a data set with more than two columns (as pointed out by A. Suliman).
Upvotes: 1
Reputation: 13125
Probably there is a bug as it works fine in 1.8.12
, also it generates the same error with
cohen.d(sat.act[1:8, c('education','gender')], "gender")
but not with
cohen.d(sat.act[1:8, c('education','gender','age')], "gender")
So, should work fine with a data frame has more than two columns
x <- c(1, 2, 3, 4, 5, 6, 7, 8)
y <- c(1, 1, 1, 1, 2, 2, 2, 2)
xy <- data.frame(x=x, group=y, z=rnorm(8))
cohen.d(xy, "group")
Call: cohen.d(x = xy, group = "group")
Cohen d statistic of difference between two means
lower effect upper
x 0.53 3.58 6.60
z -0.71 0.88 2.37
Multivariate (Mahalanobis) distance between groups
[1] 3.6
r equivalent of difference between two means
x z
0.87 0.40
Upvotes: 2