Skip to contents

The package provides functionalities to tidy a summarised result to obtain a dataframe with which is easier to do subsequent calculations.

In this line, the split functions, described in split and unite functions allow to interact with name-level columns.

For the estimates, we have the pivotEstimates function, and for the settings addSettings. Finally the tidy method accommodates the split and pivot functionalities in the same function.

Estimates

First, let’s load relevant libraries and create a mock summarised result table.

library(visOmopResults)
library(dplyr)
result <- mockSummarisedResult()
result |> glimpse()
#> Rows: 126
#> Columns: 13
#> $ result_id        <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
#> $ cdm_name         <chr> "mock", "mock", "mock", "mock", "mock", "mock", "mock…
#> $ group_name       <chr> "cohort_name", "cohort_name", "cohort_name", "cohort_…
#> $ group_level      <chr> "cohort1", "cohort1", "cohort1", "cohort1", "cohort1"…
#> $ strata_name      <chr> "overall", "age_group &&& sex", "age_group &&& sex", …
#> $ strata_level     <chr> "overall", "<40 &&& Male", ">=40 &&& Male", "<40 &&& …
#> $ variable_name    <chr> "number subjects", "number subjects", "number subject…
#> $ variable_level   <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
#> $ estimate_name    <chr> "count", "count", "count", "count", "count", "count",…
#> $ estimate_type    <chr> "integer", "integer", "integer", "integer", "integer"…
#> $ estimate_value   <chr> "807501", "8343330", "6007609", "1572084", "73994", "…
#> $ additional_name  <chr> "overall", "overall", "overall", "overall", "overall"…
#> $ additional_level <chr> "overall", "overall", "overall", "overall", "overall"…

The function pivotEstimates adds columns containing the estimates values for each combination of columns in pivotEstimatesBy. For instance, in the following example we use the columns variable_name, variable_level, and estimate_name to pivot the estimates.

result |> 
  pivotEstimates(pivotEstimatesBy = c("variable_name", "variable_level", "estimate_name")) |>
  glimpse()
#> Rows: 18
#> Columns: 15
#> $ result_id                          <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
#> $ cdm_name                           <chr> "mock", "mock", "mock", "mock", "mo…
#> $ group_name                         <chr> "cohort_name", "cohort_name", "coho…
#> $ group_level                        <chr> "cohort1", "cohort1", "cohort1", "c…
#> $ strata_name                        <chr> "overall", "age_group &&& sex", "ag…
#> $ strata_level                       <chr> "overall", "<40 &&& Male", ">=40 &&…
#> $ additional_name                    <chr> "overall", "overall", "overall", "o…
#> $ additional_level                   <chr> "overall", "overall", "overall", "o…
#> $ `number subjects_NA_count`         <int> 807501, 8343330, 6007609, 1572084, …
#> $ age_NA_mean                        <dbl> 38.870131, 97.554784, 28.989230, 67…
#> $ age_NA_sd                          <dbl> 7.0643384, 9.4857658, 1.8033877, 2.…
#> $ Medications_Amoxiciline_count      <int> 49364, 77931, 20418, 71340, 6522, 3…
#> $ Medications_Amoxiciline_percentage <dbl> 2.806097, 46.598719, 39.003139, 2.0…
#> $ Medications_Ibuprofen_count        <int> 99707, 14904, 51856, 84612, 71827, …
#> $ Medications_Ibuprofen_percentage   <dbl> 51.179131, 83.555244, 70.878116, 87…

The argument nameStyle is to customise the names of the new columns. It uses the glue package syntax. For instance:

result |> 
  pivotEstimates(pivotEstimatesBy = "estimate_name",
                 nameStyle = "{toupper(estimate_name)}") |>
  glimpse()
