tklebel / crosstabr

Cross tabulation with HTML and Markdown output
Other
1 stars 0 forks source link

implement add_stats #3

Closed tklebel closed 8 years ago

tklebel commented 9 years ago

add_stats should take arguments as a vector and output a box with stats, taken from vcd::assocstats (Chi-square, Cramers-V, ...)

tklebel commented 9 years ago

should have sensible default: fisher.test() and vcd::assocstats$cramer probably.

Statistics should be supplied in a simple way (not: fisher = T). Is there a simpler possibility?

Possibly: add_stats(~fisher, ~chisq, ~cramer)

Alternatively, with the need to quote:

ad_stats <- function(...) {
  test <- match.arg(..., c("cramer", "chisq", "fisher"), several.ok = T)
  switch(test,
         cramer = assocstats(x)$cramer,
         chisq = chisq.test(x),
         fisher = fisher.test(x))
}

although switch wouldn't work here: it just computes the first match. would need something else.

tklebel commented 9 years ago

Could work like this:

ad_stats <- function(...) {
  test <- match.arg(..., c("cramer", "chisq", "fisher"), several.ok = T)
  if ("fisher" %in% test) {
    fisher <– fisher.test(x)
  }
  ...
}