mirror of
https://github.com/ArthurDanjou/ArtStudies.git
synced 2026-01-14 18:59:59 +01:00
Add TP1
This commit is contained in:
93
M1/General Linear Models/TP1/TP1.Rmd
Normal file
93
M1/General Linear Models/TP1/TP1.Rmd
Normal file
@@ -0,0 +1,93 @@
|
||||
```{r}
|
||||
library(rmarkdown)
|
||||
health <- read.table("health.txt", header = TRUE, sep = " ", dec = ".")
|
||||
paged_table(health)
|
||||
```
|
||||
|
||||
```{r}
|
||||
Health <- health[2:5]
|
||||
|
||||
library(dplyr)
|
||||
library(corrplot)
|
||||
correlation_matrix<-cor(Health)
|
||||
corrplot(correlation_matrix, order = 'hclust',addrect = 3)
|
||||
```
|
||||
|
||||
```{r}
|
||||
model <- lm(y ~ ., data = Health)
|
||||
|
||||
coefficients(model)
|
||||
summary(model)
|
||||
```
|
||||
|
||||
```{r}
|
||||
library(ggfortify)
|
||||
library(car)
|
||||
autoplot(model,1)
|
||||
```
|
||||
|
||||
The points are not well distributed around 0 -> [P1] is not verified
|
||||
|
||||
```{r}
|
||||
autoplot(model,3)
|
||||
```
|
||||
|
||||
The points are not well distributed around 1 -> [P2] is not verified
|
||||
|
||||
```{r}
|
||||
set.seed(0)
|
||||
durbinWatsonTest(model)
|
||||
```
|
||||
|
||||
The p-value is 0.58 > 0.05 -> We do not reject H0 so the residuals are not autocorrelated -> [P3] is verified
|
||||
|
||||
```{r}
|
||||
autoplot(model,2)
|
||||
```
|
||||
|
||||
The QQPlot is align with the line y = x, so it is globally gaussian -> [P4] is verified
|
||||
|
||||
```{r}
|
||||
library(GGally)
|
||||
ggpairs(Health, progress = F)
|
||||
```
|
||||
|
||||
We observe that the variable age is correlated with the variable y. There is a quadratic relation between both variables.
|
||||
|
||||
```{r}
|
||||
Health2 <- Health
|
||||
Health2$age_sq <- Health2$age^2
|
||||
Health2 <- Health2[1:24,]
|
||||
|
||||
model2 <- lm(y ~ ., data = Health2)
|
||||
|
||||
summary(model2)
|
||||
coefficients(model2)
|
||||
```
|
||||
|
||||
```{r}
|
||||
library(ggfortify)
|
||||
library(car)
|
||||
autoplot(model2,1)
|
||||
```
|
||||
|
||||
The points are well distributed around 0 -> [P1] is verified
|
||||
|
||||
```{r}
|
||||
autoplot(model2,3)
|
||||
```
|
||||
|
||||
The points are not well distributed around 1 -> [P2] is verified
|
||||
|
||||
```{r}
|
||||
set.seed(0)
|
||||
durbinWatsonTest(model2)
|
||||
```
|
||||
|
||||
The p-value is 0.294 > 0.05 -> We do not reject H0 so the residuals are not autocorrelated -> [P3] is verified
|
||||
|
||||
```{r}
|
||||
autoplot(model2,2)
|
||||
```
|
||||
|
||||
The QQPlot is align with the line y = x, so it is gaussian -> [P4] is verified
|
||||
13
M1/General Linear Models/TP1/TP1.Rproj
Normal file
13
M1/General Linear Models/TP1/TP1.Rproj
Normal file
@@ -0,0 +1,13 @@
|
||||
Version: 1.0
|
||||
|
||||
RestoreWorkspace: Default
|
||||
SaveWorkspace: Default
|
||||
AlwaysSaveHistory: Default
|
||||
|
||||
EnableCodeIndexing: Yes
|
||||
UseSpacesForTab: Yes
|
||||
NumSpacesForTab: 2
|
||||
Encoding: UTF-8
|
||||
|
||||
RnwWeave: Sweave
|
||||
LaTeX: pdfLaTeX
|
||||
26
M1/General Linear Models/TP1/health.txt
Executable file
26
M1/General Linear Models/TP1/health.txt
Executable file
@@ -0,0 +1,26 @@
|
||||
"Id" "y" "age" "tri" "chol"
|
||||
"1" 0.344165525138049 61.3710178481415 255.998603752814 174.725536967162
|
||||
"2" 0.468648478326459 70.0093143060803 303.203193042427 191.830689532217
|
||||
"3" 0.0114155523307995 20.0903518591076 469.998112767935 126.269967628177
|
||||
"4" 0.472875443347101 71.2420938722789 146.105958395638 211.434927976225
|
||||
"5" 0 20.0899018836208 221.786231906153 240.876589370891
|
||||
"6" 0.143997241336945 43.2352053862996 266.090678572655 137.168468555901
|
||||
"7" 0.0414102111478797 25.8429238037206 372.907817093655 227.054411582649
|
||||
"8" 0.113811893132696 41.4695196016692 131.169532104395 131.447072112933
|
||||
"9" 0.109292366261165 35.7887735008262 430.398655338213 213.031274722889
|
||||
"10" 0.137468875629733 41.5359775861725 213.798411563039 248.683155018371
|
||||
"11" 0.0532629899999104 32.2978379554115 121.814481257461 216.917818398215
|
||||
"12" 0.353328774446386 61.3454213505611 407.593103558756 125.090295937844
|
||||
"13" 0.32693962726726 58.9427325245924 310.99092704244 234.297853410244
|
||||
"14" 0.160669457776164 45.8133233059198 146.624271371402 179.472973288503
|
||||
"15" 0.513130027249664 72.5317458156496 388.182279183529 179.566718712449
|
||||
"16" 0.617920854597292 80.2682227501646 227.86060355138 171.406586996745
|
||||
"17" 0.205049999385919 48.5804966441356 270.10274540633 216.100836060941
|
||||
"18" 0.0125951861990601 23.7895587598905 173.06959128473 246.627336950041
|
||||
"19" 0.321090735035653 58.1796469353139 451.47649507504 144.35365190031
|
||||
"20" 0.375862066828795 65.0117327272892 158.536369032227 127.305114357732
|
||||
"21" 0.0722375355431054 35.3545167273842 126.951391426846 193.100387256127
|
||||
"22" 0.0772129996198421 31.5452552819625 379.832963193767 235.720843761228
|
||||
"23" 0.0605716685358678 30.9160601114854 311.444346229546 191.08392035123
|
||||
"24" 0.157789955300155 44.7116475505754 164.532195450738 224.480235648807
|
||||
"25" 1 99 457.110102558509 239.30889045354
|
||||
Reference in New Issue
Block a user