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(year ~ gdpPercap,
data = gapminder)
# View summary of model 1
summary(houses_lm)
##
## Call:
## lm(formula = year ~ gdpPercap, data = gapminder)
##
## Residuals:
## Min 1Q Median 3Q Max
## -67.779 -14.901 -0.191 14.182 30.262
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1976.62723521 0.50495752 3914.44 <0.0000000000000002 ***
## gdpPercap 0.00039815 0.00004134 9.63 <0.0000000000000002 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 16.82 on 1702 degrees of freedom
## Multiple R-squared: 0.05167, Adjusted R-squared: 0.05112
## F-statistic: 92.74 on 1 and 1702 DF, p-value: < 0.00000000000000022
Hint: Your answer must include a discussion on the p-value.
The gdp per capital is statistically significant because the probablity is less than 5%.
Hint: Discuss both its sign and magnitude.
The gdapPercap has an expected life of 29 years
Hint: Provide a technical interpretation.
The intercept is 53.95 whch would be the average life expectancy
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)
# View summary of model 1
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.
I would say the 2nd one is more accurate because the first one missed 10.49 data in point years compared to the second one which is 9.694 and this is for the amount of years missed during the model.
Hint: Discuss both its sign and magnitude.
When you look at the model it shows the life expectancy in years 1952-2007 in small incriments of 5 years.
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.
Hint: Use message, echo and results in the chunk options. Refer to the RMarkdown Reference Guide.