Make sure to include the unit of the values whenever appropriate.
Hint: The variables are available in the gapminder data set from the gapminder package. Note that the data set and package both have the same name, gapminder.
library(tidyverse)
options(scipen=999)
data(gapminder, package="gapminder")
houses_lm <- lm(lifeExp ~ gdpPercap,
data = gapminder)
# View summary of model 1
summary(houses_lm)
##
## Call:
## lm(formula = lifeExp ~ gdpPercap, data = gapminder)
##
## Residuals:
## Min 1Q Median 3Q Max
## -82.754 -7.758 2.176 8.225 18.426
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 53.95556088 0.31499494 171.29 <0.0000000000000002 ***
## gdpPercap 0.00076488 0.00002579 29.66 <0.0000000000000002 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 10.49 on 1702 degrees of freedom
## Multiple R-squared: 0.3407, Adjusted R-squared: 0.3403
## F-statistic: 879.6 on 1 and 1702 DF, p-value: < 0.00000000000000022
Hint: Your answer must include a discussion on the p-value.
Yes GDPPerCap is statistically significant since its p value is below 5% (0.00000000000000022)
Hint: Discuss both its sign and magnitude.
Since the coefficienct of GDPPerCap is 0.00076488,if GDPPerCap increases $1, life expectancy increases .00076488 years
Hint: Provide a technical interpretation.
If GDPPerCap = $0 the life expectancy would be 53.95 years
Hint: This is a model with two explanatory variables. Insert another code chunk below.
data(gapminder, package="gapminder")
houses_lm <- lm(lifeExp ~ year, gdpPercap,
data = gapminder)
# View summary of model 1
summary(houses_lm)
##
## Call:
## lm(formula = lifeExp ~ year, data = gapminder, subset = gdpPercap)
##
## Residuals:
## Min 1Q Median 3Q Max
## -29.221 -9.436 1.517 11.201 21.581
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -573.69800 56.15343 -10.22 <0.0000000000000002 ***
## year 0.31998 0.02837 11.28 <0.0000000000000002 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 11.86 on 580 degrees of freedom
## (1122 observations deleted due to missingness)
## Multiple R-squared: 0.1799, Adjusted R-squared: 0.1784
## F-statistic: 127.2 on 1 and 580 DF, p-value: < 0.00000000000000022
Hint: Discuss in terms of both residual standard error and reported adjusted R squared.
The second model is better due to a lower residual standard error and a higher r-squared value (0.4368) when compared with the first model (0.3403)
Hint: Discuss both its sign and magnitude.
The GDPPerCap coefficient of the year is 0.31998 (after 1952), since this is a positive result life expectancy goes up by 0.31998 years every year after
Hint: We had this discussion in class while watching the video at DataCamp, Correlation and Regression in R. The video is titled as “Interpretation of Regression” in Chapter 4: Interpreting Regression Models.
Based on the model, a person from a country with a GDPPerCap of $40,000 in the year 1997 would have an average life expectancy of over 75 years
Hint: Use message, echo and results in the chunk options. Refer to the RMarkdown Reference Guide.