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

0 proportion showing up as NA in props() with df_stats() #11

Open
rpruim opened this issue Feb 20, 2018 · 5 comments
Open

0 proportion showing up as NA in props() with df_stats() #11

rpruim opened this issue Feb 20, 2018 · 5 comments

Comments

@rpruim
Copy link
Contributor

rpruim commented Feb 20, 2018

require(Lock5withR)
df_stats( Empathy ~ Sex, data = CompassionateRats, props)
##   Sex  prop_yes   prop_no
## 1   F 1.0000000        NA
## 2   M 0.7083333 0.2916667
@dtkaplan
Copy link
Contributor

dtkaplan commented Mar 5, 2018

@rpruim I took care of this to some extent when I merged issue008 with beta. I didn't see an easy way to detect when counts() is being used in df_stats() and then to fix it there. And I don't think we can rely on NA always turning into 0 for general statistics. So I modified counts() to change NA to 0. This percolates through to props(), which is based on counts().

In df_stats(), the flag long_names is TRUE by default. so the names I am getting with the beta branch are

props(Empathy ~ Sex, data = CompassionateRats)
  Sex Empathy_prop_yes Empathy_prop_no
1   F        1.0000000       0.0000000
2   M        0.7083333       0.2916667

Of course you can change this, but I'm not sure why your names by default correspond to long_names = FALSE

> props(Empathy ~ Sex, data = CompassionateRats, long_names = FALSE)
  Sex  prop_yes   prop_no
1   F 1.0000000 0.0000000
2   M 0.7083333 0.2916667

@rpruim
Copy link
Contributor Author

rpruim commented Mar 5, 2018

Thanks. I've been busy with other things and haven't had a chance to take a closer look at issue008.

@rpruim
Copy link
Contributor Author

rpruim commented Mar 20, 2018

After merging stuff, I'm getting

props(Empathy ~ Sex, data = CompassionateRats)
##   Sex Empathy_prop_yes Empathy_prop_no
## 1   F        1.0000000       0.0000000
## 2   M        0.7083333       0.2916667
require(Lock5withR)
df_stats( Empathy ~ Sex, data = CompassionateRats, props)
##   Sex props_Empathy_prop_yes props_Empathy_prop_no
## 1   F              1.0000000                    NA
## 2   M              0.7083333             0.2916667

Note: the fix isn't working inside a call to df_stats() and the naming of the columns has changed since what I had before the merge.

Perhaps I misunderstood that this was ready to go and waiting for me to merge with master.

In any case, this issue is definitely still open.

@rpruim
Copy link
Contributor Author

rpruim commented Mar 21, 2018

I've reset master back to before this whole process began. I think we should start from scratch to fix this since (a) I messed things up in the repo and (b) the proposed fix was not a complete solution anyway. Certainly we can look back at what was done for ideas/code as needed.

@rpruim
Copy link
Contributor Author

rpruim commented Mar 22, 2018

I have a partial solution -- it works for factors (since it can use the levels to know to compute the 0's). So the original example works because Empathy is a factor with levels yes and no.

options(digits = 3)
require(Lock5withR)
df_stats( Empathy ~ Sex, data = CompassionateRats, props)
##   Sex prop_no prop_yes
## 1   F   0.000    1.000
## 2   M   0.292    0.708

The current implementation of df_stats() computes group by group without knowing what is going on in the other groups -- including the possible values of the summarized variable. The NA in the table gets introduced at a later stage, when the results are brought into a table. As @dtkaplan suggests, just converting NAs to 0's generally probably isn't the best solution.

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

No branches or pull requests

2 participants