1.

Using the “swiss” dataset, build the best multiple regression model you can for the variable Fertility.

swiss_data <- datasets::swiss
summary(swiss_data)
##    Fertility      Agriculture     Examination      Education    
##  Min.   :35.00   Min.   : 1.20   Min.   : 3.00   Min.   : 1.00  
##  1st Qu.:64.70   1st Qu.:35.90   1st Qu.:12.00   1st Qu.: 6.00  
##  Median :70.40   Median :54.10   Median :16.00   Median : 8.00  
##  Mean   :70.14   Mean   :50.66   Mean   :16.49   Mean   :10.98  
##  3rd Qu.:78.45   3rd Qu.:67.65   3rd Qu.:22.00   3rd Qu.:12.00  
##  Max.   :92.50   Max.   :89.70   Max.   :37.00   Max.   :53.00  
##     Catholic       Infant.Mortality
##  Min.   :  2.150   Min.   :10.80   
##  1st Qu.:  5.195   1st Qu.:18.15   
##  Median : 15.140   Median :20.00   
##  Mean   : 41.144   Mean   :19.94   
##  3rd Qu.: 93.125   3rd Qu.:21.70   
##  Max.   :100.000   Max.   :26.60
swiss_model <- lm(Fertility ~ ., data = swiss_data)
summary(swiss_model)
## 
## Call:
## lm(formula = Fertility ~ ., data = swiss_data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -15.2743  -5.2617   0.5032   4.1198  15.3213 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      66.91518   10.70604   6.250 1.91e-07 ***
## Agriculture      -0.17211    0.07030  -2.448  0.01873 *  
## Examination      -0.25801    0.25388  -1.016  0.31546    
## Education        -0.87094    0.18303  -4.758 2.43e-05 ***
## Catholic          0.10412    0.03526   2.953  0.00519 ** 
## Infant.Mortality  1.07705    0.38172   2.822  0.00734 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 7.165 on 41 degrees of freedom
## Multiple R-squared:  0.7067, Adjusted R-squared:  0.671 
## F-statistic: 19.76 on 5 and 41 DF,  p-value: 5.594e-10

\[\hat{y_{i}} = \beta_{0} + \beta_{1}X_{1} + \beta_{2}X_{2} +\ ...\ + \beta_{n}X_{n}\]

The intercept (β0 = 66.9152) is the baseline fertility rate if all predictor values were zero.

\[\widehat{Fertility_{i}} = 66.9152 - 0.1721(Agriculture_{i}) - 0.2580(Examination_{i}) - 0.8709(Education_{i}) + \\ 0.1041(Catholic_{i}) + 1.0771(Infant.Mortality_{i})\]

The slope coefficient (β1 = -0.1721) for the agriculture variable indicates that as the male population involved in agriculture increases by one percentage unit, the fertility rate decreases by 0.1721. Given its p-value of 0.01873, we can determine that the relationship between agriculture involvement and the fertility rate is statistically significant.

The slope coefficient (β2 = -0.2580) for the examination variable indicates that as the number of military draftees that receive the highest marks on the army examination increases by one percentage unit, the fertility rate decreases by 0.2580. Given its p-value of 0.3155, we can determine that the relationship between army examination results and the fertility rate is not statistically significant.

The slope coefficient (β3 = -0.8709) for the education variable indicates that as the number of draftees that received education beyond primary school increases by one percentage unit, the fertility rate decreases by 0.8709. Given its p-value of 2.43 x 10-5, we can determine that the relationship between education and the fertility rate is very statistically significant.

The slope coefficient (β4 = 0.1041) for the Catholic variable indicates that as the number of individuals within a province’s population that identifies as Catholic increases by one percentage unit, the fertility rate increases by 0.1041. Given its p-value of 0.00519, we can determine that the relationship between Catholicism and the fertility rate is statistically significant.

The slope coefficient (β5 = 1.0771) for the infant mortality variable indicates that as the number of live births who survive less than one year increases by one percentage unit, the fertility rate increases by 1.0771. Given its p-value of 0.00734, we can determine that the relationship between infant mortality and the fertility rate is statistically significant.

Overall, the relationship across all variables in the regression model is statistically significant given its p-value of 5.594 x 10-10. However, the adjusted R2 value is only 0.671, which could likely be severely impacted by the inclusion of the not statistically significant examination variable.

2.

Then build a logistic regression model for predicting Fertility>70.0. Post your solutions, interpretation, and code for your peers to see.

high_fertility <- ifelse(swiss_data$Fertility > 70.0, 1, 0)

logistic_model <- glm(high_fertility ~ Agriculture + Examination + Education + Catholic + Infant.Mortality, data = swiss_data, family = binomial)
summary(logistic_model)
## 
## Call:
## glm(formula = high_fertility ~ Agriculture + Examination + Education + 
##     Catholic + Infant.Mortality, family = binomial, data = swiss_data)
## 
## Coefficients:
##                  Estimate Std. Error z value Pr(>|z|)  
## (Intercept)       4.82826    5.25607   0.919   0.3583  
## Agriculture      -0.09615    0.04011  -2.397   0.0165 *
## Examination      -0.32116    0.13844  -2.320   0.0203 *
## Education        -0.12078    0.08610  -1.403   0.1607  
## Catholic          0.02078    0.01376   1.509   0.1312  
## Infant.Mortality  0.29078    0.21051   1.381   0.1672  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 65.135  on 46  degrees of freedom
## Residual deviance: 32.887  on 41  degrees of freedom
## AIC: 44.887
## 
## Number of Fisher Scoring iterations: 6

The most significant predictors of whether a province has a fertility rate over 70.0 are agriculture involvement (Pr(>|z|) = 0.0165) and army examination results (Pr(>|z|) = 0.0203). Both of these predictor variables are associated with a lower probability of a fertility rate over 70.0. This was kind of surprising since they were the least statistically significant variables in the multiple regression model. The deviance of the model decreasing from 65.135 for the null to 32.887 for the residual indicates that the fit of the model increases with the addition of the predictor variables.