Load DAta

whoData <- read.csv('https://raw.githubusercontent.com/NNedd/DATA605/master/Assignment%2012/who.csv', stringsAsFactors = FALSE)

Part 1

plot(whoData[,"LifeExp"], whoData[,"TotExp"], main="Life Expectancy as a function of Total Expenditure", xlab = "Life Exectancy", ylab="Total Expenditure")

lfunction <- lm(whoData$LifeExp ~ whoData$TotExp)
lfunction
## 
## Call:
## lm(formula = whoData$LifeExp ~ whoData$TotExp)
## 
## Coefficients:
##    (Intercept)  whoData$TotExp  
##      6.475e+01       6.297e-05
summary(lfunction)
## 
## Call:
## lm(formula = whoData$LifeExp ~ whoData$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 ***
## whoData$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

Part 2

whoData$AdjLifeExp = whoData$LifeExp ^ 4.6
whoData$AdjTotExp = whoData$TotExp ^ 0.06

lfunction <- lm(whoData$AdjLifeExp ~ whoData$AdjTotExp)
lfunction
## 
## Call:
## lm(formula = whoData$AdjLifeExp ~ whoData$AdjTotExp)
## 
## Coefficients:
##       (Intercept)  whoData$AdjTotExp  
##        -736527909          620060216
summary(lfunction)
## 
## Call:
## lm(formula = whoData$AdjLifeExp ~ whoData$AdjTotExp)
## 
## 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 ***
## whoData$AdjTotExp  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

The second model performs better with a larger R-squared value and a lower p-value

Part 3

Life expectancy (raised to the 4.6 power) when Adjusted Total Expenditure (raised to the 0.06 power) = 1.5

Ans = -736527909 + 1.5*620060216
Ans
## [1] 193562415

Life expectancy (raised to the 4.6 power) when Adjusted Total Expenditure (raised to the 0.06 power) = 2.5

Ans = -736527909 + 2.5*620060216
Ans
## [1] 813622631

Part 4

whoData$Extra = whoData$PropMD + whoData$TotExp

lfunction <- lm(LifeExp ~ PropMD + TotExp + Extra, data=whoData)
lfunction
## 
## Call:
## lm(formula = LifeExp ~ PropMD + TotExp + Extra, data = whoData)
## 
## Coefficients:
## (Intercept)       PropMD       TotExp        Extra  
##   6.397e+01    6.508e+02    5.378e-05           NA
summary(lfunction)
## 
## Call:
## lm(formula = LifeExp ~ PropMD + TotExp + Extra, data = whoData)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -23.996  -4.880   3.042   6.958  13.415 
## 
## Coefficients: (1 not defined because of singularities)
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 6.397e+01  7.706e-01  83.012  < 2e-16 ***
## PropMD      6.508e+02  1.946e+02   3.344 0.000998 ***
## TotExp      5.378e-05  8.074e-06   6.661 2.95e-10 ***
## Extra              NA         NA      NA       NA    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.127 on 187 degrees of freedom
## Multiple R-squared:  0.2996, Adjusted R-squared:  0.2921 
## F-statistic: 39.99 on 2 and 187 DF,  p-value: 3.479e-15

This model does not perform well

part 5

LifeExp = 63.97 + 650.8*0.3 + 0.00005378*14
LifeExp
## [1] 259.2108

The result is unrealistic. Human beings do not live for that many years