Mutate logs

library(bupaverse)
library(dplyr)

Next to augment() for enriching an event log with calculated metrics, you can use mutate() to add more custom new variables to a log, or change the existing ones. The use of mutate() is especially convenient in combination with group_by().

Transforming variables

The code below transforms the lacticacid variable, stored as a character, to a numeric variable.

sepsis %>%
    mutate(lacticacid = as.numeric(lacticacid)) -> sepsis

Calculating variables

Below, we group the data by case using group_by_case(), and subsequently calculate the total lacticacid value. Note that setting na.rm = TRUE is required as there are missing values present for this variable.

sepsis %>%
    group_by_case() %>%
    mutate(total_lacticacid = sum(lacticacid, na.rm = TRUE)) %>%
    ungroup_eventlog()
## # Log of 15214 events consisting of:
## 846 traces 
## 1050 cases 
## 15214 instances of 16 activities 
## 26 resources 
## Events occurred from 2013-11-07 08:18:29 until 2015-06-05 12:25:11 
##  
## # Variables were mapped as follows:
## Case identifier:     case_id 
## Activity identifier:     activity 
## Resource identifier:     resource 
## Activity instance identifier:    activity_instance_id 
## Timestamp:           timestamp 
## Lifecycle transition:        lifecycle 
## 
## # A tibble: 15,214 × 35
##    case_id activity      lifec…¹ resou…² timestamp             age   crp diagn…³
##    <chr>   <fct>         <fct>   <fct>   <dttm>              <dbl> <dbl> <chr>  
##  1 A       ER Registrat… comple… A       2014-10-22 11:15:41    85    NA A      
##  2 A       Leucocytes    comple… B       2014-10-22 11:27:00    NA    NA <NA>   
##  3 A       CRP           comple… B       2014-10-22 11:27:00    NA   210 <NA>   
##  4 A       LacticAcid    comple… B       2014-10-22 11:27:00    NA    NA <NA>   
##  5 A       ER Triage     comple… C       2014-10-22 11:33:37    NA    NA <NA>   
##  6 A       ER Sepsis Tr… comple… A       2014-10-22 11:34:00    NA    NA <NA>   
##  7 A       IV Liquid     comple… A       2014-10-22 14:03:47    NA    NA <NA>   
##  8 A       IV Antibioti… comple… A       2014-10-22 14:03:47    NA    NA <NA>   
##  9 A       Admission NC  comple… D       2014-10-22 14:13:19    NA    NA <NA>   
## 10 A       CRP           comple… B       2014-10-24 09:00:00    NA  1090 <NA>   
## # … with 15,204 more rows, 27 more variables: diagnosticartastrup <lgl>,
## #   diagnosticblood <lgl>, diagnosticecg <lgl>, diagnosticic <lgl>,
## #   diagnosticlacticacid <lgl>, diagnosticliquor <lgl>, diagnosticother <lgl>,
## #   diagnosticsputum <lgl>, diagnosticurinaryculture <lgl>,
## #   diagnosticurinarysediment <lgl>, diagnosticxthorax <lgl>, disfuncorg <lgl>,
## #   hypotensie <lgl>, hypoxie <lgl>, infectionsuspected <lgl>, infusion <lgl>,
## #   lacticacid <dbl>, leucocytes <chr>, oligurie <lgl>, …

Before continuing to further analyses, not that you might want to ungroup the log using ungroup_eventlog(). More on grouping.

```


Read more:


Copyright © 2023 bupaR - Hasselt University