mydata <- read.csv("~/Downloads/student_data.csv")
#I imported the dataset into R program. I downloaded the dataset from kaggle.com. The dataset is about student math exam scores, their age, gender and other related factors.
head(mydata)
## school sex age address famsize Pstatus Medu Fedu Mjob Fjob reason
## 1 GP F 18 U GT3 A 4 4 at_home teacher course
## 2 GP F 17 U GT3 T 1 1 at_home other course
## 3 GP F 15 U LE3 T 1 1 at_home other other
## 4 GP F 15 U GT3 T 4 2 health services home
## 5 GP F 16 U GT3 T 3 3 other other home
## 6 GP M 16 U LE3 T 4 3 services other reputation
## guardian traveltime studytime failures schoolsup famsup paid activities
## 1 mother 2 2 0 yes no no no
## 2 father 1 2 0 no yes no no
## 3 mother 1 2 3 yes no yes no
## 4 mother 1 3 0 no yes yes yes
## 5 father 1 2 0 no yes yes no
## 6 mother 1 2 0 no yes yes yes
## nursery higher internet romantic famrel freetime goout Dalc Walc health
## 1 yes yes no no 4 3 4 1 1 3
## 2 no yes yes no 5 3 3 1 1 3
## 3 yes yes yes no 4 3 2 2 3 3
## 4 yes yes yes yes 3 2 2 1 1 5
## 5 yes yes no no 4 3 2 1 2 5
## 6 yes yes yes no 5 4 2 1 2 5
## absences G1 G2 G3
## 1 6 5 6 6
## 2 4 5 5 6
## 3 10 7 8 10
## 4 2 15 14 15
## 5 4 6 10 10
## 6 10 15 15 15
#I used the function head to show the first 6 rows of this dataset in order to have a better understanding of the variables it contains.
summary(mydata)
## school sex age address
## Length:395 Length:395 Min. :15.0 Length:395
## Class :character Class :character 1st Qu.:16.0 Class :character
## Mode :character Mode :character Median :17.0 Mode :character
## Mean :16.7
## 3rd Qu.:18.0
## Max. :22.0
## famsize Pstatus Medu Fedu
## Length:395 Length:395 Min. :0.000 Min. :0.000
## Class :character Class :character 1st Qu.:2.000 1st Qu.:2.000
## Mode :character Mode :character Median :3.000 Median :2.000
## Mean :2.749 Mean :2.522
## 3rd Qu.:4.000 3rd Qu.:3.000
## Max. :4.000 Max. :4.000
## Mjob Fjob reason guardian
## Length:395 Length:395 Length:395 Length:395
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
## traveltime studytime failures schoolsup
## Min. :1.000 Min. :1.000 Min. :0.0000 Length:395
## 1st Qu.:1.000 1st Qu.:1.000 1st Qu.:0.0000 Class :character
## Median :1.000 Median :2.000 Median :0.0000 Mode :character
## Mean :1.448 Mean :2.035 Mean :0.3342
## 3rd Qu.:2.000 3rd Qu.:2.000 3rd Qu.:0.0000
## Max. :4.000 Max. :4.000 Max. :3.0000
## famsup paid activities nursery
## Length:395 Length:395 Length:395 Length:395
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
## higher internet romantic famrel
## Length:395 Length:395 Length:395 Min. :1.000
## Class :character Class :character Class :character 1st Qu.:4.000
## Mode :character Mode :character Mode :character Median :4.000
## Mean :3.944
## 3rd Qu.:5.000
## Max. :5.000
## freetime goout Dalc Walc
## Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.000
## 1st Qu.:3.000 1st Qu.:2.000 1st Qu.:1.000 1st Qu.:1.000
## Median :3.000 Median :3.000 Median :1.000 Median :2.000
## Mean :3.235 Mean :3.109 Mean :1.481 Mean :2.291
## 3rd Qu.:4.000 3rd Qu.:4.000 3rd Qu.:2.000 3rd Qu.:3.000
## Max. :5.000 Max. :5.000 Max. :5.000 Max. :5.000
## health absences G1 G2
## Min. :1.000 Min. : 0.000 Min. : 3.00 Min. : 0.00
## 1st Qu.:3.000 1st Qu.: 0.000 1st Qu.: 8.00 1st Qu.: 9.00
## Median :4.000 Median : 4.000 Median :11.00 Median :11.00
## Mean :3.554 Mean : 5.709 Mean :10.91 Mean :10.71
## 3rd Qu.:5.000 3rd Qu.: 8.000 3rd Qu.:13.00 3rd Qu.:13.00
## Max. :5.000 Max. :75.000 Max. :19.00 Max. :19.00
## G3
## Min. : 0.00
## 1st Qu.: 8.00
## Median :11.00
## Mean :10.42
## 3rd Qu.:14.00
## Max. :20.00
#I used summary function to get the summary of the data in this dataset.
#For the first part of the assignment, the hypothesis testing, I will focus on the RQ: “Is there a significant difference in average math scores between male and female students?”
#H0: There is no significant difference in average math scores between male and female students.
#H1: There is significant difference in average math scores between male and female students.
summary(mydata$G1)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 3.00 8.00 11.00 10.91 13.00 19.00
summary(mydata$G2)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.00 9.00 11.00 10.71 13.00 19.00
summary(mydata$G3)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.00 8.00 11.00 10.42 14.00 20.00
#I did the summary of the math grades of the students.
t_test_result <- t.test(G1 ~ sex, data = mydata)
t_test_result
##
## Welch Two Sample t-test
##
## data: G1 by sex
## t = -1.8237, df = 383.79, p-value = 0.06898
## alternative hypothesis: true difference in means between group F and group M is not equal to 0
## 95 percent confidence interval:
## -1.26715575 0.04764732
## sample estimates:
## mean in group F mean in group M
## 10.62019 11.22995
#We do not have evidence to reject H0. However we will still do the nonparametric test.
#Because of the result of the 95% confidence interval, we can say that we do not have enough evidence to claim that there is a significant difference in means between males and females.
wilcoxon_test_result <- wilcox.test(G1 ~ sex, data = mydata)
wilcoxon_test_result
##
## Wilcoxon rank sum test with continuity correction
##
## data: G1 by sex
## W = 17322, p-value = 0.05957
## alternative hypothesis: true location shift is not equal to 0
#We do not have enough evidence to reject H0 as p value is 0.056.
#The result is not statistically significant.
#Therefore, we can say that there may be a difference in the location distributions of math exam scores in male and female students.
#For the second part, the regression analysis, my RQ will be: “Can we predict a student’s writing score based on their parential level of education, their age and gender?”
#H0: There is no significant relationship between the writing score and other factors.
#H1: There is significant relationship between the writing score and other factors.
regression_model <- lm(G1 ~ sex+ age + Fjob + Mjob, data = mydata)
summary(regression_model)
##
## Call:
## lm(formula = G1 ~ sex + age + Fjob + Mjob, data = mydata)
##
## Residuals:
## Min 1Q Median 3Q Max
## -7.4833 -2.4061 -0.2042 2.3075 9.3402
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 12.99982 2.37552 5.472 8.03e-08 ***
## sexM 0.55848 0.33398 1.672 0.0953 .
## age -0.09808 0.12950 -0.757 0.4493
## Fjobhealth -1.00908 1.07841 -0.936 0.3500
## Fjobother -1.25923 0.76623 -1.643 0.1011
## Fjobservices -1.28185 0.79320 -1.616 0.1069
## Fjobteacher 0.74745 0.95974 0.779 0.4366
## Mjobhealth 1.72629 0.71353 2.419 0.0160 *
## Mjobother -0.31539 0.50968 -0.619 0.5364
## Mjobservices 0.78853 0.53725 1.468 0.1430
## Mjobteacher 0.56993 0.62659 0.910 0.3636
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.224 on 384 degrees of freedom
## Multiple R-squared: 0.08075, Adjusted R-squared: 0.05681
## F-statistic: 3.373 on 10 and 384 DF, p-value: 0.00031
#Here I created a linear regression model.
#Based on the coefficient sexM = 0.559, we can conclude the next explanation - Being male is connected with an increase of 0.559 in the math score G1 compared to being a female, considering all other variables stay the same.
#We reject H0 at p-value<0.001.
#Based on the p-value we can say there is a small and statistically significant relationship between the writing score and other factors.