tableone icon indicating copy to clipboard operation
tableone copied to clipboard

p-value NaN

Open eribul opened this issue 8 years ago • 5 comments

Let's say I have some data:

data <- data.frame(
  a = factor(rep(1:2, 2), levels = 1:3), 
  b = rep(1:2, each = 2))

Hence, a has three levels but we did´t actually observe any elements of level 3.

Then:

tableone::CreateTableOne(
  vars             = "a",  
  strata           = "b",
  data             = data,
  factorVars       = "a"
) %>% 
  print(
    showAllLevels  = TRUE,
)

gives:

       Stratified by b
        level 1         2         p      test
  n           2         2                    
  a (%) 1     1 (50.0)  1 (50.0)   1.000     
        2     1 (50.0)  1 (50.0)             

hence, a p-value is given but the third level is dropped (as according to #15 ).

If I do not specify `factorVars = "a"`` such as:


tableone::CreateTableOne(
  vars             = "a",  
  strata           = "b",
  data             = data,
) %>% 
  print(
    showAllLevels  = TRUE,
  )

I get:

       Stratified by b
        level 1         2         p    test
  n           2         2                  
  a (%) 1     1 (50.0)  1 (50.0)   NaN     
        2     1 (50.0)  1 (50.0)           
        3     0 ( 0.0)  0 ( 0.0)           

hence, data for all levels but p-value = NaN.

According to the man page, kruskal.test is used in this situation but if I call kruskat.test manually (kruskal.test(a ~ b, data))I do get a valid p-value (= 1, the same as in the first case above).

I therefore assume it would be possible to give this p-value also when all levels are presented? And to to so would be quite nice!

eribul avatar May 09 '16 12:05 eribul

This is strange. Thanks for pointing out.

kaz-yos avatar Jun 29 '16 03:06 kaz-yos

I had to call the droplevels() function on the dataframe I passed in in order to get the P values to work. Unfortunately, it loses all the labels from applied by the labelled::var_label() function, so this has to be re-done.

tylcole avatar Jan 13 '19 01:01 tylcole

any progress? :-) I havn't tested if it works now, I just made an inventory of all my opened but unresolved issues and found this one.

eribul avatar May 02 '20 10:05 eribul

It looks like this is still an issue. Could you update the vignette to guide users to use factorVars() if they have 0 observations?

RiversPharmD avatar Feb 08 '22 16:02 RiversPharmD

Sorry, not sure why I took the liberty to close this issue! I appologize and reopen!

eribul avatar Feb 08 '22 22:02 eribul