The attached who.csv dataset contains real-world data from 2008. The variables included follow.

Load Dependencies and Data

## # A tibble: 6 × 10
##   Country   LifeExp InfantSurvival Under5Survival TBFree  PropMD  PropRN PersExp
##   <chr>       <dbl>          <dbl>          <dbl>  <dbl>   <dbl>   <dbl>   <dbl>
## 1 Afghanis…      42          0.835          0.743  0.998 2.29e-4 5.72e-4      20
## 2 Albania        71          0.985          0.983  1.00  1.14e-3 4.61e-3     169
## 3 Algeria        71          0.967          0.962  0.999 1.06e-3 2.09e-3     108
## 4 Andorra        82          0.997          0.996  1.00  3.30e-3 3.5 e-3    2589
## 5 Angola         41          0.846          0.74   0.997 7.04e-5 1.15e-3      36
## 6 Antigua …      73          0.99           0.989  1.00  1.43e-4 2.77e-3     503
## # ℹ 2 more variables: GovtExp <dbl>, TotExp <dbl>

Question 1

Provide a scatter plot of LifeExp~TotExp, and run simple linear regression. Do not transform the variables. Provide and interpret the F statistics, R^2, standard error,and p-values only. Discuss whether the assumptions of simple linear regression met.

ggplot(data = hw_dataset, aes(x = TotExp, y = LifeExp)) +
  geom_point() +
  theme_minimal()

exp_lm <- lm(LifeExp ~ TotExp, data = hw_dataset)
summary(exp_lm)
## 
## Call:
## lm(formula = LifeExp ~ TotExp, data = hw_dataset)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -24.764  -4.778   3.154   7.116  13.292 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 6.475e+01  7.535e-01  85.933  < 2e-16 ***
## TotExp      6.297e-05  7.795e-06   8.079 7.71e-14 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.371 on 188 degrees of freedom
## Multiple R-squared:  0.2577, Adjusted R-squared:  0.2537 
## F-statistic: 65.26 on 1 and 188 DF,  p-value: 7.714e-14

Question 2

Raise life expectancy to the 4.6 power (i.e., LifeExp^4.6). Raise total expenditures to the 0.06 power (nearly a log transform, TotExp^.06). Plot LifeExp^4.6 as a function of TotExp^.06, and re-run the simple regression model using the transformed variables. Provide and interpret the F statistics, R^2, standard error, and p-values. Which model is “better?”

new_dataset <- hw_dataset %>%
  mutate(LifeExp_New = LifeExp^4.6,
         TotExp_New = TotExp^.06)

# plot
ggplot(data = new_dataset, aes(x = TotExp_New, y = LifeExp_New)) +
  geom_point() +
  theme_minimal()

exp_lm_new <- lm(LifeExp_New ~ TotExp_New, data = new_dataset)
summary(exp_lm_new)
## 
## Call:
## lm(formula = LifeExp_New ~ TotExp_New, data = new_dataset)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -308616089  -53978977   13697187   59139231  211951764 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -736527910   46817945  -15.73   <2e-16 ***
## TotExp_New   620060216   27518940   22.53   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 90490000 on 188 degrees of freedom
## Multiple R-squared:  0.7298, Adjusted R-squared:  0.7283 
## F-statistic: 507.7 on 1 and 188 DF,  p-value: < 2.2e-16
par(mfrow=c(2,2))
plot(exp_lm_new)

Question 3

Using the results from 3, forecast life expectancy when TotExp^.06 =1.5. Then forecast life expectancy when TotExp^.06=2.5.

expected_TotExp1 <- 1.5

intercept_value <- abs(summary(exp_lm_new)$coefficients[1,1])
TotExp_estimate <- summary(exp_lm_new)$coefficients[2,1]

forcast_value_1 <- (intercept_value + TotExp_estimate * expected_TotExp1)^(1/4.6)

forcast_value_1
## [1] 101.099
expected_TotExp2 <- 2.5

forcast_value_2 <- (intercept_value + TotExp_estimate * expected_TotExp2)^(1/4.6)

forcast_value_2
## [1] 108.2953

Question 4

Build the following multiple regression model and interpret the F Statistics, R^2, standard error, and p-values. How good is the model?

LifeExp = b0+b1 x PropMd + b2 x TotExp +b3 x PropMD x TotExp

multi_lm <- lm(LifeExp ~ PropMD + TotExp + PropMD:TotExp, data = hw_dataset)

summary(multi_lm)
## 
## Call:
## lm(formula = LifeExp ~ PropMD + TotExp + PropMD:TotExp, data = hw_dataset)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -27.320  -4.132   2.098   6.540  13.074 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    6.277e+01  7.956e-01  78.899  < 2e-16 ***
## PropMD         1.497e+03  2.788e+02   5.371 2.32e-07 ***
## TotExp         7.233e-05  8.982e-06   8.053 9.39e-14 ***
## PropMD:TotExp -6.026e-03  1.472e-03  -4.093 6.35e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 8.765 on 186 degrees of freedom
## Multiple R-squared:  0.3574, Adjusted R-squared:  0.3471 
## F-statistic: 34.49 on 3 and 186 DF,  p-value: < 2.2e-16
par(mfrow=c(2,2))
plot(multi_lm)
## Warning in sqrt(crit * p * (1 - hh)/hh): NaNs produced

## Warning in sqrt(crit * p * (1 - hh)/hh): NaNs produced

Question 5

Forecast LifeExp when PropMD=.03 and TotExp = 14. Does this forecast seem realistic? Why or why not?

expected_PropMD <- .03
expected_TotExp3 <- 14

intercept_value_multi <- abs(summary(multi_lm)$coefficients[1,1])
Prop_MD_estimate_multi <- summary(multi_lm)$coefficients[2,1]
TotExp_estimate_multi <- summary(multi_lm)$coefficients[3,1]
Prop_MD_TotalExp_multi <- summary(multi_lm)$coefficients[4,1]

forcast_value_3 <- (intercept_value_multi + Prop_MD_estimate_multi * expected_PropMD + TotExp_estimate_multi * expected_TotExp3) - (Prop_MD_TotalExp_multi * expected_PropMD * expected_TotExp3) 

forcast_value_3
## [1] 107.7011