Bivariate Data Analysis: Correlation and Least-Squares Regression

Bivariate Data and Scatterplots

  • Definition of Bivariate Data:

    • Bivariate data consist of pairs of ordered values, commonly denoted as (x,y)(x, y), measured on the same individual or experimental unit.

    • It involves two distinct variables: an explanatory variable and an outcome variable.

  • The Scatterplot:

    • The fundamental graphical tool utilized to examine and display bivariate data is the scatterplot.

    • Each point represents an individual observation plotted at coordinates corresponding to its values for both variables.

    • The explanatory variable (xx) is plotted along the horizontal axis, while the response or outcome variable (yy) is plotted along the vertical axis.

  • Real Estate Example (Sue Bays Realty Sample):

    • A real estate agent studied the relationship between house size in square feet and final selling price in thousands of dollars ($1000s\$1000\text{s}) for a sample of houses located in a suburban Denver neighborhood.

    • Observed Sample Dataset (Table 4.1):

    • House 1: Size = 2521 sq ft2521\,\text{sq ft}, Selling Price = 400 thousand dollars400\,\text{thousand dollars} ($400,000\$400,000)

    • House 2: Size = 2555 sq ft2555\,\text{sq ft}, Selling Price = 426 thousand dollars426\,\text{thousand dollars} ($426,000\$426,000)

    • House 3: Size = 2735 sq ft2735\,\text{sq ft}, Selling Price = 428 thousand dollars428\,\text{thousand dollars} ($428,000\$428,000)

    • House 4: Size = 2846 sq ft2846\,\text{sq ft}, Selling Price = 435 thousand dollars435\,\text{thousand dollars} ($435,000\$435,000)

    • House 5: Size = 3028 sq ft3028\,\text{sq ft}, Selling Price = 469 thousand dollars469\,\text{thousand dollars} ($469,000\$469,000)

    • House 6: Size = 3049 sq ft3049\,\text{sq ft}, Selling Price = 475 thousand dollars475\,\text{thousand dollars} ($475,000\$475,000)

    • House 7: Size = 3198 sq ft3198\,\text{sq ft}, Selling Price = 488 thousand dollars488\,\text{thousand dollars} ($488,000\$488,000)

    • House 8: Size = 3198 sq ft3198\,\text{sq ft}, Selling Price = 455 thousand dollars455\,\text{thousand dollars} ($455,000\$455,000)

    • Visual Patterns in the Scatterplot:

    • Larger sizes tend to pair with larger prices, and smaller sizes tend to pair with smaller prices, representing a positive association.

    • The points cluster around a straight trajectory from the lower left to the upper right, demonstrating a linear relationship between size and selling price.

Scatterplot of selling price versus size for a sample of houses

Types of Association in Scatterplots

  • Forms of Association (Figure 4.2):

    • Positive Linear Association: Points cluster tightly along an upward-sloping straight line from bottom-left to top-right. As the explanatory variable increases, the response variable tends to increase.

    • Negative Linear Association: Points cluster tightly along a downward-sloping straight line from top-left to bottom-right. As the explanatory variable increases, the response variable tends to decrease.

    • Weak Linear Association: Points exhibit a broad, diffuse cloud with minimal alignment along a line, signifying a low-strength linear connection.

    • Positive Nonlinear Association: Points form an upward-trending curve where the rate of change is not constant.

    • Negative Nonlinear Association: Points form a downward-trending curve where the rate of change decreases or changes nonlinearly.

Scatterplots exhibiting various types of association
  • Limitation of Visual Scale (Figure 4.3):

    • Visual assessment of linear strength can be deceptive because it depends directly on the chosen scale of the plot axes.

    • Two scatterplots displaying the exact same dataset can convey conflicting impressions if the vertical axis scale is stretched or compressed.

    • For instance, scaling the yy-axis from 400400 to 500500 yields a wider scatter pattern, whereas scaling from 200200 to 700700 compresses the points vertically, creating the illusion of a tighter, stronger linear relationship.

    • Consequently, an objective numerical measure independent of graphical scaling is mandatory to evaluate linear relationship strength.

Effect of axis scaling on the visual appearance of linear relationship strength

The Linear Correlation Coefficient

  • Definition and Mathematical Formulation:

    • The sample correlation coefficient (rr) quantitatively measures the strength and direction of the linear relationship between two quantitative variables.

    • It computes the average product of standardized scores (zz-scores) for the two variables across all pairs:

r=1n−1∑(x−xˉsx)(y−yˉsy)r = \frac{1}{n - 1} \sum \left( \frac{x - \bar{x}}{s_x} \right) \left( \frac{y - \bar{y}}{s_y} \right)

  • Mathematical Properties of rr:

    • Bounded Range: The value always lies between −1-1 and 11 inclusive:

−1≤r≤1-1 \le r \le 1

  • Scale and Unit Invariance: The value of rr is dimensionless and does not depend on the units in which either xx or yy is measured.

  • Symmetry: Switching the explanatory variable xx and the response variable yy does not alter the correlation coefficient (cor(x,y)=cor(y,x)\text{cor}(x, y) = \text{cor}(y, x)).

  • Strict Linearity Measure: The coefficient rr measures only the strength and direction of a straight-line (linear) relationship; it does not properly measure curved or nonlinear patterns.

  • Non-Resistance to Outliers: The value of rr is sensitive to outliers and extreme values; a single aberrant observation can substantially increase or decrease rr.

  • Correlation vs. Causation Principle: A high correlation does not imply causation. A linear association between two variables does not prove that changes in one variable cause changes in the other.

    • Step-by-Step Manual Calculation for the Denver House Sample:

  • Summary Statistics:

    • Sample size: n=8n = 8

    • Mean of size: xˉ=2891.25 sq ft\bar{x} = 2891.25\,\text{sq ft}

    • Standard deviation of size: sx=269.4936 sq fts_x = 269.4936\,\text{sq ft}

    • Mean of price: yˉ=447.0 thousand dollars\bar{y} = 447.0\,\text{thousand dollars}

    • Standard deviation of price: sy=29.6841 thousand dollarss_y = 29.6841\,\text{thousand dollars}

  • Standardized Products per House:

    • House 1 (x=2521x = 2521, y=400y = 400):

x−xˉsx=−1.3738732\frac{x - \bar{x}}{s_x} = -1.3738732

y−yˉsy=−1.5833419\frac{y - \bar{y}}{s_y} = -1.5833419

(x−xˉsx)(y−yˉsy)=2.1753110\left( \frac{x - \bar{x}}{s_x} \right) \left( \frac{y - \bar{y}}{s_y} \right) = 2.1753110

* House 2 (x=2555x = 2555, y=426y = 426):

x−xˉsx=−1.2477106\frac{x - \bar{x}}{s_x} = -1.2477106

y−yˉsy=−0.7074506\frac{y - \bar{y}}{s_y} = -0.7074506

(x−xˉsx)(y−yˉsy)=0.8826936\left( \frac{x - \bar{x}}{s_x} \right) \left( \frac{y - \bar{y}}{s_y} \right) = 0.8826936

* House 3 (x=2735x = 2735, y=428y = 428):

x−xˉsx=−0.5797912\frac{x - \bar{x}}{s_x} = -0.5797912

y−yˉsy=−0.6400744\frac{y - \bar{y}}{s_y} = -0.6400744

(x−xˉsx)(y−yˉsy)=0.3711095\left( \frac{x - \bar{x}}{s_x} \right) \left( \frac{y - \bar{y}}{s_y} \right) = 0.3711095

* House 4 (x=2846x = 2846, y=435y = 435):

x−xˉsx=−0.1679075\frac{x - \bar{x}}{s_x} = -0.1679075

y−yˉsy=−0.4042575\frac{y - \bar{y}}{s_y} = -0.4042575

(x−xˉsx)(y−yˉsy)=0.0678779\left( \frac{x - \bar{x}}{s_x} \right) \left( \frac{y - \bar{y}}{s_y} \right) = 0.0678779

* House 5 (x=3028x = 3028, y=469y = 469):

x−xˉsx=0.5074333\frac{x - \bar{x}}{s_x} = 0.5074333

y−yˉsy=0.7411387\frac{y - \bar{y}}{s_y} = 0.7411387

(x−xˉsx)(y−yˉsy)=0.3760785\left( \frac{x - \bar{x}}{s_x} \right) \left( \frac{y - \bar{y}}{s_y} \right) = 0.3760785

* House 6 (x=3049x = 3049, y=475y = 475):

x−xˉsx=0.5853572\frac{x - \bar{x}}{s_x} = 0.5853572

y−yˉsy=0.9432675\frac{y - \bar{y}}{s_y} = 0.9432675

(x−xˉsx)(y−yˉsy)=0.5521484\left( \frac{x - \bar{x}}{s_x} \right) \left( \frac{y - \bar{y}}{s_y} \right) = 0.5521484

* House 7 (x=3198x = 3198, y=488y = 488):

x−xˉsx=1.1382461\frac{x - \bar{x}}{s_x} = 1.1382461

y−yˉsy=1.3812131\frac{y - \bar{y}}{s_y} = 1.3812131

(x−xˉsx)(y−yˉsy)=1.5721604\left( \frac{x - \bar{x}}{s_x} \right) \left( \frac{y - \bar{y}}{s_y} \right) = 1.5721604

* House 8 (x=3198x = 3198, y=455y = 455):

x−xˉsx=1.1382461\frac{x - \bar{x}}{s_x} = 1.1382461

y−yˉsy=0.2695050\frac{y - \bar{y}}{s_y} = 0.2695050

(x−xˉsx)(y−yˉsy)=0.3067630\left( \frac{x - \bar{x}}{s_x} \right) \left( \frac{y - \bar{y}}{s_y} \right) = 0.3067630

  • Summation and Coefficient Result:

∑(x−xˉsx)(y−yˉsy)=6.3041423\sum \left( \frac{x - \bar{x}}{s_x} \right) \left( \frac{y - \bar{y}}{s_y} \right) = 6.3041423

r=6.30414238−1=6.30414237=0.9005918r = \frac{6.3041423}{8 - 1} = \frac{6.3041423}{7} = 0.9005918

  • Computational Implementation in R:

    • Entering vector coordinates and computing correlation directly:

    • Vector definition for house sizes: x = c(2521, 2555, 2735, 2846, 3028, 3049, 3198, 3198)

    • Vector definition for house prices: y = c(400, 426, 428, 435, 469, 475, 488, 455)

    • Correlation computation command: cor(x, y)

    • Console output value: 0.9005918

  • Additional Dataset Practice Exercise:

    • Dataset values: X=(2,4,6)X = (2, 4, 6), Y=(4,8,12)Y = (4, 8, 12)

    • Provided parameters: n=3n = 3, xˉ=4\bar{x} = 4, sx=2s_x = 2, yˉ=4\bar{y} = 4, sy=4s_y = 4

    • Step-by-step substitution into correlation formula:

r=13−1{[(2−42)(4−44)]+[(4−22)(8−44)]+[(6−22)(12−44)]}=1r = \frac{1}{3 - 1} \left\{ \left[ \left( \frac{2 - 4}{2} \right) \left( \frac{4 - 4}{4} \right) \right] + \left[ \left( \frac{4 - 2}{2} \right) \left( \frac{8 - 4}{4} \right) \right] + \left[ \left( \frac{6 - 2}{2} \right) \left( \frac{12 - 4}{4} \right) \right] \right\} = 1

Least-Squares Regression

  • Variable Roles in Regression:

    • Explanatory Variable (xx): Also known as the predictor or independent variable, used to explain or forecast variations in the response.

    • Outcome Variable (yy): Also known as the response or dependent variable, representing the target outcome being modeled.

    • In the real estate context, Size is the explanatory variable (xx) and Selling Price is the outcome variable (yy).

  • Least-Squares Estimation (LSE) Criterion:

    • A regression line models the trend of the data points.

    • Vertical distances between observed points and the line are residuals.

    • The least-squares regression line minimizes the sum of squared vertical distances from the individual observed data points to the fitted line.

    • A line with smaller overall vertical distances fits the data better than a line with large vertical distances.

Comparison of regression lines illustrating vertical distances to observed points
  • Mathematical Equation of the Regression Line:

    • The least-squares regression equation for predicting yy from xx is:

y^=b0+b1x\hat{y} = b_0 + b_1 x

  • Slope (b1b_1):

b1=r(sysx)b_1 = r \left( \frac{s_y}{s_x} \right)

  • yy-Intercept (b0b_0):

b0=yˉ−b1xˉb_0 = \bar{y} - b_1 \bar{x}

  • Numerical Computation for the Denver House Sample:

    • Parameter inputs: xˉ=2891.25\bar{x} = 2891.25, yˉ=447.0\bar{y} = 447.0, sx=269.4936s_x = 269.4936, sy=29.6841s_y = 29.6841, r=0.9006r = 0.9006

    • Slope computation:

b1=0.9006×(29.6841269.4936)=0.0992b_1 = 0.9006 \times \left( \frac{29.6841}{269.4936} \right) = 0.0992

  • Intercept computation:

b0=447.0−(0.0992×2891.25)=160.1939b_0 = 447.0 - (0.0992 \times 2891.25) = 160.1939

  • Final regression line equation:

y^=160.1939+0.0992x\hat{y} = 160.1939 + 0.0992 x

/

Scatterplot with the least-squares regression line superimposed
  • Linear Model Computation in R:

    • Syntax to obtain coefficients:

    • Command: coef(lm(y ~ x))

    • Output values: (Intercept) = 160.19391458, x = 0.09919795

    • Syntax to plot the regression line on the scatterplot:

    • Command: plot(x, y)

    • Command: abline(lm(y ~ x))

Prediction and Interpretation of Regression Elements

  • Making Predictions (y^\hat{y}):

    • The least-squares regression line predicts values of the outcome variable when given a specific value of the explanatory variable.

    • Interpolation vs. Extrapolation: Predictions are valid only within the observed domain of the explanatory variable data (xx). Predicting values outside this range constitutes extrapolation and can be unreliable.

    • Computation: Substituting an explanatory value into the regression formula produces the predicted value (y^\hat{y}).

    • Example Prediction: For a house size of 2891.25 square feet2891.25\,\text{square feet}:

y^=160.1939+0.0992×2891.25=447.0\hat{y} = 160.1939 + 0.0992 \times 2891.25 = 447.0

  • Point of Averages Property: The least-squares regression line always passes through the point of averages (xˉ\bar{x}, yˉ\bar{y}). Substituting x=xˉx = \bar{x} produces y^=yˉ\hat{y} = \bar{y}.

    • Interpretation of the Predicted Value (y^\hat{y}):

  • For any specified value of xx, the predicted value y^\hat{y} provides an estimate of the average outcome (yy-value) across all individuals or units with that specific xx-value.

  • Example Interpretation for House Size of 3000 sq ft3000\,\text{sq ft}:

y^=160.1939+(0.0992×3000)=457.8\hat{y} = 160.1939 + (0.0992 \times 3000) = 457.8

  • The estimated average price for all houses measuring 3000 square feet3000\,\text{square feet} is 457.8 thousand dollars457.8\,\text{thousand dollars}, equivalent to $457,800\$457,800.

    • Interpretation of the Slope (b1b_1):

  • The slope indicates the expected average change in the outcome variable for every 11-unit increase in the explanatory variable.

  • Given b1=0.0992b_1 = 0.0992:

    • For every 1 foot1\,\text{foot} (square foot) increase in the size of the house, the selling price increases on average by +0.0992 thousand dollars+0.0992\,\text{thousand dollars} ($99.20\$99.20).

  • Multi-Unit Change Example:

    • For an increase of 150 units150\,\text{units} (such as expanding house size from 17501750 to 1900 sq ft1900\,\text{sq ft}):

Δy^=0.0992×150=14.9 thousand dollars\Delta \hat{y} = 0.0992 \times 150 = 14.9\,\text{thousand dollars}

* The predicted selling price increases by 14.9 thousand dollars14.9\,\text{thousand dollars} ($14,900\$14,900) on average.
  • Interpretation of the yy-Intercept (b0b_0):

    • The yy-intercept represents the estimated value of y^\hat{y} when the explanatory variable x=0x = 0.

    • In many practical applications, interpreting b0b_0 is not meaningful because x=0x = 0 lies entirely outside the range of observed data (for example, a house of size 0 square feet0\,\text{square feet} has no physical reality).