inv_logit: Inverse logit function

View source: R/inv_logit.R

inv_logitR Documentation

Inverse logit function

Description

Given a numeric object return the inverse logit of the values. Code adapted from the boot package.

Usage

inv_logit(logit)

Arguments

logit

A numeric object. Missing values (NAs) are allowed.

Details

The inverse logit is defined by exp(logit) / (1 + exp(logit)). Values in x of -Inf or Inf return logits of 0 or 1 respectively. Any NAs in the input will also be NAs in the output.

Value

An object of the same type as logit containing the inverse logits of the input values.

Examples

library(dplyr)
library(tibble)
library(titanic)
data(titanic_train, package = "titanic")
d <- titanic_train  # less typing
glm1 <- glm(Survived ~ Pclass, data = d, family = "binomial")
betas <- coef(glm1)

d <- d %>%
  tibble::as_tibble() %>%
  mutate(logit = betas[1] + betas[2] * Pclass,
         prob = inv_logit(logit = logit))

(preds <- predict(glm1, newdata = d, type = "response"))

d$prob == preds

emilelatour/lamisc documentation built on April 9, 2024, 10:33 a.m.