# creating the data set
income <- c(6,8,10,13,15,20,25,30,35,40)
Ni <- c(40,50,60,80,100,70,65,50,40,25)
ni <- c(8,12,18,23,45,36,39,33,30,20)
dataTemp <- data.frame(cbind(income,Ni,ni))
# printing the data set
dataTemp
## income Ni ni
## 1 6 40 8
## 2 8 50 12
## 3 10 60 18
## 4 13 80 23
## 5 15 100 45
## 6 20 70 36
## 7 25 65 39
## 8 30 50 33
## 9 35 40 30
## 10 40 25 20
log(p/1-p)
# calculating probability
Pi <- (ni/Ni)
# calculating odd ratio
Odds <- Pi/(1-Pi)
# calculating Log Odds Ratio
LogOdds <- log(Odds)
# fitting the model
Logit <- lm(LogOdds ~ income,
data = dataTemp)
# summary of the model
summary(Logit)
##
## Call:
## lm(formula = LogOdds ~ income, data = dataTemp)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.23736 -0.11364 -0.02464 0.09579 0.30791
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.720731 0.112400 -15.31 3.29e-07 ***
## income 0.080810 0.004862 16.62 1.74e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.1728 on 8 degrees of freedom
## Multiple R-squared: 0.9719, Adjusted R-squared: 0.9683
## F-statistic: 276.2 on 1 and 8 DF, p-value: 1.736e-07