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.
# load who data
who <- read.csv("C:/Users/Lelan/Documents/Education/CUNY/DATA605/Spring_2017/Homework12/who.csv")
# visually inspect data
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
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.
# Plot total expenditures vs life expectancy for who data set
plot(who$TotExp, who$LifeExp, xlab = "Total Expenditures", ylab = "Life Expectancy")
# Run simple linear regression
who_simple.lm <- lm(LifeExp ~ TotExp, data = who)
# Run summary function to provide the F statistics,
# R-squared, standard error, and p-values
summary(who_simple.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
The F-table value for 1 regression degree of freedom and 120 residual degrees of freedom is 6.851. Since the F-statistic from our model, which has 1 regression degree of freedom and 188 residual degrees of freedom, is 65.26, is much greater than the F-table value, the F-statistic suggests we can reject the null hypothesis (a regression model with a zero coefficient). Similarly, the p-value is well below typical \(\alpha\) thresholds. The \(R^2 = 0.2577\) value is not strong, it tells us that 25.77% of the variation in the data is accounted for in our model, which means the model does not strongly fit the data. The standard error is a reasonably small percentage of the coefficient.
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?”
# Create new column with LifeExp^4.6 values
who$LifeExp4.6 <- (who$LifeExp)^4.6
# Create new column with TotExp^4.6 values
who$TotExp0.06 <- (who$TotExp)^0.06
# Plot total expenditures vs life expectancy for who data set
plot(who$TotExp0.06, who$LifeExp4.6, xlab = "Total Expenditures ^ 0.06", ylab = "Life Expectancy ^ 4.6")
# Run simple linear regression
who_transformed.lm <- lm(LifeExp4.6 ~ TotExp0.06, data = who)
# Run summary function to provide the F statistics,
# R-squared, standard error, and p-values
summary(who_transformed.lm)
##
## Call:
## lm(formula = LifeExp4.6 ~ TotExp0.06, data = who)
##
## 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 ***
## TotExp0.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
The F-statistic from our transformed model is 507.7 (same degrees of freedom as model from 1.) is much better vs. the F-table value than the prior model. Similarly, the p-value is even better. Finally, the \(R^2 = 0.7298\) value is dramatically superior to our model from 1. The transformed model is the better model. The standard error is a reasonably small percentage of the coefficient.
3. Using the results from 2, forecast life expectancy when TotExp^.06 = 1.5. Then forecast life expectancy when TotExp^.06=2.5.
Our model is \(LifeExp4.6 = -736527910 + 620060216 * TotExp0.06\)
# Create formula for model
le.transformed <- function(totexp) {
(-736527910 + (620060216 * totexp))^(1/4.6)
}
# pass in TotExp^.06 = 1.5
le.transformed(1.5)
## [1] 63.31153
# pass in TotExp^.06 = 2.5
le.transformed(2.5)
## [1] 86.50645
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
# Build multiple regression model using transformed variables
who_multiple.lm <- lm(who$LifeExp4.6 ~ who$PropMD + who$TotExp0.06 + who$PropMD:who$TotExp0.06)
# Run summary function to provide the F statistics,
# R-squared, standard error, and p-values
summary(who_multiple.lm)
##
## Call:
## lm(formula = who$LifeExp4.6 ~ who$PropMD + who$TotExp0.06 + who$PropMD:who$TotExp0.06)
##
## Residuals:
## Min 1Q Median 3Q Max
## -296470018 -47729263 12183210 60285515 212311883
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -7.244e+08 5.083e+07 -14.253 <2e-16 ***
## who$PropMD 4.727e+10 2.258e+10 2.094 0.0376 *
## who$TotExp0.06 6.048e+08 3.023e+07 20.005 <2e-16 ***
## who$PropMD:who$TotExp0.06 -2.121e+10 1.131e+10 -1.876 0.0622 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 88520000 on 186 degrees of freedom
## Multiple R-squared: 0.7441, Adjusted R-squared: 0.74
## F-statistic: 180.3 on 3 and 186 DF, p-value: < 2.2e-16
# get coefficients for problem 5
who_multiple.lm$coefficients
## (Intercept) who$PropMD
## -724418697 47273338389
## who$TotExp0.06 who$PropMD:who$TotExp0.06
## 604795792 -21214671638
The F-statistic from our multiple regression model is 180.3 which is well above the F-table value of 3.949 for 3 regression degrees of freedom and 120 residual degrees of freedom and \(\alpha = 0.01\). Similarly, the p-value is strong for the model, and strong for all of the variables except PropMD x TotExp0.06, which is still pretty good (0.0622). Finally, the \(R^2 = 0.7441\) value is quite good. The standard error values for PropMD and PropMD x TotExp could be better.
5. Forecast LifeExp when PropMD=.03 and TotExp = 14. Does this forecast seem realistic? Why or why not?
Our model is \(LifeExp4.6 = -724418697 + (47273338389 * PropMD) + (604795792 * TotExp0.06) - (21214671638 * PropMD * TotExp0.06)\)
# Create formula for model
le.transformed_mutiple <- function(propmd, totexp) {
(-724418697 + (47273338389 * propmd) + (604795792 * totexp) - (21214671638 * propmd * totexp))^(1/4.6)
}
# set PropMD=.03 and TotExp = 14
pmd <- 0.03
# transform TotExp to TotExp^0.06
te <- 14
te4.6 <- te^0.06
# pass in PropMD=.03 and TotExp = 14
le.transformed_mutiple(pmd, te4.6)
## [1] 82.56958
I have a lot of reservations about the prediction because the PropMD ratio being used for the prediction is only in-line with a few outlying data points. If we plot PropMD against Life Expectancy, we can see the overwhelming majority of data points are between 0.000 and 0.005. Then we see two major outlier data points around 0.325 and 0,035. I always get nervous when predicting values that are not in the range of the values for an overwhelming percentage of observations. The Total Expenditure is also towards the bottom end of the range, though a lot of values exist in that range.
plot(who$PropMD, who$LifeExp, xlab = "Proportion MDs", ylab = "Life Expectancy")