Refactor code for improved readability and consistency across R Markdown files

- Updated comments and code formatting in `3-td_ggplot2 - enonce.Rmd` for clarity.
- Enhanced code structure in `4-td_graphiques - enonce.Rmd` by organizing options and library calls.
- Replaced pipe operator `%>%` with `|>` in `Code_Lec3.Rmd` for consistency with modern R syntax.
- Cleaned up commented-out code and ensured consistent spacing in ggplot calls.
This commit is contained in:
2025-11-06 09:26:58 +01:00
parent 8f5f2b417c
commit 03bf0a4db2
10 changed files with 764 additions and 588 deletions

View File

@@ -1,5 +1,5 @@
```{r}
setwd('/Users/arthurdanjou/Workspace/studies/M1/General Linear Models/TP1-bis')
setwd("/Users/arthurdanjou/Workspace/studies/M1/General Linear Models/TP1-bis")
library(tidyverse)
options(scipen = 999, digits = 5)
@@ -56,8 +56,8 @@ summary(model)
coef(model)
```
```{r}
data <- data %>%
mutate(yhat = beta0 + beta1 * poids) %>%
data <- data |>
mutate(yhat = beta0 + beta1 * poids) |>
mutate(residuals = cholesterol - yhat)
data
@@ -71,8 +71,8 @@ ggplot(data, aes(x = poids, y = cholesterol)) +
```{r}
mean(data[, "cholesterol"])
mean(data[, "yhat"])
mean(data[, "residuals"]) %>% round(10)
cov(data[, "residuals"], data[, "poids"]) %>% round(10)
mean(data[, "residuals"]) |> round(10)
cov(data[, "residuals"], data[, "poids"]) |> round(10)
(RSS <- sum((data[, "residuals"])^2))
(TSS <- sum((y - mean(y))^2))
TSS - beta1 * Sxy
@@ -117,10 +117,10 @@ t <- qt(0.975, dof)
sigma_hat <- sigma(model)
n <- nrow(data)
data <- data %>%
data <- data |>
mutate(error = t *
sigma_hat *
sqrt(1 / n + (poids - mean(poids))^2 / RSS)) %>%
sqrt(1 / n + (poids - mean(poids))^2 / RSS)) |>
mutate(conf.low = yhat - error, conf.high = yhat + error, error = NULL)
ggplot(data, aes(x = poids, y = cholesterol)) +