Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cohen.d gives wrong value when data is not arranged by f #27

Closed
juyujeng opened this issue Sep 9, 2018 · 4 comments
Closed

Cohen.d gives wrong value when data is not arranged by f #27

juyujeng opened this issue Sep 9, 2018 · 4 comments
Assignees
Labels

Comments

@juyujeng
Copy link

juyujeng commented Sep 9, 2018

when using cohen.d(d ~ f, data)
if data is not arranged by the f, it might give a wrong value of Cohen'd

@juyujeng juyujeng changed the title Cohen.d gives wrong value when data is not sorted by f Cohen.d gives wrong value when data is not arranged by f Sep 9, 2018
@mtorchiano
Copy link
Owner

I'm, not sure I understand you issue, could you please post a minimal working example?

@juyujeng
Copy link
Author

Sorry I didn't make my question more clear.
Here is my exmaple scripts.

I found that this problem happens when unequal sample sizes of the two groups.

library(effsize)
d.data <- data.frame(group = sample(c(1,2), 60, replace = T, prob = c(.33,.67)),
                     value = rnorm(60,100,15))
group1 <- d.data$value[d.data$group==1]
group2 <- d.data$value[d.data$group==2]
# the results of these two line bellow are different
cohen.d(value ~ group, d.data)
cohen.d(group1, group2)

d.data.arranged <- d.data[order(d.data$group),]
# after arranged, the results of these two lines bellow are the same
cohen.d(value ~ group, d.data.arranged)
cohen.d(group1, group2)

@mtorchiano
Copy link
Owner

Thanks, I'll try to have a look at it as soon as I have some spare time

@mtorchiano mtorchiano self-assigned this Sep 17, 2018
@mtorchiano mtorchiano added the bug label Sep 17, 2018
mtorchiano added a commit that referenced this issue Nov 6, 2018
- cohen.d was using `unique` instead of `levels` therefore a different orded of the factor vector could return a different effect size
@mtorchiano
Copy link
Owner

Issue resolved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants