write_popu: Write a population table (data) from a riskyr scenario...

View source: R/riskyr_sims.R

write_popuR Documentation

Write a population table (data) from a riskyr scenario (description).

Description

write_popu computes (or expands) a table popu (as an R data frame) from a riskyr scenario (description), using its 4 essential frequencies.

Usage

write_popu(x = NULL, ...)

Arguments

x

A riskyr scenario (description).

...

Additional parameters (text labels, passed to comp_popu).

Format

An object of class data.frame with N rows and 3 columns (e.g., "X/truth/cd", "Y/test/dc", "SDT/cell/class").

Details

write_popu expects a riskyr scenario as input and passes its 4 essential frequencies (rounded to integers) to comp_popu.

By default, write_popu uses the text settings contained in txt, but labels can be changed by passing arguments to comp_popu (via ...).

Value

A data frame popu containing N rows (individual cases) and 3 columns (e.g., "X/truth/cd", "Y/test/dc", "SDT/cell/class"). encoded as ordered factors (with 2, 2, and 4 levels, respectively).

See Also

comp_popu creates data (as df) from description (frequencies); read_popu creates a scenario (description) from data (as df); popu for data format; txt for current text settings; riskyr initializes a riskyr scenario.

Other functions converting data/descriptions: comp_popu(), read_popu()

Examples

# Define scenarios (by description):
s1 <- riskyr(prev = .5, sens = .5, spec = .5, N = 10)  # s1: define by 3 prob & N
s2 <- riskyr(hi = 2, mi = 3, fa = 2, cr = 3)           # s2: same scenario by 4 freq

# Create data (from descriptions):
write_popu(s1)  # data from (prob) description
write_popu(s2,  # data from (freq) description & change labels:
           cond_lbl = "Disease (X)",
           cond_true_lbl = "sick", cond_false_lbl = "healthy",
           dec_lbl = "Test (Y)")

# Rounding:
s3 <- riskyr(prev = 1/3, sens = 2/3, spec = 6/7, N = 10, round = FALSE)  # s3: w/o rounding
write_popu(s3, cond_lbl = "X", dec_lbl = "Y", sdt_lbl = "class")  # rounded to nearest integers

# Sampling:
s4 <- riskyr(prev = 1/3, sens = 2/3, spec = 6/7, N = 10, sample = TRUE)  # s4: with sampling
write_popu(s4, cond_lbl = "X", dec_lbl = "Y", sdt_lbl = "class")  # data from sampling


riskyr documentation built on Aug. 15, 2022, 9:09 a.m.