Make sure to include the unit of the values whenever appropriate.

Q1 Build a regression model to predict life expectancy using gdp per capita.

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")
gdplife <- lm(lifeExp ~ gdpPercap, 
                data = gapminder)

# View summary of model 1
summary(gdplife)
## 
## 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

Q2 Is the coefficient of gdpPercap statistically significant at 5%?

Hint: Your answer must include a discussion on the p-value.

According to the data, the coefficient is statistically significant at 5% because the p-value is less than 0.05. If the number were close to 0.05 or larger, than it would not be considered significant.

Q3 Interpret the coefficient of gdpPercap.

Hint: Discuss both its sign and magnitude.

The gdpPercap is measured in US Dollars with adjustment in inflation. According to the coefficient, for every $0.00076 the average liefspan would be increased by a year. This means that there is not much of a relation between the amount of money a person has and their life expectancy.

Q4 Interpret the Intercept.

Hint: Provide a technical interpretation.

According to the data, the avg life expectancy in relation to gdpPercap is 53.95 years. The number being positive and the significance at 5% states that the average person would live about 54.

Q5 Build another model that predicts life expectancy using gdpPercap, but also controls for another important variable, year.

Hint: This is a model with two explanatory variables. Insert another code chunk below.

library(tidyverse)
options(scipen=999)

data(gapminder, package="gapminder")
gdplifeyear <- lm(lifeExp ~ gdpPercap + year, 
                data = gapminder)

# View summary of model 1
summary(gdplifeyear)
## 
## 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

Q6 Which of the two models is better?

Hint: Discuss in terms of both residual standard error and reported adjusted R squared.

Using the residual standard error, in the first graph it shows that the number of years can vary by 10.49 years with 1702 degrees of freedom. In the second model, the residual standard error is 9.64 years at 1701 degrees of freedom. And the adjusted R squared for the first is at 34% while the second model is at 44%. According to this information, the second model is better because there is less error.

Q7 Interpret the coefficient of year.

Hint: Discuss both its sign and magnitude.

Using the variable of year, the life expectancy increases 0.23 every five years. This is due to the advancements in technology, medicine, and health. There is relation in this and it has been shown through the years given between the ranges of 1952 and 2007.

Q7.a Based on the second model, what is the predicted life expectancy for a country with gdpPercap of $40,000 a year in 1997.

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.

Using the infformation given in model 2, the average life expectancy in 1997 with a gdpPercap of $40,000 was calulated to be about 45 years.

Q8 Hide the messages, but display the code and its results on the webpage.

Hint: Use message, echo and results in the chunk options. Refer to the RMarkdown Reference Guide.

Q9 Display the title and your name correctly at the top of the webpage.

Q10 Use the correct slug.