Welcome to Bivariate Data Exploration!
In our last section, we looked at Univariate analysis—understanding one variable at a time. Now, it’s time to level up! Bivariate Data Exploration is all about looking at two variables simultaneously to see how they interact.
Why is this the "heart" of Exam PA? Because predictive modeling is essentially trying to understand the relationship between your predictors (features) and your target (what you want to predict). If you can master how to spot these relationships visually and numerically, you are halfway to building a great model! Don’t worry if you aren't a math whiz—we are going to break this down into simple, visual steps.
1. Numeric vs. Numeric: The Power Couple
When you have two continuous variables (like Age and Income), you want to see if they move together. Are they best friends who go the same way, or do they avoid each other?
The Scatterplot
The scatterplot is your best friend here. It places one variable on the x-axis and the other on the y-axis.
- Positive Relationship: The dots go "up and to the right." As \(X\) increases, \(Y\) increases.
- Negative Relationship: The dots go "down and to the right." As \(X\) increases, \(Y\) decreases.
- No Relationship: The dots look like a random cloud of bees.
Correlation (\(r\))
This is a single number that summarizes the strength of a linear relationship.
- It ranges from -1 to +1.
- +1 means a perfect positive line.
- -1 means a perfect negative line.
- 0 means no linear relationship at all.
Quick Review Box:
Correlation only measures linear (straight-line) relationships. If your data forms a perfect "U" shape, the correlation might be 0, even though there is clearly a pattern! Always look at the plot, don't just trust the number.
Did you know? In the context of Exam PA, if two predictors have a very high correlation (e.g., \(r > 0.8\)), this is called multicollinearity. It can make your model unstable, and you might need to drop one of them!
Key Takeaway:
Use scatterplots to visualize the trend and correlation coefficients to quantify the strength of the linear bond between two numeric variables.
2. Numeric vs. Categorical: Comparing Groups
Often, you want to know if a numeric value (like Claim Amount) differs based on a category (like Gender or Region).
The Side-by-Side Boxplot
This is the "gold standard" for Exam PA. You place the categories on the x-axis and the numeric values on the y-axis.
- What to look for: Are the "boxes" at the same height? If the box for "Group A" is much higher than "Group B," that category is likely a strong predictor for your target!
Density Plots (Overlaid)
Imagine two smooth hills (curves) drawn on the same graph. If the hills overlap perfectly, the category doesn't matter much. If one hill is shifted far to the right of the other, you've found a meaningful relationship.
Analogy: The Basketball Player vs. The Gymnast
If we plot the Height (numeric) of people grouped by Sport (categorical), the boxplot for Basketball will be much higher on the graph than the boxplot for Gymnasts. This tells us Sport is a great predictor for Height.
Common Mistake: Focusing only on the "middle" (mean/median). Also look at the spread (the width of the box). If one group is much more spread out than another, that’s an important insight for risk management!
Key Takeaway:
To see how a category affects a number, use side-by-side boxplots. Look for differences in the median line and the overall vertical position of the boxes.
3. Categorical vs. Categorical: Spotting Patterns
What if both variables are categories? For example, does Smoking Status (Yes/No) relate to Policy Type (Basic/Premium)?
Contingency Tables (Crosstabs)
This is a simple grid showing counts.
- Pro Tip: Don't just look at raw counts; look at proportions. If 80% of smokers choose "Basic" but only 20% of non-smokers do, you’ve found a relationship!
Stacked or Grouped Bar Charts
- Stacked Bar Chart: Each bar represents a category, and it's "colored in" by the second category. If the colors are distributed differently across bars, there is an interaction.
- Filled (Proportional) Bar Chart: Every bar is the same height (100%). This is often better for seeing if the ratio of categories changes.
Memory Aid: "The 100% Rule"
When comparing categories of different sizes (e.g., 1,000 men vs. 10 women), always use proportions (percentages) rather than raw counts, or the smaller group will be "hidden" in the chart.
Key Takeaway:
Use proportional stacked bar charts to see if the distribution of one categorical variable changes depending on another.
4. Why This Matters for the Exam
On Exam PA, you aren't just making graphs for fun. You are doing Feature Selection.
1. Predictor vs. Target: If you see a relationship here, keep the predictor! It’s useful.
2. Predictor vs. Predictor: If you see a very strong relationship here, you might have redundancy. Using both might hurt your model's interpretability.
Don't worry if this seems tricky at first! The more you practice looking at these plots in R, the faster you will get at "reading" the story the data is telling. When you write your report, describe what you see in plain English—exactly like we did with the basketball players!
Summary of Bivariate Tools:
1. Numeric + Numeric: Scatterplot, Correlation \(r\).
2. Numeric + Categorical: Side-by-side Boxplots, Overlaid Density Plots.
3. Categorical + Categorical: Contingency Tables, Stacked Bar Charts.
Quick Review Box:
Bivariate = Two variables.
Goal: Find relationships, detect multicollinearity, and identify the most important predictors for your model.