8.2 How to use mlr3

8.2.1 DALYs due to Dengue

library(hmsidwR)
library(dplyr)
library(tidyr)
dalys_dengue <- hmsidwR::infectious_diseases %>%
  arrange(year) %>%
  filter(cause_name == "Dengue",
         year<=2016,
         !location_name %in% c("Eswatini", "Lesotho")) %>%
  drop_na() %>%
  group_by(location_id) %>%
  select(-location_name, -cause_name)

dalys_dengue %>%
  head()
## # A tibble: 6 × 8
## # Groups:   location_id [3]
##    year location_id   Deaths DALYs  YLDs   YLLs Prevalence Incidence
##   <dbl>       <dbl>    <dbl> <dbl> <dbl>  <dbl>      <dbl>     <dbl>
## 1  1990         182 0.0330    7.59  5.35 2.24         33.7      560.
## 2  1990         191 0.00135   6.88  6.86 0.0229       42.4      713.
## 3  1990         169 0.000760  2.25  2.24 0.0186       13.1      222.
## 4  1991         191 0.00135   8.57  8.54 0.0230       52.5      884.
## 5  1991         182 0.0327    8.68  6.47 2.21         40.9      681.
## 6  1991         169 0.000760  2.23  2.22 0.0185       13.0      218.

Load mlr3 packages:

library(mlr3)
library(mlr3learners)
library(mlr3viz)
library(mlr3verse)
library(data.table)
# library(xgboost)

Set a Task:

task <- TaskRegr$new(id = "DALYs",
                     backend = dalys_dengue,
                     target = "DALYs"
                     )

Specify two models:

learner_cv_glmnet <- lrn("regr.cv_glmnet", 
                         alpha = 0.5, 
                         s = 0.1)
learner_xgboost <- lrn("regr.xgboost",
                       nrounds = 1000,
                       max_depth = 6,
                       eta = 0.01)