LogOddsToProb: Convert log odds to probability

Description Usage Arguments Value Examples

View source: R/log_odds_to_prob.r

Description

Logistic regression can tell you the log odds of the outcome occurring for each observation. In particular, broom::augment will add a column .fitted to your df with the log odds. Often you'll want to know the probability rather than log odds. This transforms a log odds into probability. You can get the same values using predict(f, df, type='response').

Usage

1

Arguments

x

vector of log odds

Value

vector with probabilities

Examples

1
2
3
4
5
6
f = glm(Species == 'versicolor' ~ ., data=iris, family=binomial) 
df = broom::augment(f, iris)
df$.prob = LogOddsToProb(df$.fitted)
plot(df$.prob, df$Species == 'versicolor')

all(dplyr::near(df$.prob, predict(f, iris, type='response')))  # same thing as using predict()

petersmittenaar/peterr documentation built on Feb. 13, 2021, 9:20 p.m.