R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this: #Numeric Summary:

my_data <- read.csv("/Users/shemaaeltayeb/Desktop/Intro to Statistics in R/student_data.csv")
summary(my_data)
##     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
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.3     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
data_type<-sapply(my_data,class)
print(data_type)
##      school         sex         age     address     famsize     Pstatus 
## "character" "character"   "integer" "character" "character" "character" 
##        Medu        Fedu        Mjob        Fjob      reason    guardian 
##   "integer"   "integer" "character" "character" "character" "character" 
##  traveltime   studytime    failures   schoolsup      famsup        paid 
##   "integer"   "integer"   "integer" "character" "character" "character" 
##  activities     nursery      higher    internet    romantic      famrel 
## "character" "character" "character" "character" "character"   "integer" 
##    freetime       goout        Dalc        Walc      health    absences 
##   "integer"   "integer"   "integer"   "integer"   "integer"   "integer" 
##          G1          G2          G3 
##   "integer"   "integer"   "integer"
#numeric_cols<-sapply(my_data,is.numeric)
#catocrical_cols<-sapply(my_data,is.character)
summary_for_numeric_cols<- my_data %>%
  summarise_if(is.numeric, list(
    Min=~min(.),
    Max=~max(.),
    Mean=~mean(.),
    Median=~median(.),
    Q1=~quantile(.,0.25),
    Q2=~quantile(.,0.75)
  ))

print(summary_for_numeric_cols)
##   age_Min Medu_Min Fedu_Min traveltime_Min studytime_Min failures_Min
## 1      15        0        0              1             1            0
##   famrel_Min freetime_Min goout_Min Dalc_Min Walc_Min health_Min absences_Min
## 1          1            1         1        1        1          1            0
##   G1_Min G2_Min G3_Min age_Max Medu_Max Fedu_Max traveltime_Max studytime_Max
## 1      3      0      0      22        4        4              4             4
##   failures_Max famrel_Max freetime_Max goout_Max Dalc_Max Walc_Max health_Max
## 1            3          5            5         5        5        5          5
##   absences_Max G1_Max G2_Max G3_Max age_Mean Medu_Mean Fedu_Mean
## 1           75     19     19     20  16.6962  2.749367  2.521519
##   traveltime_Mean studytime_Mean failures_Mean famrel_Mean freetime_Mean
## 1        1.448101       2.035443     0.3341772    3.944304      3.235443
##   goout_Mean Dalc_Mean Walc_Mean health_Mean absences_Mean  G1_Mean  G2_Mean
## 1   3.108861  1.481013  2.291139     3.55443      5.708861 10.90886 10.71392
##    G3_Mean age_Median Medu_Median Fedu_Median traveltime_Median
## 1 10.41519         17           3           2                 1
##   studytime_Median failures_Median famrel_Median freetime_Median goout_Median
## 1                2               0             4               3            3
##   Dalc_Median Walc_Median health_Median absences_Median G1_Median G2_Median
## 1           1           2             4               4        11        11
##   G3_Median age_Q1 Medu_Q1 Fedu_Q1 traveltime_Q1 studytime_Q1 failures_Q1
## 1        11     16       2       2             1            1           0
##   famrel_Q1 freetime_Q1 goout_Q1 Dalc_Q1 Walc_Q1 health_Q1 absences_Q1 G1_Q1
## 1         4           3        2       1       1         3           0     8
##   G2_Q1 G3_Q1 age_Q2 Medu_Q2 Fedu_Q2 traveltime_Q2 studytime_Q2 failures_Q2
## 1     9     8     18       4       3             2            2           0
##   famrel_Q2 freetime_Q2 goout_Q2 Dalc_Q2 Walc_Q2 health_Q2 absences_Q2 G1_Q2
## 1         5           4        4       2       3         5           8    13
##   G2_Q2 G3_Q2
## 1    13    14
summary_for_catocrical_cols<- my_data %>%
  summarise_if(is.character, list(
    unique_variable = ~ length(unique(.)),
    counts_variable=~n()
  ))
