Evamarija Batkoska 19568239

To commence, I will input the data set obtained from Kaggle, which provides insights into students’ academic performance, incorporating various variables that may influence their performance.

library(readr)
## Warning: package 'readr' was built under R version 4.3.2
exams <- read_csv("C:/Users/User/Desktop/exams.csv")
## Rows: 100 Columns: 8
## -- Column specification --------------------------------------------------------
## Delimiter: ","
## chr (5): gender, race/ethnicity, parental level of education, lunch, test pr...
## dbl (3): math score, reading score, writing score
## 
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
View(exams)

Now I will search for the data I will be using.

mydata <- read_csv("C:/Users/User/Desktop/exams.csv")
## Rows: 100 Columns: 8
## -- Column specification --------------------------------------------------------
## Delimiter: ","
## chr (5): gender, race/ethnicity, parental level of education, lunch, test pr...
## dbl (3): math score, reading score, writing score
## 
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(mydata)
mydata <- as.data.frame(mydata)

head(mydata)

Following that, I conducted a summary analysis of the data set, providing an overview of its key descriptive statistics and characteristics.

summary(mydata)
##     gender          race/ethnicity     parental level of education
##  Length:100         Length:100         Length:100                 
##  Class :character   Class :character   Class :character           
##  Mode  :character   Mode  :character   Mode  :character           
##                                                                   
##                                                                   
##                                                                   
##     lunch           test preparation course   math score     reading score  
##  Length:100         Length:100              Min.   : 32.00   Min.   :42.00  
##  Class :character   Class :character        1st Qu.: 55.75   1st Qu.:60.75  
##  Mode  :character   Mode  :character        Median : 65.00   Median :71.00  
##                                             Mean   : 66.42   Mean   :69.32  
##                                             3rd Qu.: 78.25   3rd Qu.:79.00  
##                                             Max.   :100.00   Max.   :96.00  
##  writing score   
##  Min.   : 34.00  
##  1st Qu.: 57.00  
##  Median : 69.50  
##  Mean   : 67.66  
##  3rd Qu.: 77.25  
##  Max.   :100.00

Research Question 1 (Statistical Hypothesis Testing):

Is there a significant difference in mean writing scores between students who completed the test preparation course and those who did not?

#H0: There is no significant difference in average scores in writing between students who completed the test preparation course and students who did not.

#H1: There is significant difference in average scores in writing between students who completed the test preparation course and students who did not.

str(mydata)
## 'data.frame':    100 obs. of  8 variables:
##  $ gender                     : chr  "male" "male" "male" "female" ...
##  $ race/ethnicity             : chr  "group E" "group B" "group D" "group C" ...
##  $ parental level of education: chr  "some college" "high school" "some college" "some college" ...
##  $ lunch                      : chr  "standard" "standard" "standard" "standard" ...
##  $ test preparation course    : chr  "none" "completed" "none" "none" ...
##  $ math score                 : num  79 81 68 61 65 62 77 47 81 85 ...
##  $ reading score              : num  77 76 54 70 67 75 66 61 81 86 ...
##  $ writing score              : num  69 78 59 67 67 75 67 59 81 85 ...
names(mydata)
## [1] "gender"                      "race/ethnicity"             
## [3] "parental level of education" "lunch"                      
## [5] "test preparation course"     "math score"                 
## [7] "reading score"               "writing score"
summary(mydata$`writing score`) #This is only doing a summary of the writing scores.
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   34.00   57.00   69.50   67.66   77.25  100.00
t_test_result <- t.test(`writing score` ~ `test preparation course`, data = mydata)
t_test_result
## 
##  Welch Two Sample t-test
## 
## data:  writing score by test preparation course
## t = 4.6486, df = 60.28, p-value = 1.868e-05
## alternative hypothesis: true difference in means between group completed and group none is not equal to 0
## 95 percent confidence interval:
##   6.882103 17.276627
## sample estimates:
## mean in group completed      mean in group none 
##                76.35714                64.27778

The p-value is very low (1.868e-05), which is less than the common significance level of 0.05. This suggests strong evidence against the null hypothesis With a low p-value, I would reject the null hypothesis. This suggests that there is a significant difference in mean writing scores between students who completed the test preparation course and those who did not.

Welch Test: The Welch Two Sample t-test is an adaptation of the t-test that does not assume equal variances between the groups. (meaning we have to continue with - wilcoxson rank sum test)

wilcox_test_result <- wilcox.test(`writing score` ~ `test preparation course`, data = mydata)
wilcox_test_result
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  writing score by test preparation course
## W = 1532.5, p-value = 5.708e-05
## alternative hypothesis: true location shift is not equal to 0

install.packages(“descrybeBy”)

library(describeBy)

describeBy(mydata\(`writing score`, group = mydata\)test preparation course)

