library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.3     ✔ 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
library(ggthemes)
library(ggrepel)
library(broom)
library(lindia)
my_data <- read.csv("/Users/shemaaeltayeb/Desktop/STATISTIC IN R /student_data.csv")

Part 1:

Build a linear (or generalized linear) model as you like and Use whatever response variable and explanatory variables you prefer:

# Build a linear regression model
lm_model <- lm(G3 ~ Pstatus + paid + Walc + Dalc, data = my_data)

# Display the summary of the model
summary(lm_model)
## 
## Call:
## lm(formula = G3 ~ Pstatus + paid + Walc + Dalc, data = my_data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -11.1050  -1.8929   0.1101   2.9996   9.9009 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  11.3965     0.8531  13.359   <2e-16 ***
## PstatusT     -0.9643     0.7541  -1.279   0.2018    
## paidyes       1.0059     0.4622   2.176   0.0301 *  
## Walc         -0.1046     0.2344  -0.446   0.6556    
## Dalc         -0.2285     0.3391  -0.674   0.5008    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.561 on 390 degrees of freedom
## Multiple R-squared:  0.01886,    Adjusted R-squared:  0.008793 
## F-statistic: 1.874 on 4 and 390 DF,  p-value: 0.1142

Created the linear regression model and indicates that the response variable is G3, and the predictor variables are Pstatus, paid, Walc, and Dalc from the dataset.

The summarize, the model does not seem to have a strong explanatory power based on the variables (Pstatus, paid, Walc, and Dalc), as indicated by the low R-squared values and non-significant coefficients for most predictors. This means that these variables do not provide a strong linear relationship with the final grade (G3).

Part 2:

Use the tools from previous weeks to diagnose the model and Highlight any issues with the model:

First,Plot the residuals against the fitted values to check for patterns:

plot(lm_model, which = 1)

Second, Plot Normal Q-Q to check if the points in the normal Q-Q plot deviate significantly from the diagonal line:

plot(lm_model, which = 2)

In the Residuals vs. Fitted Values plot, I noticed that the data points deviate both above and below the horizontal line. However, on the Normal Q-Q plot, most of the points closely follow the diagonal line, suggesting that the residuals approximately follow a normal distribution. The line in the Q-Q plot represents the expected distribution of the residuals, and the data points indicates a good fit to a normal distribution.

Part 3:

Interpret at least one of the coefficients:

lm_model <- lm(G3 ~ Pstatus + paid + Walc + Dalc, data = my_data)
summary(lm_model)
## 
## Call:
## lm(formula = G3 ~ Pstatus + paid + Walc + Dalc, data = my_data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -11.1050  -1.8929   0.1101   2.9996   9.9009 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  11.3965     0.8531  13.359   <2e-16 ***
## PstatusT     -0.9643     0.7541  -1.279   0.2018    
## paidyes       1.0059     0.4622   2.176   0.0301 *  
## Walc         -0.1046     0.2344  -0.446   0.6556    
## Dalc         -0.2285     0.3391  -0.674   0.5008    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.561 on 390 degrees of freedom
## Multiple R-squared:  0.01886,    Adjusted R-squared:  0.008793 
## F-statistic: 1.874 on 4 and 390 DF,  p-value: 0.1142

Interpret the coefficient for the paid_yes(Student get extra paid classes outside of the school) variable in the given linear regression model:

The estimate for paidyes is 1.0059. This means that students who receive extra educational support have a final grade (G3) that is approximately 1.0059 units higher than students who do not receive extra educational support.

The t-value for paidyes is 2.176. A larger t-value indicates that the coefficient is more significant.

The p-value for paidyes is 0.0301 and since the p-value is less than the significance level of 0.05, that menas we have evidence to reject the null hypothesis. Therefore, the paidyes variable is statistically significant in predicting the final grade.

The positive coefficient for paidyes indicates that students who receive extra educational support tend to have higher final grades compared to students who do not receive such support. This suggesting that the provision of extra educational support has a positive impact on students’ academic performance.

Interpret the coefficient for the PstatusT variable in the given linear regression model:

The estimate for PstatusT is -0.9643. This means that, on average, students whose parents are not living together (PstatusT = 1) have final grades (G3) that are approximately 0.9643 units lower than students whose parents are living together.

The t-value for PstatusT is -1.279. Since the t-value is relatively small, that means the coefficient for PstatusT is not statistically significant.

The p-value associated with PstatusT is 0.2018. Since the p-value (0.2018) is larger than significance level of 0.05, we do not have enough evidence to reject the null hypothesis. Therefore, the PstatusT variable is not statistically significant in predicting the final grade.

The non-significant coefficient for PstatusT suggests that the parent status (PstatusT) does not have a statistically significant impact on students’ final grades.