#> Rows: 72
#> Columns: 14
#> $ result_id        <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
#> $ cdm_name         <chr> "mock", "mock", "mock", "mock", "mock", "mock", "mock…
#> $ group_name       <chr> "cohort_name", "cohort_name", "cohort_name", "cohort_…
#> $ group_level      <chr> "cohort1", "cohort1", "cohort1", "cohort1", "cohort1"…
#> $ strata_name      <chr> "overall", "age_group &&& sex", "age_group &&& sex", …
#> $ strata_level     <chr> "overall", "<40 &&& Male", ">=40 &&& Male", "<40 &&& …
#> $ variable_name    <chr> "number subjects", "number subjects", "number subject…
#> $ variable_level   <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
#> $ additional_name  <chr> "overall", "overall", "overall", "overall", "overall"…
#> $ additional_level <chr> "overall", "overall", "overall", "overall", "overall"…
#> $ COUNT            <int> 807501, 8343330, 6007609, 1572084, 73994, 4663935, 49…
#> $ MEAN             <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
#> $ SD               <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
#> $ PERCENTAGE       <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…

Settings

The function addSettings adds a new column for each of the settings in the summarised result, if any:

mockSummarisedResult() |>
  addSettings() |>
  glimpse()
#> Rows: 126
#> Columns: 16
#> $ result_id        <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
#> $ cdm_name         <chr> "mock", "mock", "mock", "mock", "mock", "mock", "mock…
#> $ group_name       <chr> "cohort_name", "cohort_name", "cohort_name", "cohort_…
#> $ group_level      <chr> "cohort1", "cohort1", "cohort1", "cohort1", "cohort1"…
#> $ strata_name      <chr> "overall", "age_group &&& sex", "age_group &&& sex", …
#> $ strata_level     <chr> "overall", "<40 &&& Male", ">=40 &&& Male", "<40 &&& …
#> $ variable_name    <chr> "number subjects", "number subjects", "number subject…
#> $ variable_level   <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
#> $ estimate_name    <chr> "count", "count", "count", "count", "count", "count",…
#> $ estimate_type    <chr> "integer", "integer", "integer", "integer", "integer"…
#> $ estimate_value   <chr> "4028812", "7696302", "1194854", "1946950", "1645692"…
#> $ additional_name  <chr> "overall", "overall", "overall", "overall", "overall"…
#> $ additional_level <chr> "overall", "overall", "overall", "overall", "overall"…
#> $ result_type      <chr> "mock_summarised_result", "mock_summarised_result", "…
#> $ package_name     <chr> "visOmopResults", "visOmopResults", "visOmopResults",…
#> $ package_version  <chr> "0.3.0", "0.3.0", "0.3.0", "0.3.0", "0.3.0", "0.3.0",…

Tidy

Finally, the method tidy incorporates the splitting pf name-level columns and pivotting of estimates and settings. By default, it splits group, strata and additional, pivots estimates by the columns “estimate_name” and also pivots the settings.

result <- mockSummarisedResult()

result |> 
  tidy() |> 
  glimpse()
#> Rows: 72
#> Columns: 14
#> $ result_id       <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
#> $ cdm_name        <chr> "mock", "mock", "mock", "mock", "mock", "mock", "mock"…
#> $ cohort_name     <chr> "cohort1", "cohort1", "cohort1", "cohort1", "cohort1",…
#> $ age_group       <chr> "overall", "<40", ">=40", "<40", ">=40", "overall", "o…
#> $ sex             <chr> "overall", "Male", "Male", "Female", "Female", "Male",…
#> $ variable_name   <chr> "number subjects", "number subjects", "number subjects…
#> $ variable_level  <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
#> $ count           <int> 7269489, 6376856, 3964100, 9594826, 2986580, 502012, 5…
#> $ mean            <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
#> $ sd              <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
#> $ percentage      <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
#> $ result_type     <chr> "mock_summarised_result", "mock_summarised_result", "m…
#> $ package_name    <chr> "visOmopResults", "visOmopResults", "visOmopResults", …
#> $ package_version <chr> "0.3.0", "0.3.0", "0.3.0", "0.3.0", "0.3.0", "0.3.0", …

Which column pairs to split can be customised with the split arguments, while pivotEstimatesBy and nameStyle are for pivotting estimates. If pivotEstimatesBy is NULL or character(), estimates will not be modified. Settings will always be pivotted if present.