Relationships Between Variables and Least Squares Regression
Categorical Variables: Contingency Tables and Proportions
Contingency tables are used to summarize the relationship between two categorical variables by displaying the counts of every possible outcome combination.
Using the email data set ($3921$ emails), we analyze the relationship between the variable spam and the variable number (which identifies if an email contains none, small numbers under 1 million, or big numbers over 1 million).
A contingency table (Table 2.24) summarizes these outcomes:
Spam and No number:
Spam and Small number:
Spam and Big number:
Total Spam:
Not spam and No number:
Not spam and Small number:
Not spam and Big number:
Total Not spam:
Column Totals: None (), Small (), Big (), Grand Total ().
Row and column proportions facilitate comparisons:
Row Proportions: Calculated by dividing a cell count by its row total. For example, the proportion of spam emails with no numbers is .
Column Proportions: Calculated by dividing a cell count by its column total. For example, the proportion of emails with no numbers that are spam is .
Comparing column proportions provides evidence of association. Because the spam rate varies across levels ( for none, for small, and for big), the variables are associated.
When choosing between row and column proportions, prioritize the one that answers the specific research question. To classify emails, column proportions are more useful because they show how the proportion of spam changes within each category of the explanatory variable (e.g., format or number).
In the case of spam and format (plain text vs. HTML):
Plain text spam rate:
HTML spam rate:
Visualizing Qualitative Relationships: Stacked Bar Plots
A stacked bar plot is a graphical representation of the information in a contingency table.
In a standardized stacked bar plot, each bar is of equal height (representing or ), and the internal segments show the proportion of each outcome.
Standardized plots are often clearer for identifying associations because they allow for a direct comparison of proportions across groups regardless of total counts.
Variables are dependent if the proportions of one variable change across the groups of another; they are independent if the proportions remain constant.
Comparing Qualitative and Quantitative Variables: Box Plots and Histograms
Relationships between a categorical and a quantitative variable are investigated by splitting the population into groups based on the categorical variable and comparing plots for each group.
Side-by-side box plots are traditional tools for comparing centers (median) and spreads (IQR). For example, comparing median household income between counties with a population gain versus those with no gain:
Counties with population gain: Median income approx. , with higher variability.
Counties with no gain: Median income approx. , with lower variability.
Hollow histograms use the outlines of histograms for each group on the same scale, which is useful for comparing distribution shapes, skewness, and identifying modes.
Note: Observed relationships between variables in observational data, such as income and population gain, cannot be interpreted as causal connections.
Relationships Between Two Quantitative Variables: Scatterplots
Scatterplots display the relationship between two numerical variables. Each point represents a single case.
Associated variables (also called dependent variables) show a discernible pattern in the scatterplot.
Independent variables show no evident relationship.
Types of Association:
Positive Association: Points have a trend going up and to the right; a high value in one variable is associated with a high value in the other (e.g., poverty rate and federal spending per capita).
Negative Association: Points have a downward trend; a high value in one variable is associated with a low value in the other (e.g., homeownership vs. multi-unit structures).
Nonlinear Relationships: Trends can be nonlinear, such as car price versus weight, which may show a curved "horseshoe" or decaying trend.
Transformations: To model data with clusters near zero or non-constant trends, transformations (like log base e) are applied to improve the linearity and model fit.
The Correlation Coefficient
Correlation measures the strength of the linear relationship between two variables and ranges from to .
Let be observations. The correlation is calculated following quadrant splitting around the sample means .
Points in the upper-right or lower-left quadrants contribute a positive score to the relationship, while points in the other two quadrants contribute a negative score.
The Sample Covariance is defined as:
Because covariance changes if units of measure change, we standardize it using standard deviations and to find Correlation :
Interpretations of :
or : Perfect linear relationship.
: Strong positive linear trend.
: Strong negative linear trend.
: No linear association (though a strong nonlinear relationship may still exist).
Special Visualizations: Time Plots and Maps
Time Plots: Scatterplots where the x-axis represents time, often with points connected by a continuous line to show evolution over time (e.g., unemployment rates).
Intensity Maps: Used for geographic data; different colors represent ranges of values for variables like poverty rates or federal spending per capita across counties.
These maps are useful for seeing geographic trends (e.g., the oil boom near the Canadian border or high poverty in the deep south).
Linear Combinations of Variables
A linear combination of two variables and is defined as , where , , and are fixed and known constants.
Average of a Linear Combination: The sample average for the combination is found by plugging in the sample averages for each variable:
Variability of Linear Combinations:
For independent variables:
For dependent variables, we must include the covariance term: In terms of correlation , this is:
Covariance Property:
Correlation Property: . This implies the absolute value of correlation is invariant under linear transformations.
The Least Squares Regression Line
Explanatory vs. Response Variables:
The response variable (), also called dependent or explorative, is the variable we wish to predict.
The explanatory variable (), also called independent, is the variable used to predict the outcome.
Prediction and : Estimates for the response variable are denoted with a "hat" symbol: .
Residuals: The residual () is the difference between the observed value and the predicted value:
If the model underestimates an observation, the residual is positive.
If it overestimates, the residual is negative.
Best Fit Criterion: The least squares line minimizes the sum of the squared residuals (). This method is preferred because it is standard, easier to calculate than absolute magnitudes, and penalizes large errors more heavily via squaring.
Estimating and Interpreting Regression Parameters
Slope calculation ():
Intercept calculation (): Since the point always lies on the least squares line:
Parameter Interpretations:
Slope (): Represents the estimated average change in the response variable for every one-unit increase in the explanatory variable.
Intercept (): Represents the estimated average value of the response variable if the explanatory variable is zero.
ANOVA and Determination Coefficient :
Total variations () can be split into variation explained by the model () and residual variation ():
The Coefficient of Determination () indicates the proportion of total variation explained by the linear model:
Successfully, is also the square of the correlation coefficient ().
Limitations of Linear Models
Robustness: The least squares line is not robust against outliers because its components (means, standard deviations, correlation) are not robust.
Extrapolation: Applying model estimates outside the range of the original data is dangerous and unreliable. For example, using an income-based gift aid model to predict aid for a family earning million might result in impossible negative aid values ().
Structural Mis-specification: Linear models are unsuitable for relationships that are clearly decaying or curvilinear, though transformations for or (like ) can sometimes turn non-linear relationships into manageable simple linear models.