AndriSignorell / DescTools

Tools for Descriptive Statistics and Exploratory Data Analysis
http://andrisignorell.github.io/DescTools/
86 stars 18 forks source link

P-Value number #156

Closed giuseppetrimarchi closed 3 months ago

giuseppetrimarchi commented 3 months ago

There is the possibility of inserting in the TOne function the number of the P-value in the last right column of the word file created and not the asterisks that indicate the various levels of significance ( 0.001 0.01 0.05 '.' 0.1 ' 1)? Thank you

AndriSignorell commented 3 months ago

Simply use the fmt argument and define the pval=as.fmt(fmt="p", na.form=" ") as follows:

TOne(x, grp = NA, add.length = TRUE, colnames = NULL, vnames = NULL, 
     total = TRUE, align = "\\l", 
     FUN = NULL, TEST = NULL, intref = "high",
     fmt = list(abs = Fmt("abs"), num  = Fmt("num"), per = Fmt("per"),
                pval = as.fmt(fmt = "p", na.form = "   ")) )

example:

TOne(x = iris[, -5], grp = iris[, 5],
     FUN = function(x) gettextf("%s / %s",
                                Format(mean(x, na.rm = TRUE), digits = 1),
                                Format(sd(x, na.rm = TRUE), digits = 3)),

     TEST = list(
       num = list(fun = function(x, g){summary(aov(x ~ g))[[1]][1, "Pr(>F)"]},
                  lbl = "ANOVA"),
       cat = list(fun = function(x, g){chisq.test(table(x, g))$p.val},
                  lbl = "Chi-Square test"),
       dich = list(fun = function(x, g){fisher.test(table(x, g))$p.val},
                   lbl = "Fisher exact test")),
     fmt = list(abs = Fmt("abs"), num  = Fmt("num"), per = Fmt("per"),
                pval = as.fmt(fmt = "p", na.form = "   "))
)
giuseppetrimarchi commented 3 months ago

Thank you