tableone
tableone copied to clipboard
p-value NaN
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!
This is strange. Thanks for pointing out.
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.
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.
It looks like this is still an issue. Could you update the vignette to guide users to use factorVars() if they have 0 observations?
Sorry, not sure why I took the liberty to close this issue! I appologize and reopen!