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.
WHO <- read.csv("~/Dropbox/Data/Data 605/who.csv", header = TRUE, stringsAsFactors = FALSE)
head(WHO)
##               Country LifeExp InfantSurvival Under5Survival  TBFree
## 1         Afghanistan      42          0.835          0.743 0.99769
## 2             Albania      71          0.985          0.983 0.99974
## 3             Algeria      71          0.967          0.962 0.99944
## 4             Andorra      82          0.997          0.996 0.99983
## 5              Angola      41          0.846          0.740 0.99656
## 6 Antigua and Barbuda      73          0.990          0.989 0.99991
##        PropMD      PropRN PersExp GovtExp TotExp
## 1 0.000228841 0.000572294      20      92    112
## 2 0.001143127 0.004614439     169    3128   3297
## 3 0.001060478 0.002091362     108    5184   5292
## 4 0.003297297 0.003500000    2589  169725 172314
## 5 0.000070400 0.001146162      36    1620   1656
## 6 0.000142857 0.002773810     503   12543  13046
who.lm <- lm(LifeExp ~ TotExp, data = WHO)
who.lm
## 
## Call:
## lm(formula = LifeExp ~ TotExp, data = WHO)
## 
## Coefficients:
## (Intercept)       TotExp  
##   6.475e+01    6.297e-05
summary(who.lm)
## 
## Call:
## lm(formula = LifeExp ~ TotExp, data = WHO)
## 
## 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
plot(WHO$LifeExp ~ WHO$TotExp, xlab = "Personal and Government Expenditures", ylab = "Life Expectancy")

\(y(LifeExp) = 64.75 + 6.297e-05 * TotExp\)

F Stats = 1 regression degree of freedom and 188 residual degrees of freedom is 65.26. R-Squared Value is \(0.2577\). This tells us that only 25.77% of our data is accounted for in this model. Not a significant amount. Standard Error is \(6.297e-05\) P-Values are \(2e-16\) and \(7.71e-14\). Both values are close to 0, making them significant.

qqnorm(who.lm$residuals)
qqline(who.lm$residuals)

hist(who.lm$residuals)

  1. 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?”
life_exp4.6 <- WHO$LifeExp^4.6
tot_exp0.06 <- WHO$TotExp^.06

plot(life_exp4.6 ~ tot_exp0.06, xlab = "Personal and Government Expenditures transformed by ^.06", ylab = "Life Expectancy transformed by ^4.6")

who.lm.2 <- lm(life_exp4.6 ~ tot_exp0.06)
summary(who.lm.2)
## 
## Call:
## lm(formula = life_exp4.6 ~ tot_exp0.06)
## 
## 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 ***
## tot_exp0.06  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
who.lm.2
## 
## Call:
## lm(formula = life_exp4.6 ~ tot_exp0.06)
## 
## Coefficients:
## (Intercept)  tot_exp0.06  
##  -736527909    620060216

\(y(LifeExp) = -736527909 + 620060216 * TotExp\)

F Stats = 1 regression degree of freedom and 188 residual degrees of freedom is 507.7. R-Squared Value is \(0.7298\). This tells us that 72.98% of our data is accounted for in this model. A big improvement from the last model. Standard Error is \(620060216\) P-Values are both \(<2e-16\). Both values are close to 0, making them significant.

qqnorm(who.lm.2$residuals)
qqline(who.lm.2$residuals)

hist(who.lm.2$residuals)

  1. Using the results from 2, forecast life expectancy when TotExp^.06 =1.5. Then forecast life expectancy when TotExp^.06=2.5
TotExp <- 1.5
results <- -736527909  + 620060216 * TotExp
results <- results ^(1/4.6)
results
## [1] 63.31153

Forcast for life expectancy is 63.31 when Total Expenditure is 1.5

TotExp = 2.5
results <- -736527909  + 620060216 * TotExp
results <- results^(1/4.6)
results
## [1] 86.50645

Forcast for life expectancy is 86.51 when Total Expenditure is 2.5

  1. 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 * PropMd + b2 * TotExp +b3 * PropMD * TotExp\)
who.multreg <- lm(LifeExp ~ PropMD * TotExp + PropMD * TotExp, data=WHO)
who.multreg
## 
## Call:
## lm(formula = LifeExp ~ PropMD * TotExp + PropMD * TotExp, data = WHO)
## 
## Coefficients:
##   (Intercept)         PropMD         TotExp  PropMD:TotExp  
##     6.277e+01      1.497e+03      7.233e-05     -6.026e-03
summary(who.multreg)
## 
## Call:
## lm(formula = LifeExp ~ PropMD * TotExp + PropMD * TotExp, data = WHO)
## 
## 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

$y(LifeExp) = 62.77 + 1.497e+03 * PropMD + 7.233e-05 * TotExp + -6.026e-03(PropMDTotExp)

F Stats = 3 regression degree of freedom on 186 is 34.49. R-Squared Value is \(0.3574\). This tells us that 35.74% of our data is accounted for in this model. The P-Values are 2e-16, 2.32e-07, 9.39e-14, 6.35e-05, which are all very close to zero. Stardard errors are 2.788e+02, 8.982e-06, 1.472e-03

  1. Forecast LifeExp when PropMD=.03 and TotExp = 14. Does this forecast seem realistic? Why or why not?
TotExp <- 14
PropMD <- .03
results <- 62.77  +  1.497e+03 * PropMD + 7.233e-05 * TotExp + -6.026e-03*(PropMD*TotExp) 
results
## [1] 107.6785

By comparing the percentage of population who are doctors to the total life expetancy does not seem realistic. This would assume that the population had access to these doctors, which is not always the case.