mirror of
https://github.com/ArthurDanjou/ArtStudies.git
synced 2026-01-14 15:54:13 +01:00
Add TP2
This commit is contained in:
37
M1/General Linear Models/TP2/Cepages B TP2.csv
Normal file
37
M1/General Linear Models/TP2/Cepages B TP2.csv
Normal file
@@ -0,0 +1,37 @@
|
||||
Origine;Couleur;Alcool;pH;AcTot;Tartrique;Malique;Citrique;Acetique;Lactique
|
||||
Bordeaux;Blanc;12;2,84;89;21,1;21;4,3;16,9;9,3
|
||||
Bordeaux;Blanc;11,5;3,1;97;26,4;34,2;3,9;9,9;16
|
||||
Bordeaux;Blanc;14,6;2,96;99;20,7;21,8;8,1;19,7;11,2
|
||||
Bordeaux;Blanc;10,5;3,1;72;29,7;4,2;3,6;11,9;14,4
|
||||
Bordeaux;Blanc;14;3,29;76;22,3;9,3;4,7;20,1;21,6
|
||||
Bordeaux;Blanc;13,2;2,94;83;24,6;9,4;4,1;19,7;16,8
|
||||
Bordeaux;Blanc;11,2;2,91;95;39,4;14,5;4,2;19,4;10,5
|
||||
Bordeaux;Blanc;15,4;3,43;86;14,1;28,8;8,5;15;12,6
|
||||
Bordeaux;Blanc;13,4;3,35;76;18,9;23;6,4;14,4;10,5
|
||||
Bourgogne;Blanc;11,4;2,9;103;50;18;2,8;14,4;8,5
|
||||
Bourgogne;Blanc;10,5;2,95;118;31,6;38,8;4,2;13,1;15,7
|
||||
Bourgogne;Blanc;10,3;2,9;106;37,5;27,6;3,2;14,7;11,5
|
||||
Bourgogne;Blanc;13;2,89;97;42,1;19;3,6;11,2;15,7
|
||||
Bourgogne;Blanc;13,4;2,83;107;50,5;22,1;5;11,9;9,4
|
||||
Bourgogne;Blanc;12,7;3,11;101;33,2;17,5;5,3;9,4;36,7
|
||||
Bourgogne;Blanc;10,8;2,83;121;42,5;44,8;4,6;9,4;8,7
|
||||
Bourgogne;Blanc;12;3,25;76;44,2;1;3;17,5;17,6
|
||||
Bourgogne;Blanc;13,8;3,15;87;29,2;24,4;6,4;10,6;8,6
|
||||
Bordeaux;Rouge;11,7;3,49;74;22,5;3,6;1,4;21,8;24,3
|
||||
Bordeaux;Rouge;10,8;3,5;76;24,8;1,8;1,3;21,2;27
|
||||
Bordeaux;Rouge;10,1;3,66;72;25,7;5;0,8;20;29,7
|
||||
Bordeaux;Rouge;11,7;3,22;77;30,1;1,4;1,1;17,5;20,2
|
||||
Bordeaux;Rouge;10,2;3,45;74;23,5;2;1;20,6;23,5
|
||||
Bordeaux;Rouge;11,5;3,28;86;26,4;3,4;1,1;21,2;30,4
|
||||
Bordeaux;Rouge;11,2;3,35;73;30,8;1,8;3,6;10,3;22,2
|
||||
Bordeaux;Rouge;12,2;3,43;77;26,1;1,8;1,4;14,7;17,9
|
||||
Bordeaux;Rouge;11,2;3,41;75;27,2;3;1,5;15,9;23,1
|
||||
Bourgogne;Rouge;12,7;3,36;78;36,2;2;0,8;17,2;20,1
|
||||
Bourgogne;Rouge;13,1;3,48;87;30;2;1;22,1;37,4
|
||||
Bourgogne;Rouge;13,4;3,5;75;27,8;0;1,3;14,7;33,1
|
||||
Bourgogne;Rouge;13,2;3,59;76;30;3,6;2,2;13,4;40,9
|
||||
Bourgogne;Rouge;13,4;3,34;79;34,6;0;1,6;16,2;23,2
|
||||
Bourgogne;Rouge;13,8;3,46;76;27,7;1,2;3;16,2;30,4
|
||||
Bourgogne;Rouge;13,6;3,17;97;39,7;18,4;5,4;12,2;14,3
|
||||
Bourgogne;Rouge;14;3,42;76;32,6;0,4;2,1;14,7;20,4
|
||||
Bourgogne;Rouge;13,1;3,35;81;36;1,6;1,9;15;23,1
|
||||
|
86
M1/General Linear Models/TP2/TP2.rmd
Normal file
86
M1/General Linear Models/TP2/TP2.rmd
Normal file
@@ -0,0 +1,86 @@
|
||||
```{r}
|
||||
setwd('/Users/arthurdanjou/Workspace/studies/M1/General Linear Models/TP2')
|
||||
```
|
||||
|
||||
# Question 1 : Import dataset and check variables
|
||||
|
||||
```{r}
|
||||
library(dplyr)
|
||||
cepages <- read.csv("Cepages B TP2.csv", header = TRUE, sep = ";", dec = ",")
|
||||
cepages$Couleur <- as.factor(cepages$Couleur)
|
||||
cepages$Origine <- as.factor(cepages$Origine)
|
||||
cepages <- cepages %>% mutate(across(where(is.character), as.numeric))
|
||||
cepages <- cepages %>% mutate(across(where(is.integer), as.numeric))
|
||||
paged_table(cepages)
|
||||
```
|
||||
|
||||
# Question 2 : Table of counts
|
||||
|
||||
```{r}
|
||||
table(cepages$Origine, cepages$Couleur)
|
||||
```
|
||||
|
||||
# Question 3
|
||||
|
||||
## Display the table of average Ph according to couleur and average ph
|
||||
|
||||
```{r}
|
||||
tapply(cepages$pH, list(Couleur = cepages$Couleur), mean)
|
||||
```
|
||||
|
||||
## Display the table of average pH according to couleur and origine
|
||||
|
||||
```{r}
|
||||
tapply(cepages$pH, list(Couleur = cepages$Couleur, Origine = cepages$Origine), mean)
|
||||
```
|
||||
|
||||
# Question 4 : Regression lines of ph over AcTol for different Color
|
||||
```{r}
|
||||
library(ggplot2)
|
||||
|
||||
ggplot(cepages, aes(x = AcTot, y = pH, color = Couleur)) +
|
||||
geom_point(col = 'red', size = 0.5) +
|
||||
geom_smooth(method = "lm", se = F)
|
||||
|
||||
ggplot(cepages, aes(y = pH, x = AcTot, colour = Couleur, fill = Couleur)) +
|
||||
geom_boxplot(alpha = 0.5, outlier.alpha = 0)
|
||||
```
|
||||
|
||||
# Question 5 : Regression Ligne of pH over AcTot for different Origine
|
||||
|
||||
```{r}
|
||||
ggplot(cepages, aes(x = AcTot, y = pH, color = Origine)) +
|
||||
geom_smooth(method = 'lm', se = F) +
|
||||
geom_point(col = 'red', size = 0.5)
|
||||
|
||||
ggplot(cepages, aes(y = pH, x = AcTot, colour = Origine, fill = Origine)) +
|
||||
geom_boxplot(alpha = 0.5, outlier.alpha = 0)
|
||||
```
|
||||
|
||||
# Question 6 : ANOVA
|
||||
```{r}
|
||||
model_full <- lm(pH ~ Couleur, data = cepages)
|
||||
summary(model_full)
|
||||
```
|
||||
|
||||
```{r}
|
||||
autoplot(model_full, 1:4)
|
||||
```
|
||||
|
||||
[P1] is verified as the 'Residuals vs Fitted' plot shows that the points are well distributed around 0
|
||||
[P2] is verified as the 'Scale-Location' plot shows that the points are well distributed around 1
|
||||
[P4] is verified as the 'QQPlot' is aligned with the 'y=x' line
|
||||
|
||||
```{r}
|
||||
set.seed(12)
|
||||
durbinWatsonTest(model_full)
|
||||
```
|
||||
|
||||
[P3] is verified as the p-value is 0.7 > 0.05, so we do not reject H0 so the residuals are not auto-correlated
|
||||
|
||||
# Bonus : Type II Test
|
||||
|
||||
```{r}
|
||||
library(car)
|
||||
Anova(model_full)
|
||||
```
|
||||
Reference in New Issue
Block a user