Learn R Programming

scrutiny (version 1.0.0)

disperse: Vary hypothetical group sizes

Description

If a study reports a total sample size but no group sizes, these functions generate pairs of hypothetical group sizes that add up to the total:

  • disperse() takes half of an even total and goes up and down from it.

  • disperse2() takes the two consecutive numbers around half of an odd total, and goes down from the lower and up from the upper.

  • disperse_total() takes the total itself and calls one of the two, depending on whether it is even or odd.

They are the basis of grim_map_total_n() and the other functions made by function_map_total_n().

Usage

disperse(n, dispersion = 0:5, n_min = 1L, n_max = NULL, constant = NULL)

disperse2(n, dispersion = 0:5, n_min = 1L, n_max = NULL, constant = NULL)

disperse_total(n, dispersion = 0:5, n_min = 1L, n_max = NULL, constant = NULL)

Value

A tibble with these columns:

  • n: the group sizes. Each pair of consecutive rows adds up to the total.

  • n_change: the number of steps from the input n, negative for the lower group size of each pair.

Arguments

n

Numeric. In disperse(), half of an even total. In disperse2(), the two consecutive numbers closest to half of an odd total, such as c(25, 26) for 51. In disperse_total(), the total itself.

dispersion

Numeric. Non-negative whole numbers of steps up and down from n (or, in disperse_total(), from half of n). Default is 0:5.

n_min

Numeric. Minimal group size. Default is 1L.

n_max

Numeric. Maximal group size. Default is NULL, no maximum.

constant

Optionally, a length-2 vector, or a list of such vectors (which includes a data frame with two rows), to repeat alongside each pair of group sizes. Default is NULL.

Details

A pair with a group size below n_min or above n_max is dropped. Columns from constant are named after a named list's elements, or "constant1", "constant2", etc. for an unnamed one; a single pair is "constant".

References

Bauer, P. J., & Francis, G. (2021). Expression of Concern: Is It Light or Dark? Recalling Moral Behavior Changes Perception of Brightness. Psychological Science, 32(12), 2042–2043. https://journals.sagepub.com/doi/10.1177/09567976211058727

See Also

function_map_total_n() and grim_map_total_n().

Examples

Run this code
# For a total of 40, `n` is 20:
disperse(n = 20)

disperse(n = 20, dispersion = c(3, 6, 10))

# For an odd total, `disperse2()` takes two group sizes:
disperse2(n = c(25, 26))

# `disperse_total()` takes the total itself:
disperse_total(n = 40)
disperse_total(n = 51)

# Values that repeat alongside the pairs:
disperse_total(37, constant = c("5.24", "3.80"))

df_constant <- tibble::tibble(
  name = c("Paul", "Mathilda"), age = 27:28,
  registered = c(TRUE, FALSE)
)
disperse_total(37, constant = df_constant)

Run the code above in your browser using DataLab