#4.4 For the snoring and heart disease data of Table 3.1 (Section 3.2.3) with snoring-level scores (0, 2, 4, 5), the logistic regression ML fit is logit[ ˆ P(Y = 1)] = −3.866 +0.397x. Interpret the effect of snoring on the odds of heart disease.

#defining variables
inter=-3.866
beta.hat<-0.397

#computing effect of snoring
eff0<-exp(inter+(beta.hat*(0)))/(1+(exp(inter+(beta.hat*(0)))))
eff2<-exp(inter+(beta.hat*(2)))/(1+(exp(inter+(beta.hat*(2)))))
eff4<-exp(inter+(beta.hat*(4)))/(1+(exp(inter+(beta.hat*(4)))))
eff5<-exp(inter+(beta.hat*(5)))/(1+(exp(inter+(beta.hat*(5)))))


eff0 #non snorers
## [1] 0.0205124
eff2 #occasional snorers
## [1] 0.04427712
eff4 #those who snore nearly every night
## [1] 0.09296146
eff5 #hose who always snore
## [1] 0.1322741

The estimated probability of heart disease for non snores is 0.02 The estimated probability of heart disease for occasional snorers 0.044 The estimated probability of heart disease for those who snore nearly every night 0.09 The estimated probability of heart disease for those who always snore 0.13

#Q4.6 For Exercise 3.9 on travel credit cards, use the logistic output there to (a) interpret the effect of income on the odds of possessing a travel credit card, and conduct

We have for probability $(x), that an adult has a travel credit card of income x (in thousands of euros), is given by the function: logit(pi-hat)= -3.5179 +0.1054x The median effective level at which the \(\hat{pi}\)=0.5 is

## [1] 33.38

(b) a significance test For the logistic regression model, H0: β = 0 states that the probability of success is independent of x (income in thousands of euros)

#Wald test statistic
wald.test=betahat/se
wald.test
## [1] 4.022901
 2*pnorm(-abs(wald.test)) #two sided p-value
## [1] 5.748572e-05

We reject the null hypothesis of

(c) a confidence interval for that effect.

#Wald confidence interval
LL<-betahat-(z*se)
UL<-betahat+(z*se)
ll<-exp(LL)
ul<-exp(UL)
cbind(ll,ul)
##            ll       ul
## [1,] 1.055535 1.169705

the multiplicative effect on the odds of a 1-unit increase in x (income in thousands of euros)

#Q.4.8

For the Crabs data file at the text website, fit the logistic regression model for the probability of a satellite (y = 1) using x = weight as the sole explanatory variable.

Crabs <- read.table("http://www.stat.ufl.edu/~aa/cat/data/Crabs.dat",header=TRUE)
head(Crabs)
##   crab sat y weight width color spine
## 1    1   8 1   3.05  28.3     2     3
## 2    2   0 0   1.55  22.5     3     3
## 3    3   9 1   2.30  26.0     1     1
## 4    4   0 0   2.10  24.8     3     3
## 5    5   4 1   2.60  26.0     3     3
## 6    6   0 0   2.10  23.8     2     3
  1. Report the ML prediction equation. At the mean weight value of 2.437 kg, give a linear approximation for the estimated effect of logit[P(Y = 1)] = α + βx, logit[P(Y = 1)] = -3.6947 + 1.8151 x,
library(gam)
## Warning: package 'gam' was built under R version 4.1.3
## Loading required package: splines
## Loading required package: foreach
## Loaded gam 1.20.1
fit <- glm(y ~ weight, family=binomial, data=Crabs) # link=logit is default
summary(fit)
## 
## Call:
## glm(formula = y ~ weight, family = binomial, data = Crabs)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -2.1108  -1.0749   0.5426   0.9122   1.6285  
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept)  -3.6947     0.8802  -4.198 2.70e-05 ***
## weight        1.8151     0.3767   4.819 1.45e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 225.76  on 172  degrees of freedom
## Residual deviance: 195.74  on 171  degrees of freedom
## AIC: 199.74
## 
## Number of Fisher Scoring iterations: 4
  1. a 1-kg increase in weight. This represents a relatively large increase, so convert this to the effect of

  2. a 0.10-kg increase,

  3. a standard deviation increase in weight (0.58 kg).

#mean weight value of 2.437
predict(fit, data.frame(weight =2.437 ), type="response")
##         1 
## 0.6745377
  1. Find and interpret the average marginal effect of weight per 0.10-kg increase.

  2. Construct the classification table using the sample proportion of y = 1 as the cutoff. Report the sensitivity and specificity. Interpret.

  3. Construct an ROC curve, and report and interpret the area under it.