inv_logit | R Documentation |
Given a numeric object return the inverse logit of the values. Code adapted
from the boot
package.
inv_logit(logit)
logit |
A numeric object. Missing values (NAs) are allowed. |
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 NA
s in the input will also be NA
s
in the output.
An object of the same type as logit
containing the inverse logits of the input values.
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.