Practical Task 11
Step 0: Preparing the data
# Loading necessary libraries
library(ggplot2)
library(tidyr)
library(dplyr)##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(effects)## Loading required package: carData
## lattice theme set by effectsTheme()
## See ?effectsTheme for details.
# Loading the dataset
library(readr)
CASchools <- read_csv("~/Documents/DATA ANALYTICS/CASchools.csv")## Rows: 420 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (7): students, teachers, lunch, expenditure, english, read, math
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Step 1: Adding new variables for average test score and student-teacher ratio
CASchools$average <- (CASchools$read + CASchools$math) / 2
CASchools$ratio <- CASchools$students / CASchools$teachersStep 2: Linear regression with average test score as the dependent variable
# Include ratio, lunch, expenditure, and english as explanatory variables
model <- lm(average ~ ratio + lunch + expenditure + english, data = CASchools)Step 3: Checking the summary of the regression model
##
## Call:
## lm(formula = average ~ ratio + lunch + expenditure + english,
## data = CASchools)
##
## 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
Step 4: Interpretating the results
Coefficients:
- The coefficient for ratio is not statistically significant (p-value = 0.43).
- The coefficients for lunch, expenditure, and english are statistically significant at the 5% level.
Residuals:
- The residuals have a mean close to zero and are distributed around it.
- R-squared:
- The model explains approximately 78.34% of the variability in the average test scores.
F-statistic:
The F-statistic is highly significant (p-value < 2.2e-16), indicating that the overall model is significant.
Why can you not include the math and read test scores as further explanatory variables?
Including both math and read test scores as explanatory variables in the same regression model is avoided due to multicollinearity concerns. Since math and read scores are likely to be highly correlated, their inclusion can lead to unstable coefficients, reduced precision in estimating their effects, and challenges in interpretation. Multicollinearity makes it difficult to discern the unique contribution of each variable and can result in inflated standard errors. To address this issue, it’s common to choose one of the correlated variables or use techniques like principal component analysis (PCA) to create composite variables that retain the relevant information while minimizing collinearity. This ensures more reliable and interpretable regression results by avoiding the pitfalls associated with multicollinearity.
Null and alternative hypothesis for each of the t-tests of the coefficients.
Intercept (Intercept):
Null Hypothesis (H0): The intercept is equal to zero. Alternative Hypothesis (H1): The intercept is not equal to zero.
Ratio (ratio):
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.
Lunch (lunch):
Null Hypothesis (H0): The coefficient of the lunch variable is equal to zero. Alternative Hypothesis (H1): The coefficient of the lunch variable is not equal to zero.
Expenditure (expenditure):
Null Hypothesis (H0): The coefficient of the expenditure variable is equal to zero. Alternative Hypothesis (H1): The coefficient of the expenditure variable is not equal to zero.
English (english):
Null Hypothesis (H0): The coefficient of the english variable is equal to zero. Alternative Hypothesis (H1): The coefficient of the english variable is not equal to zero.
For each t-test, the null hypothesis assumes that the corresponding coefficient has no effect (equal to zero), while the alternative hypothesis suggests that there is a significant effect (not equal to zero). The p-values associated with each t-test will indicate whether there is enough evidence to reject the null hypothesis for each variable.
Conclusion
In conclusion, the variables lunch, expenditure, and english have a statistically significant linear relationship with the average test score, while the variable ratio does not show a significant effect.