Skip to content

Commit

Permalink
Deploying to gh-pages from @ 9e78c34 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
ismayc committed Nov 10, 2024
1 parent 80658aa commit e05caba
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
Binary file modified v2/ModernDive.pdf
Binary file not shown.
14 changes: 7 additions & 7 deletions v2/ModernDive.tex
Original file line number Diff line number Diff line change
Expand Up @@ -5039,7 +5039,7 @@ \subsection{Exploratory data analysis}\label{model1EDA}

Observe that \texttt{Rows:\ 181} indicates that there are 181 rows/observations in \texttt{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 \emph{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 \texttt{un\_member\_states\_2024} can be found by reading the associated help file (run \texttt{?un\_member\_states\_2024} in the console). Let's describe only the 4 variables we selected in \texttt{UN\_data\_ch5}:
A full description of all the variables included in \texttt{un\_member\_states\_2024} can be found by reading the associated help file (run \href{https://moderndive.github.io/moderndive/reference/un_member_states_2024.html}{\texttt{?un\_member\_states\_2024}} in the console). Let's describe only the 4 variables we selected in \texttt{UN\_data\_ch5}:

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
Expand Down Expand Up @@ -5527,7 +5527,7 @@ \subsection{Observed/fitted values and residuals}\label{model1points}

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 \emph{all} 181 UN member states with complete data as of 2024. Recall that each country corresponds to one of the 181 rows in the \texttt{UN\_data\_ch5} data frame and also one of the 181 points in the regression plot in Figure \ref{fig:numxplot4}.

We could repeat the previous calculations we performed by hand 181 times, but that would be tedious and time consuming. Instead, we do this using a computer with the \href{https://moderndive.com/v2/moderndive.github.io/moderndive/reference/get_regression_points.html}{\texttt{get\_regression\_points()}} function. We apply the \href{https://moderndive.com/v2/moderndive.github.io/moderndive/reference/get_regression_points.html}{\texttt{get\_regression\_points()}} function to \texttt{demographics\_model}, which is where we saved our \texttt{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 181 times, but that would be tedious and time consuming. Instead, we do this using a computer with the \href{https://moderndive.github.io/moderndive/reference/get_regression_points.html}{\texttt{get\_regression\_points()}} function. We apply the \href{https://moderndive.github.io/moderndive/reference/get_regression_points.html}{\texttt{get\_regression\_points()}} function to \texttt{demographics\_model}, which is where we saved our \texttt{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.

\begin{Shaded}
\begin{Highlighting}[]
Expand Down Expand Up @@ -5563,7 +5563,7 @@ \subsection{Observed/fitted values and residuals}\label{model1points}
\caption{The concept of a wrapper function.}\label{fig:moderndive-figure-wrapper}
\end{figure}

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 \href{https://moderndive.com/v2/moderndive.github.io/moderndive/reference/get_regression_points.html}{\texttt{get\_regression\_points()}} function takes a saved \texttt{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 \href{https://moderndive.com/v2/moderndive.github.io/moderndive/reference/get_regression_points.html}{\texttt{get\_regression\_points()}} 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 \href{https://moderndive.github.io/moderndive/reference/get_regression_points.html}{\texttt{get\_regression\_points()}} function takes a saved \texttt{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 \href{https://moderndive.github.io/moderndive/reference/get_regression_points.html}{\texttt{get\_regression\_points()}} 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 @@ -6127,7 +6127,7 @@ \subsection{Observed/fitted values and residuals}\label{model2points}
Residuals \(y - \widehat{y}\), or the error between the observed value and the fitted value
\end{enumerate}

We obtained these values and other values using the \href{https://moderndive.com/v2/moderndive.github.io/moderndive/reference/get_regression_points.html}{\texttt{get\_regression\_points()}} function from the \texttt{moderndive} package. This time, however, we add an argument setting \texttt{ID\ =\ "country"}: this is telling the function to use the variable \texttt{country} in \texttt{gapminder2022} as an \emph{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 \href{https://moderndive.github.io/moderndive/reference/get_regression_points.html}{\texttt{get\_regression\_points()}} function from the \texttt{moderndive} package. This time, however, we add an argument setting \texttt{ID\ =\ "country"}: this is telling the function to use the variable \texttt{country} in \texttt{gapminder2022} as an \emph{identification variable} in the output. This will help contextualize our analysis by matching values to countries.

\begin{Shaded}
\begin{Highlighting}[]
Expand Down Expand Up @@ -6412,12 +6412,12 @@ \subsection{get\_regression\_x() functions}\label{underthehood}
\begin{itemize}
\tightlist
\item
\href{https://moderndive.com/v2/moderndive.github.io/moderndive/reference/get_regression_points.html}{\texttt{get\_regression\_points()}} that returns point-by-point information from a regression model in Subsection \ref{model1points}.
\href{https://moderndive.github.io/moderndive/reference/get_regression_points.html}{\texttt{get\_regression\_points()}} that returns point-by-point information from a regression model in Subsection \ref{model1points}.
\end{itemize}

What is going on behind the scenes with the \href{https://moderndive.com/v2/moderndive.github.io/moderndive/reference/get_regression_points.html}{\texttt{get\_regression\_points()}} function? We mentioned in Subsection \ref{model1table} that this was an example of a \emph{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 \href{https://moderndive.github.io/moderndive/reference/get_regression_points.html}{\texttt{get\_regression\_points()}} function? We mentioned in Subsection \ref{model1table} that this was an example of a \emph{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 \href{https://moderndive.com/v2/moderndive.github.io/moderndive/reference/get_regression_points.html}{\texttt{get\_regression\_points()}} 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. \href{https://moderndive.com/v2/moderndive.github.io/moderndive/reference/get_regression_points.html}{\texttt{get\_regression\_points()}} \index{R packages!moderndive!get\_regression\_points()} uses the \texttt{augment()} \index{R packages!broom!augment()} function in the \href{https://broom.tidyverse.org/}{\texttt{broom} package} to produce the data shown in Table \ref{tab:regpoints-augment}. Additionally, it uses \texttt{clean\_names()} \index{R packages!janitor!clean\_names()} from the \href{https://github.com/sfirke/janitor}{\texttt{janitor} package} \citep{R-janitor} to clean up the variable names.
The \href{https://moderndive.github.io/moderndive/reference/get_regression_points.html}{\texttt{get\_regression\_points()}} 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. \href{https://moderndive.github.io/moderndive/reference/get_regression_points.html}{\texttt{get\_regression\_points()}} \index{R packages!moderndive!get\_regression\_points()} uses the \texttt{augment()} \index{R packages!broom!augment()} function in the \href{https://broom.tidyverse.org/}{\texttt{broom} package} to produce the data shown in Table \ref{tab:regpoints-augment}. Additionally, it uses \texttt{clean\_names()} \index{R packages!janitor!clean\_names()} from the \href{https://github.com/sfirke/janitor}{\texttt{janitor} package} \citep{R-janitor} to clean up the variable names.

\begin{Shaded}
\begin{Highlighting}[]
Expand Down
Loading

0 comments on commit e05caba

Please sign in to comment.