# Multiple Regression Example in R

02-21-2024

Back to ~/csb

## Multiple Regression

The following example is based on:

Pedhazur, E. J. (1997). Multiple regression in behavioral research: Explanation and prediction (3rd ed.). Wadsworth.

From the chapter: “Elements of Multiple Regression Analysis: Two Independent Variables” (pp. 95-134).

``````Y  <- c(2,4,4,1,5,4,7,9,7,8,5,2,8,6,10,9,3,6,7,10)
X1 <- c(1,2,1,1,3,4,5,5,7,6,4,3,6,6,8,9,2,6,4,4)
X2 <- c(3,5,3,4,6,5,6,7,8,4,3,4,6,7,7,6,6,5,6,9)``````

where:

• $Y$ = reading achievement
• $X1$ = verbal aptitude
• $X2$ = achievement motivation

Objectives:

• Find the constants in the multiple regression equation: $Y' = a + {b_1}{X_1} + {b_2}{X_2}$
• Find the “proportion of variance ‘accounted for,’ that is $R^2_y.12$” (p. 99). I.e., how much does verbal aptitude and achievement motivation explain the variance in reading achievement.
• Test for statistical significance of the whole model or test if the coefficients are statistically significant from zero.
• Test the relative importance of $X1$ and $X2$ on $Y$.

(Note to self: Work through the section and address the above objectives and specific tests in more detail.)

``````mr.ex <- data.frame(Y,X1,X2)
fit.1 <- lm(Y ~ X1 + X2, data = mr.ex)
summary(fit.1)

Call:
lm(formula = Y ~ X1 + X2, data = mr.ex)

Residuals:
Min       1Q   Median       3Q      Max
-2.19708 -1.35307  0.04611  0.93246  2.32495

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept)  -0.4707     1.1942  -0.394 0.698353
X1            0.7046     0.1753   4.021 0.000887 ***
X2            0.5919     0.2438   2.428 0.026580 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.514 on 17 degrees of freedom
Multiple R-squared:  0.7229,    Adjusted R-squared:  0.6903
F-statistic: 22.17 on 2 and 17 DF,  p-value: 1.83e-05``````