Skip to content

Commit

Permalink
Fix broken links
Browse files Browse the repository at this point in the history
  • Loading branch information
ismayc committed Nov 10, 2024
1 parent e025016 commit 9e78c34
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions 05-regression.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ glimpse(UN_data_ch5)

Observe that ``Rows: `r n_demo_ch5` `` indicates that there are `r n_demo_ch5` rows/observations in `UN_data_ch5` after filtering out the missing values, where each row corresponds to one observed country/member state. It is important to note that the *observational unit* \index{observational unit} is an individual country. Recall from Subsection \@ref(exploredataframes) that the observational unit is the "type of thing" that is being measured by our variables.

A full description of all the variables included in `un_member_states_2024` can be found by reading the associated help file (run `?un_member_states_2024` in the console). Let's describe only the `r UN_data_ch5 |> ncol()` variables we selected in `UN_data_ch5`:
A full description of all the variables included in `un_member_states_2024` can be found by reading the associated help file (run [`?un_member_states_2024`](https://moderndive.github.io/moderndive/reference/un_member_states_2024.html) in the console). Let's describe only the `r UN_data_ch5 |> ncol()` variables we selected in `UN_data_ch5`:

1. `iso`: An identification variable used to distinguish between the `r n_demo_ch5` countries in the filtered dataset.
2. `fert_rate`: A numerical variable representing the country's fertility rate in 2022 corresponding to the expected number of children born per woman in child-bearing years. This is the outcome variable $y$ of interest.
Expand Down Expand Up @@ -572,7 +572,7 @@ best_fit_plot

Now say we want to compute both the fitted value $\widehat{y} = b_0 + b_1 \cdot x$ and the residual $y - \widehat{y}$ for *all* `r n_demo_ch5` UN member states with complete data as of 2024. Recall that each country corresponds to one of the `r n_demo_ch5` rows in the `UN_data_ch5` data frame and also one of the `r n_demo_ch5` points in the regression plot in Figure \@ref(fig:numxplot4).

We could repeat the previous calculations we performed by hand `r n_demo_ch5` times, but that would be tedious and time consuming. Instead, we do this using a computer with the [`get_regression_points()`](https://moderndive.com/v2/moderndive.github.io/moderndive/reference/get_regression_points.html) function. We apply the [`get_regression_points()`](https://moderndive.com/v2/moderndive.github.io/moderndive/reference/get_regression_points.html) function to `demographics_model`, which is where we saved our `lm()` model in the previous section. In Table \@ref(tab:regression-points-1) we present the results of only the 21st through 24th courses for brevity's sake.
We could repeat the previous calculations we performed by hand `r n_demo_ch5` times, but that would be tedious and time consuming. Instead, we do this using a computer with the [`get_regression_points()`](https://moderndive.github.io/moderndive/reference/get_regression_points.html) function. We apply the [`get_regression_points()`](https://moderndive.github.io/moderndive/reference/get_regression_points.html) function to `demographics_model`, which is where we saved our `lm()` model in the previous section. In Table \@ref(tab:regression-points-1) we present the results of only the 21st through 24th courses for brevity's sake.

```{r, eval=FALSE}
regression_points <- get_regression_points(demographics_model)
Expand Down Expand Up @@ -605,7 +605,7 @@ This function is an example of what is known in computer programming as a *wrapp
include_graphics("images/shutterstock/wrapper_function.png")
```

So all you need to worry about is what the inputs look like and what the outputs look like; you leave all the other details "under the hood of the car." In our regression modeling example, the [`get_regression_points()`](https://moderndive.com/v2/moderndive.github.io/moderndive/reference/get_regression_points.html) function takes a saved `lm()` linear regression model as input and returns a data frame of the regression predictions as output. If you are interested in learning more about the [`get_regression_points()`](https://moderndive.com/v2/moderndive.github.io/moderndive/reference/get_regression_points.html) function's inner workings, check out Subsection \@ref(underthehood).
So all you need to worry about is what the inputs look like and what the outputs look like; you leave all the other details "under the hood of the car." In our regression modeling example, the [`get_regression_points()`](https://moderndive.github.io/moderndive/reference/get_regression_points.html) function takes a saved `lm()` linear regression model as input and returns a data frame of the regression predictions as output. If you are interested in learning more about the [`get_regression_points()`](https://moderndive.github.io/moderndive/reference/get_regression_points.html) function's inner workings, check out Subsection \@ref(underthehood).

We inspect the individual columns and match them with the elements of Figure \@ref(fig:numxplot4):

Expand Down Expand Up @@ -1097,7 +1097,7 @@ Recall in Subsection \@ref(model1points), we defined the following three concept
1. Fitted values $\widehat{y}$, or the value on the regression line for a given $x$ value
1. Residuals $y - \widehat{y}$, or the error between the observed value and the fitted value

We obtained these values and other values using the [`get_regression_points()`](https://moderndive.com/v2/moderndive.github.io/moderndive/reference/get_regression_points.html) function from the `moderndive` package. This time, however, we add an argument setting `ID = "country"`: this is telling the function to use the variable `country` in `gapminder2022` as an *identification variable* in the output. This will help contextualize our analysis by matching values to countries.
We obtained these values and other values using the [`get_regression_points()`](https://moderndive.github.io/moderndive/reference/get_regression_points.html) function from the `moderndive` package. This time, however, we add an argument setting `ID = "country"`: this is telling the function to use the variable `country` in `gapminder2022` as an *identification variable* in the output. This will help contextualize our analysis by matching values to countries.

```{r, eval=FALSE}
regression_points <- get_regression_points(life_exp_model, ID = "country")
Expand Down Expand Up @@ -1427,11 +1427,11 @@ Compute the sum of squared residuals by hand for each line and show that of thes

Recall in this chapter we introduced a wrapper function from the `moderndive` package:

- [`get_regression_points()`](https://moderndive.com/v2/moderndive.github.io/moderndive/reference/get_regression_points.html) that returns point-by-point information from a regression model in Subsection \@ref(model1points).
- [`get_regression_points()`](https://moderndive.github.io/moderndive/reference/get_regression_points.html) that returns point-by-point information from a regression model in Subsection \@ref(model1points).

What is going on behind the scenes with the <!-- `get_regression_table()` and --> [`get_regression_points()`](https://moderndive.com/v2/moderndive.github.io/moderndive/reference/get_regression_points.html) function? We mentioned in Subsection \@ref(model1table) that this was an example of a *wrapper function*. Such functions take other pre-existing functions and "wrap" them into single functions that hide the user from their inner workings. This way all the user needs to worry about is what the inputs look like and what the outputs look like. In this subsection, we'll "get under the hood" of these functions and see how the "engine" of these wrapper functions works.
What is going on behind the scenes with the <!-- `get_regression_table()` and --> [`get_regression_points()`](https://moderndive.github.io/moderndive/reference/get_regression_points.html) function? We mentioned in Subsection \@ref(model1table) that this was an example of a *wrapper function*. Such functions take other pre-existing functions and "wrap" them into single functions that hide the user from their inner workings. This way all the user needs to worry about is what the inputs look like and what the outputs look like. In this subsection, we'll "get under the hood" of these functions and see how the "engine" of these wrapper functions works.

The [`get_regression_points()`](https://moderndive.com/v2/moderndive.github.io/moderndive/reference/get_regression_points.html) function is a wrapper function, returning information about the individual points involved in a regression model like the fitted values, observed values, and the residuals. [`get_regression_points()`](https://moderndive.com/v2/moderndive.github.io/moderndive/reference/get_regression_points.html) \index{R packages!moderndive!get\_regression\_points()} uses the `augment()` \index{R packages!broom!augment()} function in the [`broom` package](https://broom.tidyverse.org/) <!-- instead of the `tidy()` function as with `get_regression_table()` --> to produce the data shown in Table \@ref(tab:regpoints-augment). Additionally, it uses `clean_names()` \index{R packages!janitor!clean\_names()} from the [`janitor` package](https://github.com/sfirke/janitor) [@R-janitor] to clean up the variable names.
The [`get_regression_points()`](https://moderndive.github.io/moderndive/reference/get_regression_points.html) function is a wrapper function, returning information about the individual points involved in a regression model like the fitted values, observed values, and the residuals. [`get_regression_points()`](https://moderndive.github.io/moderndive/reference/get_regression_points.html) \index{R packages!moderndive!get\_regression\_points()} uses the `augment()` \index{R packages!broom!augment()} function in the [`broom` package](https://broom.tidyverse.org/) <!-- instead of the `tidy()` function as with `get_regression_table()` --> to produce the data shown in Table \@ref(tab:regpoints-augment). Additionally, it uses `clean_names()` \index{R packages!janitor!clean\_names()} from the [`janitor` package](https://github.com/sfirke/janitor) [@R-janitor] to clean up the variable names.


```{r, eval=FALSE}
Expand Down

0 comments on commit 9e78c34

Please sign in to comment.