HW1

Load Data:

load("~/ARE106/ARE106_HW1_F2025.RData")

Model 1:

(ols <- lm(colGPA ~ ACT, data =D)) 
## 
## Call:
## lm(formula = colGPA ~ ACT, data = D)
## 
## Coefficients:
## (Intercept)          ACT  
##     2.37607      0.02667
summary(ols)
## 
## Call:
## lm(formula = colGPA ~ ACT, data = D)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.81611 -0.24945 -0.01611  0.28389  0.73723 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  2.37607    0.30728   7.733 8.93e-12 ***
## ACT          0.02667    0.01265   2.108   0.0376 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3423 on 99 degrees of freedom
## Multiple R-squared:  0.04296,    Adjusted R-squared:  0.03329 
## F-statistic: 4.443 on 1 and 99 DF,  p-value: 0.03756
b0 <- 2.37607
b1 <- 0.02667 # 
R2 <- 0.04296 
#If student A has an achievement score that is 5 points higher than student B, what is the predicted difference between the two student's GPA?
pre.dif <- b1 *5

Model 2:

(ols2 <- lm(colGPA ~ ACT + skipped, data = D))
## 
## Call:
## lm(formula = colGPA ~ ACT + skipped, data = D)
## 
## Coefficients:
## (Intercept)          ACT      skipped  
##     2.33392      0.03326     -0.10596
summary(ols2)
## 
## Call:
## lm(formula = colGPA ~ ACT + skipped, data = D)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.93216 -0.23195 -0.02025  0.23414  0.81897 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  2.33392    0.29126   8.013 2.38e-12 ***
## ACT          0.03326    0.01213   2.743 0.007248 ** 
## skipped     -0.10596    0.03012  -3.518 0.000662 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3242 on 98 degrees of freedom
## Multiple R-squared:  0.1502, Adjusted R-squared:  0.1329 
## F-statistic: 8.664 on 2 and 98 DF,  p-value: 0.0003431
m2.b0 <- 2.334
m2.b1 <- 0.033
m2.b2 <- -0.106
m2.R2 <- 0.150
#Using Model 2, if Student A skips two more classes per week than Student B, what is the predicted difference between the two students’ college GPAs?
m2.pre.dif <- m2.b2 * 2

Model 3:

(ols3 <- lm(colGPA ~ ACT + skipped + hsGPA, data = D))
## 
## Call:
## lm(formula = colGPA ~ ACT + skipped + hsGPA, data = D)
## 
## Coefficients:
## (Intercept)          ACT      skipped        hsGPA  
##     1.68859      0.02458     -0.09968      0.25157
m3.b0 <- 1.688
m3.b1 <- 0.025 #
m3.b2 <- -0.099
m3.b3 <- 0.251
#Suppose Student A and Student B have the same ACT and skip the same number of classes, except Student A has a high school GPA of 3.1 and Student B has a high school GPA of 3.6. What is the predicted difference in Student A’s college GPA relative to Student B? 
m3.pre.dif <- m3.b3 * (3.1 - 3.6)

Perfect Multicollinearity:

ols4 <- lm(colGPA ~ ACT + skipped + hsGPA + soph + junior + senior + senior5, data = D)
summary(ols4)
## 
## Call:
## lm(formula = colGPA ~ ACT + skipped + hsGPA + soph + junior + 
##     senior + senior5, data = D)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.8046 -0.2155 -0.0432  0.2089  0.7605 
## 
## Coefficients: (1 not defined because of singularities)
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.712485   0.415480   4.122  8.1e-05 ***
## ACT          0.025481   0.012532   2.033  0.04484 *  
## skipped     -0.093195   0.030512  -3.054  0.00293 ** 
## hsGPA        0.228470   0.107247   2.130  0.03576 *  
## soph        -0.378304   0.349168  -1.083  0.28138    
## junior       0.085861   0.118082   0.727  0.46895    
## senior      -0.004864   0.114070  -0.043  0.96608    
## senior5            NA         NA      NA       NA    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.316 on 94 degrees of freedom
## Multiple R-squared:  0.2254, Adjusted R-squared:  0.176 
## F-statistic:  4.56 on 6 and 94 DF,  p-value: 0.0004209

Two-Step Regression:

firststage <- lm(ACT ~ skipped + hsGPA, data=D) #Estimate the first-stage linear regression
D$v <- resid(firststage) # OLS residual
summary(firststage)
## 
## Call:
## lm(formula = ACT ~ skipped + hsGPA, data = D)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -7.005 -1.506 -0.247  1.502  7.915 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  15.2355     2.8084   5.425 4.19e-07 ***
## skipped       0.4131     0.2371   1.742  0.08459 .  
## hsGPA         2.5063     0.8230   3.045  0.00299 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.581 on 98 degrees of freedom
## Multiple R-squared:  0.1083, Adjusted R-squared:  0.09007 
## F-statistic: 5.949 on 2 and 98 DF,  p-value: 0.003643
secondstage <- lm(colGPA ~ v, data=D) #Second-stage linear regression
summary(secondstage)
## 
## Call:
## lm(formula = colGPA ~ v, data = D)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.85042 -0.25636 -0.00729  0.27045  0.73738 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  3.01980    0.03424  88.183   <2e-16 ***
## v            0.02458    0.01347   1.825    0.071 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3442 on 99 degrees of freedom
## Multiple R-squared:  0.03255,    Adjusted R-squared:  0.02278 
## F-statistic: 3.331 on 1 and 99 DF,  p-value: 0.07102
coef(secondstage)["v"] #Extract v
##          v 
## 0.02458266
model_3 <- lm(colGPA ~ ACT + skipped + hsGPA, data=D) #Equation for model 3
summary(model_3)
## 
## Call:
## lm(formula = colGPA ~ ACT + skipped + hsGPA, data = D)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.83329 -0.20939 -0.03506  0.23983  0.74239 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.68859    0.39300   4.297 4.12e-05 ***
## ACT          0.02458    0.01240   1.983  0.05019 .  
## skipped     -0.09968    0.02955  -3.374  0.00107 ** 
## hsGPA        0.25157    0.10567   2.381  0.01923 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3167 on 97 degrees of freedom
## Multiple R-squared:  0.1972, Adjusted R-squared:  0.1723 
## F-statistic:  7.94 on 3 and 97 DF,  p-value: 8.661e-05
coef(model_3)["ACT"] #Extract ACT
##        ACT 
## 0.02458266