# Step 1: Load the data
data <- read.csv("C:/Users/daniv/Downloads/CASchools.csv")
# Step 2: Add new variables
data$average <- (data$read + data$math) / 2
data$ratio <- data$students / data$teachers
Two new variables are created in the dataset: ‘average,’ which is the average of reading and math scores, and ‘ratio,’ which represents the student-teacher ratio.
# Step 3: Explore the relationship
correlation <- cor(data$average, data$ratio)
plot(data$ratio, data$average, main = "Scatter Plot", xlab = "Student-Teacher Ratio", ylab = "Average Test Score")
The correlation between ‘average’ and ‘ratio’ is calculated to assess
their relationship. A scatter plot is generated to visualize the
relationship between the student-teacher ratio and the average test
score.
# Step 4: Linear regression with control variables
model <- lm(average ~ ratio + lunch + expenditure + english, data = data)
summary(model)
##
## Call:
## lm(formula = average ~ ratio + lunch + expenditure + english,
## data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -33.366 -5.683 0.281 5.288 30.266
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 6.660e+02 9.460e+00 70.398 < 2e-16 ***
## ratio -2.354e-01 2.983e-01 -0.789 0.43
## lunch -5.464e-01 2.119e-02 -25.780 < 2e-16 ***
## expenditure 3.622e-03 8.766e-04 4.132 4.36e-05 ***
## english -1.283e-01 3.175e-02 -4.042 6.32e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.91 on 415 degrees of freedom
## Multiple R-squared: 0.7834, Adjusted R-squared: 0.7813
## F-statistic: 375.3 on 4 and 415 DF, p-value: < 2.2e-16
A linear regression is performed with ‘average’ as the dependent variable and ‘ratio,’ ‘lunch,’ ‘expenditure,’ and ‘english’ as explanatory (control) variables. The model summary provides detailed information, including coefficients and p-values.
# Step 5: Excluding math and read as explanatory variables
# Explanation provided in previous response
Excluding math and read as explanatory variables: Including both math and read as explanatory variables could lead to multicollinearity issues since they are highly correlated with the average test score (as they were used to compute it). Multicollinearity can make it difficult to interpret the individual effects of predictors.
Test for statistical significance: Check which explanatory variables yield a statistically significant linear relationship with the average test score.
# Step 6: Test for statistical significance
# Assuming 'model' is the name of your linear regression model
summary(model)
##
## Call:
## lm(formula = average ~ ratio + lunch + expenditure + english,
## data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -33.366 -5.683 0.281 5.288 30.266
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 6.660e+02 9.460e+00 70.398 < 2e-16 ***
## ratio -2.354e-01 2.983e-01 -0.789 0.43
## lunch -5.464e-01 2.119e-02 -25.780 < 2e-16 ***
## expenditure 3.622e-03 8.766e-04 4.132 4.36e-05 ***
## english -1.283e-01 3.175e-02 -4.042 6.32e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.91 on 415 degrees of freedom
## Multiple R-squared: 0.7834, Adjusted R-squared: 0.7813
## F-statistic: 375.3 on 4 and 415 DF, p-value: < 2.2e-16
In the summary output, look at the p-values associated with each coefficient. The null hypothesis for each coefficient is that the coefficient is equal to zero, and the alternative hypothesis is that it is not equal to zero. A low p-value (typically < 0.05) indicates that you can reject the null hypothesis and consider the variable statistically significant.
For example, the null hypothesis for the ratio coefficient would be:
Null hypothesis (H0): The coefficient of the ratio variable is equal to zero. Alternative hypothesis (H1): The coefficient of the ratio variable is not equal to zero.