print(summary_for_catocrical_cols)
##   school_unique_variable sex_unique_variable address_unique_variable
## 1                      2                   2                       2
##   famsize_unique_variable Pstatus_unique_variable Mjob_unique_variable
## 1                       2                       2                    5
##   Fjob_unique_variable reason_unique_variable guardian_unique_variable
## 1                    5                      4                        3
##   schoolsup_unique_variable famsup_unique_variable paid_unique_variable
## 1                         2                      2                    2
##   activities_unique_variable nursery_unique_variable higher_unique_variable
## 1                          2                       2                      2
##   internet_unique_variable romantic_unique_variable school_counts_variable
## 1                        2                        2                    395
##   sex_counts_variable address_counts_variable famsize_counts_variable
## 1                 395                     395                     395
##   Pstatus_counts_variable Mjob_counts_variable Fjob_counts_variable
## 1                     395                  395                  395
##   reason_counts_variable guardian_counts_variable schoolsup_counts_variable
## 1                    395                      395                       395
##   famsup_counts_variable paid_counts_variable activities_counts_variable
## 1                    395                  395                        395
##   nursery_counts_variable higher_counts_variable internet_counts_variable
## 1                     395                    395                      395
##   romantic_counts_variable
## 1                      395
combine_numeric_categorical = bind_cols(summary_for_numeric_cols,summary_for_catocrical_cols)
print(combine_numeric_categorical)
##   age_Min Medu_Min Fedu_Min traveltime_Min studytime_Min failures_Min
## 1      15        0        0              1             1            0
##   famrel_Min freetime_Min goout_Min Dalc_Min Walc_Min health_Min absences_Min
## 1          1            1         1        1        1          1            0
##   G1_Min G2_Min G3_Min age_Max Medu_Max Fedu_Max traveltime_Max studytime_Max
## 1      3      0      0      22        4        4              4             4
##   failures_Max famrel_Max freetime_Max goout_Max Dalc_Max Walc_Max health_Max
## 1            3          5            5         5        5        5          5
##   absences_Max G1_Max G2_Max G3_Max age_Mean Medu_Mean Fedu_Mean
## 1           75     19     19     20  16.6962  2.749367  2.521519
##   traveltime_Mean studytime_Mean failures_Mean famrel_Mean freetime_Mean
## 1        1.448101       2.035443     0.3341772    3.944304      3.235443
##   goout_Mean Dalc_Mean Walc_Mean health_Mean absences_Mean  G1_Mean  G2_Mean
## 1   3.108861  1.481013  2.291139     3.55443      5.708861 10.90886 10.71392
##    G3_Mean age_Median Medu_Median Fedu_Median traveltime_Median
## 1 10.41519         17           3           2                 1
##   studytime_Median failures_Median famrel_Median freetime_Median goout_Median
## 1                2               0             4               3            3
##   Dalc_Median Walc_Median health_Median absences_Median G1_Median G2_Median
## 1           1           2             4               4        11        11
##   G3_Median age_Q1 Medu_Q1 Fedu_Q1 traveltime_Q1 studytime_Q1 failures_Q1
## 1        11     16       2       2             1            1           0
##   famrel_Q1 freetime_Q1 goout_Q1 Dalc_Q1 Walc_Q1 health_Q1 absences_Q1 G1_Q1
## 1         4           3        2       1       1         3           0     8
##   G2_Q1 G3_Q1 age_Q2 Medu_Q2 Fedu_Q2 traveltime_Q2 studytime_Q2 failures_Q2
## 1     9     8     18       4       3             2            2           0
##   famrel_Q2 freetime_Q2 goout_Q2 Dalc_Q2 Walc_Q2 health_Q2 absences_Q2 G1_Q2
## 1         5           4        4       2       3         5           8    13
##   G2_Q2 G3_Q2 school_unique_variable sex_unique_variable
## 1    13    14                      2                   2
##   address_unique_variable famsize_unique_variable Pstatus_unique_variable
## 1                       2                       2                       2
##   Mjob_unique_variable Fjob_unique_variable reason_unique_variable
## 1                    5                    5                      4
##   guardian_unique_variable schoolsup_unique_variable famsup_unique_variable
## 1                        3                         2                      2
##   paid_unique_variable activities_unique_variable nursery_unique_variable
## 1                    2                          2                       2
##   higher_unique_variable internet_unique_variable romantic_unique_variable
## 1                      2                        2                        2
##   school_counts_variable sex_counts_variable address_counts_variable
## 1                    395                 395                     395
##   famsize_counts_variable Pstatus_counts_variable Mjob_counts_variable
## 1                     395                     395                  395
##   Fjob_counts_variable reason_counts_variable guardian_counts_variable
## 1                  395                    395                      395
##   schoolsup_counts_variable famsup_counts_variable paid_counts_variable
## 1                       395                    395                  395
##   activities_counts_variable nursery_counts_variable higher_counts_variable
## 1                        395                     395                    395
##   internet_counts_variable romantic_counts_variable
## 1                      395                      395

