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.
my_git_url <- getURL("https://raw.githubusercontent.com/AhmedBuckets/SPS605/main/who.csv")
who_data <- read.csv(text = my_git_url)
exp_model <- lm(LifeExp ~ TotExp, data = who_data)
## integer(0)
##
## Call:
## lm(formula = LifeExp ~ TotExp, data = who_data)
##
## 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-stat which is 65.26 for this model, is fairly large and so the model shows a strong relationship between the predictor (total expenditure) and the response (life expectancy). The very small p-value of 7.714e-14, way smaller than 0.05, also indicates that the results are statistically significant.
The R-squared value represents how much of the response is predictable by the independent variable, and in this case the value is 0.2577, meaning 25.77% of the variance in life expectancy can be explained by total expenditure.
This model had a residual standard error of 9.371. The standard error shows how much the observations tend to deviate from the predicted values. In this case they will be off by about 9 years.
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?”
who_data$LifeExp_46 <- who_data$LifeExp^4.6
who_data$TotExp_06 <- who_data$TotExp^0.06
##
## Call:
## lm(formula = LifeExp_46 ~ TotExp_06, data = who_data)
##
## 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_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
## integer(0)
The F-stat which is 507.7 for this new model, is very large and so the model shows a very strong relationship between the predictor (total expenditure^0.06) and the response (life expectancy^4.6). The very small p-value of 2e-16, way smaller than 0.05, also indicates that the results are statistically significant.
The R-squared value represents how much of the response is predictable by the independent variable, and in this case the value is 0.7298, meaning 72.98% of the variance in life expectancy^4.6 can be explained by total expenditure^0.06.
This model had a residual standard error of 90,490,000. The standard error shows how much the observations tend to deviate from the predicted values. In this case they will be off by a value of 90,490,000. This is very large and would normally be a huge error, but the scale of the y axis which represents life expectancy^4.6 is in the hundreds of millions.
Because the R-squared value is so much higher in this model, and the fact that the standard error isn’t as high (relatively to the scale of the dependent variable) I would say this is the “better” one.
Using the results from 3, forecast life expectancy when TotExp^.06 =1.5. Then forecast life expectancy when TotExp^.06=2.5.
We can use the predict function to use the model.
new_data <- data.frame(TotExp_06 = c(1.5, 2.5))
predicted_lifeexp <- predict(modded_model, newdata = new_data)
predicted_lifeexp_original_scale <- predicted_lifeexp^(1/4.6)
predicted_lifeexp_original_scale
## 1 2
## 63.31153 86.50645
When TotExp^.06 = 1.5, life expectancy = 63.31153
When TotExp^.06 = 2.5, life expectancy = 86.50645
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_model <- lm(LifeExp ~ PropMD + TotExp + PropMD*TotExp, data = who_data)
summary(multi_model)
##
## Call:
## lm(formula = LifeExp ~ PropMD + TotExp + PropMD * TotExp, data = who_data)
##
## 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
The F-stat which is 34.49 for this multi model, is very large and so the model shows a very strong relationship between the predictors and life expectancy. The very small p-value of 2.2e-16, way smaller than 0.05, also indicates that the results are statistically significant. At least one predictor will be reliable.
The R-squared value represents how much of the response is predictable by the independent variables, and in this case the value is 0.3574, meaning 35.74% of the variance in life expectancy can be explained by the predictors.
This model had a residual standard error of 8.765. This means the observations will be off by a value of 8.765 years.
Based on R-squared, this model is the better than the first model with 35.74% of the variance explained by the predictors as opposed to the 25.77% of the first model. The residual standard error is also slightly lower, meaning the predicted results will be closer to the observed ones. However I think the second model would still perform the best because its R squared is much higher.
new_data <- data.frame(PropMD = 0.03, TotExp = 14)
predicted_lifeexp <- predict(multi_model, newdata = new_data)
predicted_lifeexp
## 1
## 107.696
The model predicts that the life expectancy when the proportion of doctors is 0.3 and total expenditure is 14 will be 107.696 years old.
## Average Total Expenditures: 41695.49
## Median Total Expenditures: 5541
## Average Proportion of MDs: 0.00179538
## Median Proportion of MDs: 0.001047359
A total expenditure of 14 is way less than the mean and median expenditures for this data. However the propMd value of 0.03 is a lot higher than the average and median. Perhaps an abundance of doctors could explain the high life expectancy, but we know that