clprep
Presets: a published dataset’s columns onto a generic function’s arguments
clprep(data = NULL, preset = NULL)A preset says how the columns of one published dataset (an Ontario
segregation table, the Special Investigations Unit’s cases, a use-of-force
file) feed the arguments of one of crimlab’s generic functions, so that
generic(clprep(data, preset)) gives the published analysis while the
same generic runs on anyone’s data given as plain vectors. A preset
describes a layout and ships no data: the user supplies the table.
Parameters
Section titled “Parameters”dataThe dataset: a data frame with the columns the preset names.
NULL(withpresetNULL) lists the presets.presetThe preset’s name, as
clprep()lists them;NULLfor the list.
Returns
Section titled “Returns”With a preset, an object of class clpre: a list of the
generic’s arguments, which the generic takes as its first argument,
with attributes preset, generic, source, units, note and
drop. Without one, a data frame of the presets: preset, generic,
args and source.
The presets are rows of presets.tsv (in the installed package’s
presets folder), one per preset and argument: preset, generic,
arg, column (the dataset’s column), recode, filter, units,
note, source. Python reads the same file. A recode is one of:
empty (the column as it is); fac (a factor, one effect per value);
num (numbers); one (a 1 for every row); sub:a,b (characters a to
b, as a year from an ISO date); const:v (the argument is v, no
column); or a mapping x|y=1;has:abc=1;*=0 from labels, compared without
case or surrounding space (has: a label containing the text), to
values, * covering every other label and *=NA dropping those rows. A
filter col=value keeps the rows whose column has that value. An
arg of recipe derives columns first: long stacks the two count
columns named in recode as count with with 1 for the first; acvm
and pyr reduce one row per placement to one per person and year (see
Details of the returned attributes).
Rows with a missing value in any column the preset reads are dropped,
as the source analyses drop them; their number is the attribute
drop.
Examples
Section titled “Examples”head(clprep())# a table laid out as the published OTIS c01 table (numbers made up)d <- data.frame(EndFiscalYear = rep(2020:2022, each = 2), Gender = rep(c("Female", "Male"), 3), NumberIndividuals_RestrictiveConfinement = c(40, 310, 52, 335, 47, 360))p <- clprep(d, "otis-c01-cnt")cntreg(p)# the same model on plain vectorscntreg(d$NumberIndividuals_RestrictiveConfinement, d$Gender == "Female", adj = factor(d$EndFiscalYear))Generated from the R help page: clprep in the R reference.