entity_strata: Stratification by Entity

nordcanstat_metadata_statistics_tables_namesR Documentation

Stratification by Entity

Description

Compute statistics by entity number.

Usage

nordcanstat_metadata_statistics_tables_names(
  participant_name = nordcancore::nordcan_metadata_participant_info()[["name"]]
)

loop_over_entity_numbers(x, entities, fun, arg_list)

loop_over_entity_columns(x, entities, fun, arg_list)

nordcanstat_by_entity(
  entities,
  arg_list,
  basicepistats_fun,
  loop_over = c("entity_numbers", "entity_columns")[1L]
)

Arguments

participant_name

⁠[character]⁠ (optional, default taken from settings)

see nordcancore::set_global_nordcan_settings

x

⁠[data.table]⁠ (mandatory, no default)

a NORDCAN cancer record dataset

entities

⁠[NULL, integer]⁠ (optional, default NULL)

see by for how to stratify output by entity number.

  • NULL: output of nordcancore::nordcan_metadata_entity_no_set("all") is used

  • integer: these entity numbers are used

fun

⁠[function]⁠ (mandatory, no default)

function that is applied to each entity / entity column; see Details

arg_list

⁠[list]⁠ (mandatory, no default)

a list containing arguments to pass to fun; see Details

basicepistats_fun

⁠[function]⁠ (mandatory, no default)

function from basicepistats, e.g. ⁠[basicepistats::stat_count]⁠; this function will be run to produce results by entity number

loop_over

⁠[character]⁠ (mandatory, default "entity_numbers")

  • "entity_columns": function loop_over_entity_columns is called internally

  • "entity_numbers": function loop_over_entity_numbers is called internally

Details

loop_over_entity_numbers effectively loops over each entity number given in entities and computes the results separately for each.

loop_over_entity_columns loops over each column defining entities in x. For each such column, arg_list[["by"]] is created or modified to have (also) the column in question, limited to only those entities supplied in entities.

Both of these two functions are intended to be applied internally by the nordcanstat_ family of functions and not by the user.

fun is called using arg_list after the appropriate entity- or entity column-specific modification using ⁠[base::do.call]⁠.

loop_over_entity_numbers modifies an element in arg_list named subset, intended to subset the cancer record dataset. If fun does not have an argument named subset, the dataset x is itself subset before passing to fun. This is done separately for each entity number.

loop_over_entity_columns modifies or creates arg_list[["by"]] before calling fun. x is not subset by this function. Therefore loop_over_entity_columns is a more efficient but also less flexible version of loop_over_entity_numbers.

Value

Either a list or a data.table. Initially results are collected into a list where each element is the set of results for an individual entity or entity column. If every element of this list is a data.table, then every element is combined into one long data.table where column "entity" will identify the entity. In the case of loop_over_entity_numbers the column "entity" is created and in the case of loop_over_entity_columns each entity column is renamed to "entity" in the entity column-specific results before combining.


CancerRegistryOfNorway/nordcanepistats documentation built on June 3, 2024, 5:41 p.m.