You can use the log() function in R to calculate the log and the exp() function to calculate $$e^x$$. For example, if I wanted to calculate log(10), I would run:

log(10)
## [1] 2.302585

If I wanted to calculate $$e^10$$, I would run:

exp(10)
## [1] 22026.47

If I wanted to calculate $$e^{log(10)}$$, I would run:

exp(log(10))
## [1] 10

## The probability of an event occuring is 0.5, calculate the odds.

0.5 / (1 - 0.5)
## [1] 1

## The probability of an event occuring is 0.25, calculate the odds.

0.25 / (1 - 0.25)
## [1] 0.3333333

## The probability of an event occuring is 0.9, calculate the log(odds)

log(.9 / (1 - .9))
## [1] 2.197225

## The odds of an event are 2:1, calculate the probability.

2 / (1 + 2)
## [1] 0.6666667

## The odds of an event are 1:5, calculate the probability.

(1 / 5) / (1 + (1 / 5))
## [1] 0.1666667

## Using the following model: log(odds) = 0.2 + 2 x, what is the log(odds) given x is 1

0.2 + 2 * 1
## [1] 2.2

## Using the same model, what is the probability that the Outcome is Yes (1), given x is 1?

exp(0.2 + 2 * 1) / (1 + exp(0.2 + 2 * 1))
## [1] 0.9002495
library(Stat2Data)
library(tidyverse)
library(broom)
data("MedGPA")
glimpse(MedGPA)
## Observations: 55
## Variables: 11
## $Accept <fct> D, A, A, A, A, A, A, D, A, A, A, A, A, D, D, A, D, A,… ##$ Acceptance <int> 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1,…
## $Sex <fct> F, M, F, F, F, M, M, M, F, F, F, F, M, M, M, F, M, M,… ##$ BCPM       <dbl> 3.59, 3.75, 3.24, 3.74, 3.53, 3.59, 3.85, 3.26, 3.74,…
## $GPA <dbl> 3.62, 3.84, 3.23, 3.69, 3.38, 3.72, 3.89, 3.34, 3.71,… ##$ VR         <int> 11, 12, 9, 12, 9, 10, 11, 11, 8, 9, 11, 11, 8, 9, 11,…
## $PS <int> 9, 13, 10, 11, 11, 9, 12, 11, 10, 9, 9, 8, 10, 9, 8, … ##$ WS         <int> 9, 8, 5, 7, 4, 7, 6, 8, 6, 6, 8, 4, 7, 4, 6, 8, 8, 9,…
## $BS <int> 9, 12, 9, 10, 11, 10, 11, 9, 11, 10, 11, 8, 10, 10, 7… ##$ MCAT       <int> 38, 45, 33, 40, 35, 36, 40, 39, 35, 34, 39, 31, 35, 3…
## $Apps <int> 5, 3, 19, 5, 11, 5, 5, 7, 5, 11, 6, 9, 5, 8, 15, 6, 6… ## Fit the appropriate model predicting MCAT from GPA lm(MCAT ~ GPA, data = MedGPA) %>% tidy() ## # A tibble: 2 x 5 ## term estimate std.error statistic p.value ## <chr> <dbl> <dbl> <dbl> <dbl> ## 1 (Intercept) 3.92 6.92 0.567 0.573 ## 2 GPA 9.10 1.94 4.69 0.0000197 glm(MCAT ~ GPA, data = MedGPA) %>% tidy() ## # A tibble: 2 x 5 ## term estimate std.error statistic p.value ## <chr> <dbl> <dbl> <dbl> <dbl> ## 1 (Intercept) 3.92 6.92 0.567 0.573 ## 2 GPA 9.10 1.94 4.69 0.0000197 glm(MCAT ~ GPA, data = MedGPA, family = gaussian) %>% tidy() ## # A tibble: 2 x 5 ## term estimate std.error statistic p.value ## <chr> <dbl> <dbl> <dbl> <dbl> ## 1 (Intercept) 3.92 6.92 0.567 0.573 ## 2 GPA 9.10 1.94 4.69 0.0000197 ## Fit the appropriate model predicting Accept from GPA levels(MedGPA$Accept)
## [1] "A" "D"
MedGPA <- MedGPA %>%
mutate(Accept = fct_relevel(Accept, c("D", "A")))

glm(Accept ~ GPA, data = MedGPA, family = binomial) %>%
tidy()
## # A tibble: 2 x 5
##   term        estimate std.error statistic  p.value
##   <chr>          <dbl>     <dbl>     <dbl>    <dbl>
## 1 (Intercept)   -19.2       5.63     -3.41 0.000644
## 2 GPA             5.45      1.58      3.45 0.000553

## How do you think you interpret the coefficient for GPA in the second model?

One unit change in GPA yields a 5.45 change in the log odds of acceptance to medical school.

## How can I change this from log odds to odds

exp(5.45)
## [1] 232.7582

One unite change in GPA yields a 232 change in the odds of acceptance to medical school