Add TP1 GLM & DM Monte Carlo

This commit is contained in:
2024-11-05 10:33:07 +01:00
parent d1f3951285
commit f6f9dcce40
5 changed files with 1392 additions and 23 deletions

Binary file not shown.

View File

@@ -0,0 +1,345 @@
library(rmarkdown)
health <- read.table("health.txt", header = TRUE, sep = " ", dec = ".")
paged_table(health)
library(dplyr)
names(health)
library(dplyr)
names(health)
Health<-health[,2:4]
names(Ozone)
library(dplyr)
names(health)
Health<-health[,2:4]
names(Health)
library(dplyr)
names(health)
Health<-health[,2:5]
names(Health)
library(ggplot2)
library(plotly)
p1<-ggplot(health) + aes(x = T12, y = maxO3) + geom_point(col = 'red', size = 0.5) + geom_smooth(method = "lm", se = FALSE)
ggplotly(p1)
library(ggplot2)
library(plotly)
p1<-ggplot(health) + aes(x = age, y = y) + geom_point(col = 'red', size = 0.5) + geom_smooth(method = "lm", se = FALSE)
ggplotly(p1)
library(rmarkdown)
health <- read.table("health.txt", header = TRUE, sep = " ", dec = ".")
paged_table(health)
library(rmarkdown)
health <- read.table("health.txt", header = TRUE, sep = " ", dec = ".")
paged_table(health)
library(dplyr)
library(corrplot)
install.packages("corrplot")
library(dplyr)
library(corrplot)
correlation_matrix<-cor(Health)
library(dplyr)
library(corrplot)
correlation_matrix<-cor(health)
corrplot(correlation_matrix, order = 'hclust',addrect = 3)
GGally
install.packages("GGally")
library(dplyr)
library(corrplot)
correlation_matrix<-cor(health)
corrplot(correlation_matrix, order = 'hclust',addrect = 3)
library(GGally)
ggpairs(Ozone)
library(dplyr)
library(corrplot)
correlation_matrix<-cor(health)
corrplot(correlation_matrix, order = 'hclust',addrect = 3)
library(GGally)
ggpairs(health)
library(dplyr)
library(corrplot)
correlation_matrix<-cor(health)
corrplot(correlation_matrix, order = 'hclust',addrect = 3)
library(GGally)
ggpairs(health)
library(dplyr)
library(corrplot)
correlation_matrix<-cor(health)
corrplot(correlation_matrix, order = 'hclust',addrect = 3)
Health <- health[2:5]
library(dplyr)
library(corrplot)
correlation_matrix<-cor(Health)
corrplot(correlation_matrix, order = 'hclust',addrect = 3)
model <- lm(y ~ ., data = Health)
coefficients(model)
summary(model)
library(ggfortify)
install.packages("ggfortify")
library(ggfortify)
autoplot(mod,1)
library(ggfortify)
autoplot(model,1)
library(ggfortify)
autoplot(model,1)
autoplot(model,3)
library(ggfortify)
autoplot(model,1)
autoplot(model,3)
set.seed(0)
durbinWatsonTest(model)
install.packages("car")
library(ggfortify)
autoplot(model,1)
autoplot(model,3)
set.seed(0)
durbinWatsonTest(model)
library(ggfortify)
autoplot(model,1)
autoplot(model,3)
set.seed(0)
durbinWatsonTest(model)
library(ggfortify)
library(car)
autoplot(model,1)
autoplot(model,3)
set.seed(0)
durbinWatsonTest(model)
library(ggfortify)
library(car)
autoplot(model,1)
autoplot(model,3)
set.seed(0)
durbinWatsonTest(model)
library(ggfortify)
library(car)
autoplot(model,1)
autoplot(model,3)
set.seed(0)
durbinWatsonTest(model)
autoplot(model,2)
model <- lm(y ~ age, data = Health)
coefficients(model)
library(ggfortify)
library(car)
autoplot(model,1)
autoplot(model,3)
set.seed(0)
durbinWatsonTest(model)
autoplot(model,2)
model <- lm(y ~ ., data = Health)
coefficients(model)
library(ggfortify)
library(car)
autoplot(model,1)
autoplot(model,3)
set.seed(0)
durbinWatsonTest(model)
autoplot(model,2)
library(ggfortify)
library(car)
autoplot(model,1)
autoplot(model,3)
set.seed(0)
durbinWatsonTest(model)
autoplot(model,2)
model <- lm(y ~ ., data = Health)
coefficients(model)
summary(model)
model <- lm(y ~ age, data = Health)
coefficients(model)
summary(model)
library(ggfortify)
library(car)
autoplot(model,1)
model <- lm(y ~ ., data = Health)
coefficients(model)
summary(model)
library(ggfortify)
library(car)
autoplot(model,1)
library(GGally)
ggpairs(model)
library(GGally)
ggpairs(health)
library(GGally)
ggpairs(Health)
library(GGally)
ggpairs(Health, mapping = F)
library(GGally)
ggpairs(Health, progress = F)
model2 <- lm(y ~ age**2 + tri + chol, data = Health)
model2 <- lm(y ~ age**2 + tri + chol, data = Health)
summary(model2)
coefficients(model2)
library(ggfortify)
library(car)
autoplot(model2,1)
autoplot(model2,3)
set.seed(0)
durbinWatsonTest(model2)
autoplot(model2,2)
model2 <- lm(y ~ sqrt(age) + tri + chol, data = Health)
summary(model2)
coefficients(model2)
model2 <- lm(y ~ sqrt(age) + tri + chol, data = Health)
summary(model2)
coefficients(model2)
library(ggfortify)
library(car)
autoplot(model2,1)
Health2 <- Health
Health2[1] <- Health2[1]^2
model2 <- lm(y ~ ., data = Health)
summary(model2)
coefficients(model2)
library(ggfortify)
library(car)
autoplot(model2,1)
View(Health)
View(Health)
View(Health2)
View(Health2)
Health2 <- Health
View(Health2)
View(Health2)
Health2 <- Health
Health2[2] <- Health2[2]^2
model2 <- lm(y ~ ., data = Health)
summary(model2)
coefficients(model2)
library(ggfortify)
library(car)
autoplot(model2,1)
View(Health2)
View(Health2)
autoplot(model2,3)
Health2 <- Health
Health2[2] <- Health2[2]^2
model2 <- lm(y ~ ., data = Health2)
summary(model2)
coefficients(model2)
library(ggfortify)
library(car)
autoplot(model2,1)
autoplot(model2,3)
set.seed(0)
durbinWatsonTest(model2)
autoplot(model2,2)
Health2 <- Health
Health2[2] <- sqrt(Health2[2])
model2 <- lm(y ~ ., data = Health2)
summary(model2)
coefficients(model2)
library(ggfortify)
library(car)
autoplot(model2,1)
Health2 <- Health
Health2[2] <- Health2[2]^2
model2 <- lm(y ~ ., data = Health2)
summary(model2)
coefficients(model2)
Health2 <- Health
Health2[2] <- Health2[2]^2
model2 <- lm(y ~ ., data = Health2)
summary(model2)
coefficients(model2)
library(ggfortify)
library(car)
autoplot(model2,1)
autoplot(model2,3)
Health2 <- Health
Health2[6] <- Health2[2]^2
View(Health2)
View(Health2)
Health2 <- c(Health, c())
Health2[6] <- Health2[2]^2
Health2 <- c(Health, c())
Health2[5] <- Health2[2]^2
View(Health2)
View(Health2)
Health2 <- Health
Health2 <- append(Health2, Health[2]^2)
model2 <- lm(y ~ ., data = Health2)
View(Health2)
Health2 <- Health
Health2 <- append(Health2, Health[2]^2)
model2 <- lm(y ~ ., data = Health2)
Health2 <- Health
# Add to Health a new column with the square of the age named age_sq
Health2$age_sq <- Health2$age^2
model2 <- lm(y ~ ., data = Health2)
summary(model2)
coefficients(model2)
View(Health2)
Health2 <- Health
the age named age_sq
library(ggfortify)
library(car)
autoplot(model2,1)
Health2 <- Health
Health2$age_sq <- Health2$age^2
model2 <- lm(y ~ ., data = Health2)
summary(model2)
coefficients(model2)
library(ggfortify)
library(car)
autoplot(model2,1)
autoplot(model2,3)
autoplot(model2,2)
View(Health2)
View(Health2)
Health2 <- Health
Health2$age_sq <- sqrt(Health2$age)
model2 <- lm(y ~ ., data = Health2)
summary(model2)
coefficients(model2)
library(ggfortify)
library(car)
autoplot(model2,1)
Health2 <- Health
Health2$age_sq <- Health2$age^2
model2 <- lm(y ~ ., data = Health2)
summary(model2)
coefficients(model2)
library(ggfortify)
library(car)
autoplot(model2,1)
View(Health2)
View(Health2)
Health2 <- Health
Health2$age_sq <- Health2$age^2
Health2 <- Health2[1:99,]
model2 <- lm(y ~ ., data = Health2)
summary(model2)
coefficients(model2)
library(ggfortify)
library(car)
autoplot(model2,1)
Health2 <- Health
Health2$age_sq <- Health2$age^2
Health2 <- Health2[1:5,24]
model2 <- lm(y ~ ., data = Health2)
Health2 <- Health
Health2$age_sq <- Health2$age^2
Health2 <- Health2[1:5,]
model2 <- lm(y ~ ., data = Health2)
summary(model2)
coefficients(model2)
View(Health2)
Health2 <- Health
Health2$age_sq <- Health2$age^2
Health2 <- Health2[1:24,]
model2 <- lm(y ~ ., data = Health2)
summary(model2)
coefficients(model2)
library(ggfortify)
library(car)
autoplot(model2,1)
autoplot(model2,3)
set.seed(0)
durbinWatsonTest(model2)
autoplot(model2,2)
Health2 <- Health
Health2$age_sq <- Health2$age^2
Health2 <- Health2[1:24,]
model2 <- lm(y ~ ., data = Health2)
summary(model2)
coefficients(model2)

View File

@@ -23,16 +23,12 @@ summary(model)
```{r}
library(ggfortify)
library(car)
autoplot(model,1)
autoplot(model,1:3)
```
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
The QQPlot is align with the line y = x, so it is globally gaussian -> [P4] is verified
```{r}
set.seed(0)
@@ -41,12 +37,6 @@ 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)
@@ -68,16 +58,12 @@ coefficients(model2)
```{r}
library(ggfortify)
library(car)
autoplot(model2,1)
autoplot(model2,1:4)
```
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
The QQPlot is align with the line y = x, so it is gaussian -> [P4] is verified
```{r}
set.seed(0)
@@ -86,8 +72,3 @@ 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