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  lifecycle resource timestamp             age   crp diagnose
##    <chr>   <fct>     <fct>     <fct>    <dttm>              <dbl> <dbl> <chr>   
##  1 A       ER Regis… complete  A        2014-10-22 11:15:41    85    NA A       
##  2 A       Leucocyt… complete  B        2014-10-22 11:27:00    NA    NA <NA>    
##  3 A       CRP       complete  B        2014-10-22 11:27:00    NA   210 <NA>    
##  4 A       LacticAc… complete  B        2014-10-22 11:27:00    NA    NA <NA>    
##  5 A       ER Triage complete  C        2014-10-22 11:33:37    NA    NA <NA>    
##  6 A       ER Sepsi… complete  A        2014-10-22 11:34:00    NA    NA <NA>    
##  7 A       IV Liquid complete  A        2014-10-22 14:03:47    NA    NA <NA>    
##  8 A       IV Antib… complete  A        2014-10-22 14:03:47    NA    NA <NA>    
##  9 A       Admissio… complete  D        2014-10-22 14:13:19    NA    NA <NA>    
## 10 A       CRP       complete  B        2014-10-24 09:00:00    NA  1090 <NA>    
## # ℹ 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>, …

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