A summarised result

knitr::opts_chunk$set(
  collapse = TRUE, message = FALSE, warning = FALSE,
  comment = "#>"
)

Introduction

A summarised result is a table that contains aggregated summary statistics (a result set with no patient-level data). The summarised result object consists of two objects: a results table and a settings table.

Results table

This table has 13 columns:

The following table summarises the requirements of each column in the summarised_result format:

dplyr::tibble(
  `Column name` = omopgenerics::resultColumns(),
  `Column type` = c("integer", rep("character", 12)),
  `is NA allowed?` = c(rep("No", 7), "Yes", rep("No", 5)),
  `Requirements` = c(NA, NA, "name1", "level1", "name2", "level2", NA, NA, "snake_case", "estimateTypeChoices()", NA, "name3", "level3")
) |>
  gt::gt()

Settings

The settings table provides one row per result_id with the settings used to generate those results. There is no limit on the number of columns or parameters that can be provided per result_id, but at least three values should be provided:

These columns must be character vectors, but this restriction does not apply to other extra columns.

newSummarisedResult

The newSummarisedResult() function can be used to create objects. The inputs to this function are the summarised_result table, which must satisfy the conditions specified above, and the settings argument. The settings argument can be NULL or omit some required columns; missing columns will be populated by default and a warning will appear. Let's see a very simple example:

library(omopgenerics)
library(dplyr)

x <- tibble(
  result_id = 1L,
  cdm_name = "my_cdm",
  group_name = "cohort_name",
  group_level = "cohort1",
  strata_name = "sex",
  strata_level = "male",
  variable_name = "Age group",
  variable_level = "10 to 50",
  estimate_name = "count",
  estimate_type = "numeric",
  estimate_value = "5",
  additional_name = "overall",
  additional_level = "overall"
)

result <- newSummarisedResult(x)
result |>
  glimpse()
settings(result)

We can also associate settings with our results. These will typically be used to explain how the result was created.

result <- newSummarisedResult(
  x = x,
  settings = tibble(
    result_id = 1L,
    package_name = "PatientProfiles",
    study = "my_characterisation_study"
  )
)

result |> glimpse()
settings(result)

Combining summarised results

Multiple summarised result objects can be combined using the bind function. Result IDs will be assigned for each set of results with the same settings. If two groups of results have the same settings, although they are in different objects, they will be merged into a single one.

result1 <- newSummarisedResult(
  x = tibble(
    result_id = 1L,
    cdm_name = "my_cdm",
    group_name = "cohort_name",
    group_level = "cohort1",
    strata_name = "sex",
    strata_level = "male",
    variable_name = "Age group",
    variable_level = "10 to 50",
    estimate_name = "count",
    estimate_type = "numeric",
    estimate_value = "5",
    additional_name = "overall",
    additional_level = "overall"
  ),
  settings = tibble(
    result_id = 1L,
    package_name = "PatientProfiles",
    package_version = "1.0.0",
    study = "my_characterisation_study",
    result_type = "stratified_by_age_group"
  )
)

result2 <- newSummarisedResult(
  x = tibble(
    result_id = 1L,
    cdm_name = "my_cdm",
    group_name = "overall",
    group_level = "overall",
    strata_name = "overall",
    strata_level = "overall",
    variable_name = "overall",
    variable_level = "overall",
    estimate_name = "count",
    estimate_type = "numeric",
    estimate_value = "55",
    additional_name = "overall",
    additional_level = "overall"
  ),
  settings = tibble(
    result_id = 1L,
    package_name = "PatientProfiles",
    package_version = "1.0.0",
    study = "my_characterisation_study",
    result_type = "overall_analysis"
  )
)

Now that we have our results, we can combine them using bind. Because the two sets of results contain the same result ID, this will be automatically updated when the results are combined.

result <- bind(result1, result2)
result |>
  dplyr::glimpse()
settings(result)

Minimum cell count suppression

We have an entire vignette explaining how the summarised_result object is suppressed: vignette("suppression", "omopgenerics").

Export and import summarised results

The summarised_result object can be exported and imported as a CSV file with the following functions:

Note that exportSummarisedResult() also suppresses the results.

x <- tempdir()
files <- list.files(x)

exportSummarisedResult(result, path = x, fileName = "result.csv")
setdiff(list.files(x), files)

Note that the settings are included in the CSV file:

fil <- file.path(x, "result.csv")
readLines(fil) |>
  cat()

You can later import the results back with importSummarisedResult():

res <- importSummarisedResult(path = file.path(x, "result.csv"))
class(res)
res |>
  glimpse()
res |>
  settings()

Tidy a <summarised_result>

Tidy method

omopgenerics defines a tidy() method for <summarised_result> objects. This function:

1. Split group, strata, and additional pairs into separate columns:

The <summarised_result> object has the following pair columns: group_name-group_level, strata_name-strata_level, and additional_name-additional_level. These pairs use the &&& separator to combine multiple fields. For example, if you want to combine cohort_name and age_group in the group_name-group_level pair: group_name = "cohort_name &&& age_group" and group_level = "my_cohort &&& <40". By default, if no aggregation is produced in the group_name-group_level pair: group_name = "overall" and group_level = "overall".

ORIGINAL FORMAT:

dplyr::tibble(
  group_name = c("cohort_name", c("cohort_name &&& sex"), c("sex &&& age_group")),
  group_level = c("acetaminophen", c("acetaminophen &&& Female"), c("Male &&& <40"))
) |>
  gt::gt()

