Question1

  1. Assumptions of binomial
load("CS1policies.RData")
names(CS1policies)
## [1] "age"      "duration" "claimed"
model1<-glm(claimed~age,data = CS1policies,family = binomial)
summary(model1)
## 
## Call:
## glm(formula = claimed ~ age, family = binomial, data = CS1policies)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -0.8276  -0.7386  -0.6711  -0.6086   1.8960  
## 
## Coefficients:
##              Estimate Std. Error z value Pr(>|z|)    
## (Intercept) -2.336974   0.420104  -5.563 2.65e-08 ***
## age          0.024023   0.009069   2.649  0.00807 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1058.9  on 999  degrees of freedom
## Residual deviance: 1051.8  on 998  degrees of freedom
## AIC: 1055.8
## 
## Number of Fisher Scoring iterations: 4
options(scipen=999)
anova(model1, test = "LRT")
## Analysis of Deviance Table
## 
## Model: binomial, link: logit
## 
## Response: claimed
## 
## Terms added sequentially (first to last)
## 
## 
##      Df Deviance Resid. Df Resid. Dev Pr(>Chi)   
## NULL                   999     1058.9            
## age   1   7.0772       998     1051.8 0.007807 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
model2<-glm(claimed~duration, data = CS1policies, family = binomial)
summary(model2)
## 
## Call:
## glm(formula = claimed ~ duration, family = binomial, data = CS1policies)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.2013  -0.7483  -0.4978  -0.3333   2.4243  
## 
## Coefficients:
##              Estimate Std. Error z value            Pr(>|z|)    
## (Intercept)  0.390062   0.171760   2.271              0.0231 *  
## duration    -0.027608   0.002864  -9.641 <0.0000000000000002 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1058.86  on 999  degrees of freedom
## Residual deviance:  948.98  on 998  degrees of freedom
## AIC: 952.98
## 
## Number of Fisher Scoring iterations: 4

+intercept = 0.390062 +slope(duration) = -0.027607

model3<-glm(claimed~age+duration, CS1policies, family = binomial)
summary(model3)
## 
## Call:
## glm(formula = claimed ~ age + duration, family = binomial, data = CS1policies)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.3639  -0.7387  -0.4894  -0.3058   2.5370  
## 
## Coefficients:
##              Estimate Std. Error z value             Pr(>|z|)    
## (Intercept) -0.909944   0.458663  -1.984              0.04727 *  
## age          0.029434   0.009630   3.057              0.00224 ** 
## duration    -0.028040   0.002883  -9.725 < 0.0000000000000002 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1058.86  on 999  degrees of freedom
## Residual deviance:  939.51  on 997  degrees of freedom
## AIC: 945.51
## 
## Number of Fisher Scoring iterations: 5
  1. +MOdel3
    • AIC = 945.51
    • residual deviance = 939.51

Model3 has a lower AIC and residual deviance than model 1 and 2 hence model 3 is better conjecture

Question 2

load("heights.Rdata")
plot(heights)

+there is no relationship between father.height and mother.height

options(scipen=999)
m1<-lm(daughter.height~mother.height+father.height, heights)
summary(m1)
## 
## Call:
## lm(formula = daughter.height ~ mother.height + father.height, 
##     data = heights)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.8805 -0.6942  0.5915  0.8651  3.3138 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     7.4543    10.8804   0.685    0.503    
## mother.height   0.7072     0.1289   5.488  0.00004 ***
## father.height   0.1636     0.1266   1.293    0.213    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.94 on 17 degrees of freedom
## Multiple R-squared:  0.6752, Adjusted R-squared:  0.637 
## F-statistic: 17.67 on 2 and 17 DF,  p-value: 0.00007057

\[y=7.4543+0.7072mother.height+0.1636father.height\]

plot(m1,1)

new_data<-data.frame(mother.height=61,father.height=63)
predict(m1,new_data,level = 0.95,interval = "predict")
##       fit      lwr      upr
## 1 60.9025 56.42272 65.38228