socialresearchcentre / projectable

Produce table-like objects made up of special metadata-rich column vectors, and project them into two dimensions.
https://socialresearchcentre.github.io/projectable
GNU General Public License v3.0
3 stars 0 forks source link

Make `col` API as consistent as possible #1

Closed kinto-b closed 4 years ago

kinto-b commented 4 years ago

We should probably rename successes and sample to little_n and big_n respectively for consistency with col_freq

Possibly the same is true of probability and proportion. But it's less clear that that's the right way to go because the probability in a col_binomial is NOT a proportion; it's an estimated probability. And since the col_binomial is created using the Agresti-Coull method, there's a substantive difference between the two.

kinto-b commented 4 years ago

Also allow for summarised/unsummarised inputs:

col_freq <- function(n = double(), N = double(), p = NULL, summarised = FALSE) {
  if (!summarised) {
    n <- sum(n, na.rm = TRUE)
    N <- sum(N, na.rm = TRUE)
    if (!is.null(p)) stop("May only provide `p` if `summarised` is TRUE")
  }
  if (is.null(p)) p <- n / N
  out <- vctrs::vec_cast_common(n, N, p, .to = double())
  out <- vctrs::vec_recycle_common(!!!out)

  validate_col_freq(
    new_col_freq(out[[1]], out[[2]], out[[3]])
  )
}