question 2:

A set of at least 5 novel questions to investigate informed by the following:

Novel questions:

1-What is the impact of gender on student performance, considering subjects as (math, reading, writing)?

2-Are there any significant differences in student performance based on the race/ethnicity of students?

3-Is there a relationship between the level of parental education and the frequency of test preparation courses?

4- Do students with a higher number of siblings tend to perform better academically?

5-Does the type of lunch students receive impact their test scores?

column summaries:

A column summary provides a brief description of each column (attribute) in a dataset, including its data type and potential values. Here’s a column summary for the dataset with the specified columns:

1-school (Categorical): The name of the school (‘GP’ - Gabriel Pereira or ‘MS’ - Mousinho da Silveira).

2-sex (Categorical): Student’s gender (‘F’ for female or ‘M’ for male).

3-age (Numeric): Student’s age.

4-address (Categorical): Student’s home address type (‘U’ for urban or ‘R’ for rural).

5-famsize (Categorical): Family size (‘LE3’ for less or equal to 3, ‘GT3’ for greater than 3).

6-Pstatus (Categorical): Parent’s cohabitation status (‘A’ for apart or ‘T’ for together).

7-Medu (Numeric): Mother’s education level (0 - none, 1 - primary education, 2 - 5th to 9th grade, 3 - secondary education, 4 - higher education).

8-Fedu (Numeric): Father’s education level (0 - none, 1 - primary education, 2 - 5th to 9th grade, 3 - secondary education, 4 - higher education).

9-Mjob (Categorical): Mother’s job.

10-Fjob (Categorical): Father’s job.

11-reason (Categorical): Reason for choosing this school.

12-guardian (Categorical): Student’s guardian.

13-traveltime (Numeric): Travel time to school.

14-studytime (Numeric): Weekly study time.

15-failures (Numeric): Number of past class failures.

16-schoolsup (Categorical): Extra educational support (‘yes’ or ‘no’).

17-famsup (Categorical): Family educational support (‘yes’ or ‘no’).

18-paid (Categorical): Extra paid classes within the course subject (‘yes’ or ‘no’).

19-activities (Categorical): Extra-curricular activities (‘yes’ or ‘no’).

20-nursery (Categorical): Attended nursery school (‘yes’ or ‘no’).

21-higher (Categorical): Wants to take higher education (‘yes’ or ‘no’).

22-internet (Categorical): Internet access at home (‘yes’ or ‘no’).

23-romantic (Categorical): In a romantic relationship (‘yes’ or ‘no’).

24-famrel (Numeric): Quality of family relationships.

25-freetime (Numeric): Free time after school.

26-goout (Numeric): Going out with friends.

27-Dalc (Numeric): Weekday alcohol consumption.

28-Walc (Numeric): Weekend alcohol consumption.

29-health (Numeric): Current health status.

30-absences (Numeric): Number of school absences.

31-G1 (Numeric): First period grade.

32-G2 (Numeric): Second period grade.

33-G3 (Numeric): Final grade.

data documentation:

Dataset Name: Student Performance Dataset .

This dataset contains information related to student performance and various attributes that may influence academic outcomes.

project’s goals/purpose:

The aim of this project is to identify the factors that impact student performance.Explore how parental education levels (Medu and Fedu) correlate with student success and academic outcomes.Investigate and identify the key factors that influence student performance. Examine and compare the academic performance of male and female students to identify any gender-related disparities and their potential causes.Investigate reasons for choosing a particular school (reason) and determine if these reasons correlate with academic performance.Investigate the effect of family relationships (famrel) and free time (freetime) on student academic performance.

question 3:

Use of aggregation functions (other than the ones used from the first bullet, above) I.e., use these explore something interesting about your data

# Calculate the total number of students who have internet access
students_with_internet <- my_data %>%
  filter(internet == "yes") %>%
  summarise(total_students_with_internet = n())

print(students_with_internet)
##   total_students_with_internet
## 1                          329

question 4

A visual summary of at least 5 columns of your data This should include distributions at least In addition, you should consider trends, correlations, and interactions between variables Use different channels (e.g., color) to show how categorical variables interact with continuous variables

vis_summary_5_coulums <- my_data[, c("age", "studytime", "absences", "G1", "G3")]

# Distribution of Age
plot1 <- ggplot(vis_summary_5_coulums, aes(x = age)) +
  geom_histogram(binwidth = 1, fill = "lightblue", color = "black") +
  labs(title = "Distribution of Age",
       x = "Age",
       y = "Frequency")
print(plot1)