The tidy format puts each value into its own column. This makes it easier to manipulate, but the output is no longer standardised, as each <summarised_result> object will have a different number and set of column names. Missing values will be filled with the "overall" label.

TIDY FORMAT:

dplyr::tibble(
  group_name = c("cohort_name", c("cohort_name &&& sex"), c("sex &&& age_group")),
  group_level = c("acetaminophen", c("acetaminophen &&& Female"), c("Male &&& <40"))
) |>
  splitGroup() |>
  gt::gt()

2. Add settings of the <summarised_result> object as columns:

Each <summarised_result> object has a settings attribute that relates the 'result_id' column to each different set of settings. The columns 'result_type', 'package_name' and 'package_version' are always present in settings, but we may also have extra parameters depending on how the object was created. In the <summarised_result> format, we need to use the settings() function to see those variables:

ORIGINAL FORMAT:

settings:

dplyr::tibble(
  result_id = c(1L, 2L),
  my_setting = c(TRUE, FALSE),
  package_name = "omopgenerics"
) |>
  gt::gt()

<summarised_result>:

dplyr::tibble(
  result_id = c("1", "...", "2", "..."),
  cdm_name = c("omop", "...", "omop", "..."),
  " " = c("..."),
  additional_name = c("overall", "...", "overall", "...")
) |>
  gt::gt()

In the tidy format, we add the settings as columns, so their values are repeated multiple times (there is only one row per result_id in settings, whereas there can be multiple rows in the <summarised_result> object). The column 'result_id' is removed because it no longer provides information. Again, we lose standardisation (multiple different settings), but we gain flexibility:

TIDY FORMAT:

dplyr::tibble(
  cdm_name = c("omop", "...", "omop", "..."),
  " " = c("..."),
  additional_name = c("overall", "...", "overall", "..."),
  my_setting = c("TRUE", "...", "FALSE", "..."),
  package_name = c("omopgenerics", "...", "omopgenerics", "...")
) |>
  gt::gt()

3. Pivot estimates as columns:

In the <summarised_result> format estimates are displayed in 3 columns:

ORIGINAL FORMAT:

dplyr::tibble(
  variable_name = c("number individuals", "age", "age"),
  estimate_name = c("count", "mean", "sd"),
  estimate_type = c("integer", "numeric", "numeric"),
  estimate_value = c("100", "50.3", "20.7")
) |>
  gt::gt()

In the tidy format, we pivot the estimates, creating a new column for each 'estimate_name' value. The columns will be cast to 'estimate_type'. If there are multiple estimate_type values for the same estimate_name, they will not be cast and will be displayed as character values (a warning will be thrown). Missing data are populated with NAs.

TIDY FORMAT:

dplyr::tibble(
  variable_name = c("number individuals", "age"),
  count = c(100L, NA),
  mean = c(NA, 50.3),
  sd = c(NA, 20.7)
) |>
  gt::gt()

Example

Let's see a simple example with some toy data:

result |>
  tidy()

Split

The split functions are provided independently:

There is also the function: - splitAll() that splits any x_name-x_level pair found in the data.

splitAll(result)

Pivot estimates

pivotEstimates() can be used to pivot the variables that we are interested in.

The argument pivotEstimatesBy specifies which variables we want to use to pivot by. There are four options:

Note that variable_level can contain NA values, these will be ignored on the naming part.

pivotEstimates(
  result,
  pivotEstimatesBy = c("variable_name", "variable_level", "estimate_name")
)

Add settings

addSettings() is used to add the settings that we want as new columns to our <summarised_result> object.

The settingsColumn argument is used to choose which settings we want to add.

addSettings(
  result,
  settingsColumn = "result_type"
)

Filter

Dealing with an <summarised_result> object can be difficult, especially when we are trying to filter. For example, it can be difficult to filter to a certain result_type or, when many strata are joined together, to filter only one of the variables. The tidy format makes filtering easier, but using it means losing the <summarised_result> object.

The omopgenerics package contains functions that help with this process:

For instance, let's filter result so it only has results for males:

result |>
  filterStrata(sex == "male")

Now let's see an example using the information in settings to filter the result. In this case, we only want results from the "overall_analysis". Since this information is in the result_type column in settings, we proceed as follows:

result |>
  filterSettings(result_type == "overall_analysis")

Utility functions for <summarised_result>

Column retrieval functions

Working with <summarised_result> objects often involves managing columns for settings, grouping, strata, and additional levels. These retrieval functions help you identify and manage columns:

Let's see the different values with our example result data:

settingsColumns(result)
groupColumns(result)
strataColumns(result)
additionalColumns(result)
tidyColumns(result)

Unite functions

The unite functions serve as the complementary tools to the split functions, allowing you to generate name-level pair columns from targeted columns within a <dataframe>.

There are three unite functions that allow you to create group, strata, and additional name-level columns from specified sets of columns:

Example

For example, to create group_name and group_level columns from a tibble, you can use:

# Create and show mock data
data <- tibble(
  denominator_cohort_name = c("general_population", "older_than_60", "younger_than_60"),
  outcome_cohort_name = c("stroke", "stroke", "stroke")
)
head(data)

# Unite into group name-level columns
data |>
  uniteGroup(cols = c("denominator_cohort_name", "outcome_cohort_name"))

These functions can be helpful when creating your own <summarised_result>.



Try the omopgenerics package in your browser

Any scripts or data that you put into this service are public.

omopgenerics documentation built on Sept. 8, 2026, 9:06 a.m.