Skip to content

Instantly share code, notes, and snippets.

@primaryobjects
Created April 27, 2016 14:26
Show Gist options
  • Select an option

  • Save primaryobjects/2138d6fb1447d3f1be4a937e2def6dfc to your computer and use it in GitHub Desktop.

Select an option

Save primaryobjects/2138d6fb1447d3f1be4a937e2def6dfc to your computer and use it in GitHub Desktop.
Logistic regression intro formulas.
---
title: "Logistic Regression Intro"
output: html_document
---
Suppose the coefficients of a logistic regression model with two independent variables are as follows:
B0 = -1.5
B1 = 3
B2 = -0.5
And we have an observation with the following values for the independent variables:
x1 = 1
x2 = 5
```{r}
B <- c(-1.5, 3, -0.5)
x <- c(1, 5)
```
What is the value of the Logit for this observation? Recall that the Logit is log(Odds).
```{r}
logit <- B[1] + B[2]*x[1] + B[3]*x[2]
logit
```
What is the value of the Odds for this observation? Note that you can compute e^x, for some number x, in your R console by typing exp(x). The function exp() computes the exponential of its argument.
```{r}
exp(logit)
```
What is the value of P(y = 1) for this observation?
```{r}
1 / (1 + exp(-1 * logit))
```
Logistic Regression Intro
Suppose the coefficients of a logistic regression model with two independent variables are as follows: B0 = -1.5 B1 = 3 B2 = -0.5
And we have an observation with the following values for the independent variables: x1 = 1 x2 = 5
B <- c(-1.5, 3, -0.5)
x <- c(1, 5)
What is the value of the Logit for this observation? Recall that the Logit is log(Odds).
logit <- B[1] + B[2]*x[1] + B[3]*x[2]
logit
## [1] -1
What is the value of the Odds for this observation? Note that you can compute e^x, for some number x, in your R console by typing exp(x). The function exp() computes the exponential of its argument.
exp(logit)
## [1] 0.3678794
What is the value of P(y = 1) for this observation?
1 / (1 + exp(-1 * logit))
## [1] 0.2689414
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment