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)
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.
The p-value is showing at <0.0000000000000002, which is far less than 5%. Due to this, the coefficient is statistically significant.
Hint: Discuss both its sign and magnitude.
The result of gdpPercap’s coefficient is 0.00076488. Therefore, there is an increase in gdpPercap by $1. The magnitude may indicate that life expectancy of each individual shows a slight increase by approximately 0.00076488 years as a result.
Hint: Provide a technical interpretation.
The value of the intercept reads as 53.9555608. This can be explained as meaning if someone is born with a $0 gdpPercap, their life expectancy from birth would be close to 53.9555608 or 54 years old rounding up.
Hint: This is a model with two explanatory variables. Insert another code chunk below.
library(tidyverse)
options(scipen=999)
data(gapminder, package="gapminder")
houses_lm <- lm(lifeExp ~gdpPercap + year,
data = gapminder)
summary(houses_lm)
##
## Call:
## lm(formula = lifeExp ~ gdpPercap + year, data = gapminder)
##
## Residuals:
## Min 1Q Median 3Q Max
## -67.262 -6.954 1.219 7.759 19.553
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -418.42425945 27.61713769 -15.15 <0.0000000000000002 ***
## gdpPercap 0.00066973 0.00002447 27.37 <0.0000000000000002 ***
## year 0.23898275 0.01397107 17.11 <0.0000000000000002 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 9.694 on 1701 degrees of freedom
## Multiple R-squared: 0.4375, Adjusted R-squared: 0.4368
## F-statistic: 661.4 on 2 and 1701 DF, p-value: < 0.00000000000000022
Hint: Discuss in terms of both residual standard error and reported adjusted R squared.
The first model displays the residual standard error at 10.49 on 1702 degrees of freedom. The second model, however, displays the residual standard error at 9.694 on 1701 degrees of freedom. This implies that the first model does not count roughly 11 people, whilst the second model does not count roughly 10 people.
The R-squared value in the first model reads as 0.3403. The R-squared value in the second model reads as 0.4368. This indicates that the data shown in the first model will be closer to the line of regression than in the second model.
The second model would appear to be better because although the data follows the line of regression more closely than the first model, the second model misses one less person.
Hint: Discuss both its sign and magnitude.
The coefficient of the year reads as 0.23898275. The magnitude of this result may mean that after each year, a person’s life expectancy may increase by appoximately 0.23898275 years, which really seems like a few weeks.
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 second model, the predicted life expectancy for a country with a gdpPercap of $40,000 in the year 1997 would be approximately 76.49 years old.
Hint: Use message, echo and results in the chunk options. Refer to the RMarkdown Reference Guide.