R Tutorial: The modeling problem for explanation

Learn to separate true relationships from noise when building explanatory models. Using teaching data, the instructor shows how geom_jitter reveals overlapping points that scatter plots hide, then calculates a Pearson correlation of -0.107 between instructor age and teaching score, indicating a weak negative relationship.
Chapters
Now that you have some background on modeling, let's introduce the goal of Modeling for Explanation and use the Evals teaching score data. As an example. Recall that of the elements of the general modeling framework, we previously covered the outcome variable Y and explanatory predictor variables X. Now let's first study F, which defines an explicit relationship between Y and X, and then the error component epsilon. Let's address some points about the modeling problem. Usually, you won't know the true form of F nor the mechanism that generates the error's epsilon. However, you will know the observations Y and X as they are given in our data. Using Y and X, the goal is to construct or fit a model F hat that approximates the true F but not epsilon. In other words, you want to separate the signal from the noise. With the fitted model F hat, you can apply it to X to obtain fitted or predicted values of Y, called Y hat. In this course, you'll keep things simple and only fit models that are linear. But first, let's now perform an EDA of the relationship between the variables in our modeling for explanation example. Earlier, you performed a univariate EDA on the outcome variable score and and the explanatory variable age. By univariate, we mean they only considered one variable at a time. The goal of modeling, however, is exploring relationships between variables. So how can you visually explore such relationships Using a scatter plot? You use a geompoint to create a scatter plot with X mapped to age and Y map to score. This will mark each instructor's age and score with a point. Let's ask ourselves, is the relationship positive? Meaning as professors age, do they also get higher scores or is it negative? It's hard to say as the pattern isn't super clear. Before you attempt to answer this, let's first address an issue known as over plotting. For example, focus on the point at age equals 70 with the highest score of 4.6. Although not immediately apparent, there are actually not one, but two perfectly superimposed points. How can you visually bring this fact to light? By adding a little random jitter to each point, meaning nudge each point just enough so you can distinguish them, but not so much that the plot is overly altered. This is done by taking the same code that generated the scatter plot and replacing the geompoint with a GEOM jitter. Observe There are indeed two values at age 70 and score 4.6. Other over plotted points similarly get broken up. Note that the jittering is strictly a visualization tool. It does not alter the original values in the data set. So back to our earlier question. Is the relationship positive or negative? You can answer this using the correlation coefficient. A correlation coefficient is a summary statistic between negative 1 and 1 measuring the strength of linear association of two numerical variables or the degree to which points fall on a line. In the top left plot where the correlation is negative one, the points fall perfectly on a negatively sloped line. So as values of x increase, values of Y decrease in lockstep. In the bottom right plot where the correlation is one, the relationship is perfectly positive. In the middle, where the correlation is zero, there is no relationship. X and Y behave independently. The remaining plots illustrate other in between values. Let's compute the correlation coefficient for age and score. The core function takes two numerical variables and returns the correlation which you embed in the summarize function. -0.107 indicates a negative relationship, meaning as professors age, they also tend to get lower scores. However, this relationship is only weakly negative. In the next exercise, you'll perform an EDA of the relationship between teaching score and beauty score.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







