MyNixOS website logo
Description

Additional Families for Generalized Linear Models.

Creates family objects identical to stats family but for new links.

extendedFamily

R-CMD-check Codecov testcoverage CRANstatus

extendedFamily adds new links to R’s generalized linear models. These families are drop in additions to existing families.

Links:

  • loglog
  • logc
  • identity
  • odds-power

Logit and Loglog: Mathematical Comparison

For the binomial family, the link is usually the logit but there are other options. The loglog model assigns a lower probability for X ranging from -5 to 2. For X over 2, the models are essentially indistinguishable. This can lead to improved performance when the response rate is much lower than 50%.

Logit and Loglog: Model Performance on Real World Data

The heart data contains info on 4,483 heart attack victims. The goal is to predict if a patient died in the next 48 hours following a myocardial infarction. The low death rate makes this dataset a good candidate for the loglog link.

data(heart)

heart %>%
  summarise(deathRate = mean(death))
#>    deathRate
#> 1 0.03925942

Only the family object needs to change to use the loglog link.

glmLogit <- glm(
  formula = death ~ anterior + hcabg + kk2 + kk3 + kk4 + age2 + age3 + age4,
  data = heart, family = binomial(link = "logit")
)
glmLoglog <- glm(
  formula = death ~ anterior + hcabg + kk2 + kk3 + kk4 + age2 + age3 + age4,
  data = heart, family = binomialEF(link = "loglog")
)

AUC improved by changing the link.

predictions <- heart %>%
  select(death) %>%
  mutate(
    death = factor(death, levels = c("0", "1")),
    logitProb = predict(object = glmLogit, newdata = heart, type = "response"),
    loglogProb = predict(object = glmLoglog, newdata = heart, type = "response")
  )

roc_auc(data = predictions, truth = death, event_level = "second", logitProb)
#> # A tibble: 1 × 3
#>   .metric .estimator .estimate
#>   <chr>   <chr>          <dbl>
#> 1 roc_auc binary         0.797

roc_auc(data = predictions, truth = death, event_level = "second", loglogProb)
#> # A tibble: 1 × 3
#>   .metric .estimator .estimate
#>   <chr>   <chr>          <dbl>
#> 1 roc_auc binary         0.801

Tidymodels

The family objects integrate with Tidymodels.

library(tidymodels)

heart <- heart %>%
  mutate(death = factor(death, levels = c("0", "1")))

parsnip_fit <-
  logistic_reg() %>%
  set_engine("glm", family = binomialEF("loglog")) %>%
  fit(death ~ anterior + hcabg + kk2 + kk3 + kk4 + age2 + age3 + age4, data = heart)

testPredictions <- parsnip_fit %>%
  predict(new_data = heart, type = "prob")
testPredictions <- heart %>%
  select(death) %>%
  bind_cols(testPredictions)

testPredictions %>%
  roc_auc(truth = death, event_level = "second", .pred_1)
#> # A tibble: 1 × 3
#>   .metric .estimator .estimate
#>   <chr>   <chr>          <dbl>
#> 1 roc_auc binary         0.801
Metadata

Version

0.2.4

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows