Introduction

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

Country: name of the country LifeExp: average life expectancy for the country in years InfantSurvival: proportion of those surviving to one year or more Under5Survival: proportion of those surviving to five years or more TBFree: proportion of the population without TB. PropMD: proportion of the population who are MDs PropRN: proportion of the population who are RNs PersExp: mean personal expenditures on healthcare in US dollars at average exchange rate GovtExp: mean government expenditures per capita on healthcare, US dollars at average exchange rate TotExp: sum of personal and government expenditures.

library(RCurl)
## Warning: package 'RCurl' was built under R version 3.6.2
library(ggplot2)

file_url <- getURL("https://raw.githubusercontent.com/jey1987/DATA605/master/who.csv")
df_input <- read.csv(text=file_url,header=TRUE)

Question 1

Provide a scatterplot 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.

Plots

plot(df_input$LifeExp~df_input$TotExp)

lm_life <- lm(df_input$LifeExp~df_input$TotExp)
summary(lm_life)
## 
## Call:
## lm(formula = df_input$LifeExp ~ df_input$TotExp)
## 
## 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 ***
## df_input$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
par(mfrow=c(2,2))
plot(lm_life)
abline(lm_life)

Measure

F-Statistics = 65.26

R-Square = 0.2537

Standard Error = 9.371

p-values = 7.714e-14

Interpretation

Based on the following conditions of Linear Regression, We can conclude that the data is not providing strong relationship.

Linearity - The data is non-linear as the residuals are not following theoretical line.

Homoscedasticity - From Scale location plot we can see that the line is not horizontal and angled. This explains the homoscedasticity is not satisfied.

Independence - Life Expectancy and Total Expenditure are both independent variables

Normality - By looking at the QQ Plot we can see that the data is not distributed normally

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 r 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?”

Plots

df_input$LifeExp = df_input$LifeExp^4.6
df_input$TotExp = df_input$TotExp^0.06

plot(df_input$LifeExp~df_input$TotExp)

lm_life <- lm(df_input$LifeExp~df_input$TotExp)
summary(lm_life)
## 
## Call:
## lm(formula = df_input$LifeExp ~ df_input$TotExp)
## 
## 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 ***
## df_input$TotExp  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(lm_life)
abline(lm_life)

Measure

F-Statistics = 507.7

R-Square = 0.7283

Standard Error = 90490000

p-values = < 2.2e-16

Interpretation

Based on the following conditions of Linear Regression, We can conclude that the data is not providing strong relationship.

Linearity - The data is linear as the residuals are following theoretical line.

Homoscedasticity - From Scale location plot we can see that the line is horizontal and not angled. This explains the homoscedasticity is satisfied.

Independence - Life Expectancy and Total Expenditure are independent variables

Normality - By looking at the QQ Plot we can see that the data is distributed normally

By comparing the conditions of linear regression, We can say that Model 2 is better than 1

Question 3

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

mod <- lm(LifeExp~TotExp,data=df_input)
newd <- data.frame(TotExp=c(1.5,2.5))
predict(mod, newd, interval="predict")^(1/4.6)
##        fit      lwr      upr
## 1 63.31153 35.93545 73.00793
## 2 86.50645 81.80643 90.43414

The Life Expectancy is forecasted at 63 years.

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

file_url <- getURL("https://raw.githubusercontent.com/jey1987/DATA605/master/who.csv")
df_input <- read.csv(text=file_url,header=TRUE)

mod_new <- lm(LifeExp ~ PropMD + TotExp + PropMD * TotExp,data=df_input)
summary(mod_new)
## 
## Call:
## lm(formula = LifeExp ~ PropMD + TotExp + PropMD * TotExp, data = df_input)
## 
## 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(mod_new)
## Warning in sqrt(crit * p * (1 - hh)/hh): NaNs produced

## Warning in sqrt(crit * p * (1 - hh)/hh): NaNs produced
abline(mod_new)
## Warning in abline(mod_new): only using the first two of 4 regression
## coefficients

Measure

F-Statistics = 34.49

R-Square = 0.3471

Standard Error = 8.765

p-values = < 2.2e-16

Interpretation

Based on the following conditions of Linear Regression, We can conclude that the data is not providing strong relationship.

Linearity - The data is non-linear as the residuals are not following theoretical line.

Homoscedasticity - From Scale location plot we can see that the line is not horizontal and angled. This explains the homoscedasticity is not satisfied.

Independence - Life Expectancy and Total Expenditure are both independent variables

Normality - By looking at the QQ Plot we can see that the data is not distributed normally

Question 5

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

newd <- data.frame(PropMD=0.03,TotExp=14)
predict(mod_new, newd, interval="predict")
##       fit      lwr      upr
## 1 107.696 84.24791 131.1441

The Life Expectancy is forecasted at 107 years, this seems not possible considering the average life of humans is ~ 70.