mirror of
https://github.com/ArthurDanjou/ArtStudies.git
synced 2026-01-30 21:28:40 +01:00
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:
@@ -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)) +
|
||||
|
||||
Reference in New Issue
Block a user