!!!! In this section, I generated distinct tables for each group and conducted a comparative analysis. Despite encountering difficulties installing the “describeBy” package due to version constraints, I proceeded with the interpretation of the tables to draw meaningful insights into the performance differences between the two groups.!!

#Interpretation:

The group with completed test preparation has a higher mean and median writing score compared to the group with no test preparation. The higher mean and median scores suggest that, on average, students who completed the test preparation course performed better in writing compared to those who did not.

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.2

In the subsequent code, I looked for an assistance from an AI to craft a histogram showing the observed differences in writing scores, as illustrated in the following image.

ggplot(mydata, aes(x = `writing score`, fill = `test preparation course`)) +
  geom_histogram(position = "identity", alpha = 0.7, bins = 20, color = "black") +
  labs(title = "Histogram of Writing Scores by Test Preparation Course",
       x = "Writing Score", y = "Frequency") +
  scale_fill_manual(values = c("completed" = "blue", "none" = "orange")) +
  theme_minimal()

Research Question 2 (Regression Analysis):

Multiple linear regression - to analyze the relationship between the “writing score” (dependent variable) and the “math score” and “reading score” (explanatory variables)

regression_model <- lm(`writing score` ~ `math score` + `reading score`, data = mydata)
summary(regression_model)
## 
## Call:
## lm(formula = `writing score` ~ `math score` + `reading score`, 
##     data = mydata)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -11.5715  -2.2484   0.4682   2.9509   9.0415 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     -2.24402    2.55811  -0.877    0.383    
## `math score`     0.01655    0.05341   0.310    0.757    
## `reading score`  0.99257    0.06019  16.492   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.659 on 97 degrees of freedom
## Multiple R-squared:  0.889,  Adjusted R-squared:  0.8867 
## F-statistic: 388.3 on 2 and 97 DF,  p-value: < 2.2e-16

This code fits a linear regression model using “math score” and “reading score” as independent variables to predict the “writing score.” as dependent variable. It then provides a summary of the model, including coefficients, standard errors, t-values, and p-values.

#Interpretation: 1.Coefficients

Intercept (Constant): The intercept is estimated to be approximately -2.24. However, since the p-value is 0.383 (greater than 0.05), we fail to reject the null hypothesis that the intercept is zero. Meaning the intercept may not be statistically significant.

math score Coefficient: The coefficient for “math score” is estimated to be 0.01655. The p-value for this coefficient is 0.757 (greater than 0.05), indicating that “math score” is not a statistically significant predictor of “writing score” in this model.

reading score Coefficient: The coefficient for “reading score” is estimated to be 0.99257. The p-value for this coefficient is extremely small (p-value: < 2e-16), indicating that “reading score” is a highly significant predictor of “writing score.” I reading score increases by 1, on average the writing score increases by 0.99257.

#The residuals represent the differences between the observed and predicted values. The residual standard error is approximately 4.659.

#Multiple R-squared: The multiple R-squared value is 0.889, indicating that the model explains about 88.9% of the variance in the “writing score.”

#: The F-statistic is 388.3 with a very small p-value (< 2.2e-16). This suggests that the overall model (with both predictors) is statistically significant in predicting the “writing score.”

The model suggests that “reading score” is a highly significant predictor of “writing score,” while “math score” is not statistically significant in predicting “writing score” in this model.

The overall model is statistically significant, and it explains a substantial portion of the variance in the “writing score.”

options(repos = c(CRAN = "https://cran.r-project.org"))
install.packages("car")
## Installing package into 'C:/Users/User/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## package 'car' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\User\AppData\Local\Temp\RtmpGiIut9\downloaded_packages
library(car)
## Warning: package 'car' was built under R version 4.3.2
## Loading required package: carData
## Warning: package 'carData' was built under R version 4.3.2
scatterplot(`writing score` ~ `reading score`, data = mydata, 
            smooth = FALSE, main = "Scatterplot of Writing Score vs. Reading Score",
            xlab = "Reading Score", ylab = "Writing Score")

The positive slope of the regression line indicates a positive linear relationship between “reading score” and “writing score.” As “reading score” increases, “writing score” tends to increase as well.

The blue line in the scatter plot is the linear regression line fitted to the data. It represents the best-fit line that minimizes the sum of squared differences between the observed “writing score” values and the values predicted by the linear model.

With a strong linear relationship, you can use the regression line for prediction. Given a certain “reading score,” you can use the line to estimate the corresponding “writing score.”

#Assumptions Check

Assumptions such as normality of residuals, homoscedasticity, and others were checked.

SUMMARY

In this analysis, I investigated the relationship between test preparation, specifically whether completing the test preparation course, and writing scores. Utilizing Welch’s t-test and the Wilcoxon rank-sum test, I found a significant difference in writing scores between students who completed the course and those who did not. Subsequently, through multiple linear regression, I explored the predictive factors of writing scores, revealing that both math and reading scores significantly contribute to the variation in writing scores.