Commit 7e98dbaa authored by Lie-Piang, Anouk's avatar Lie-Piang, Anouk
Browse files

Update ComponentModelv2_averages.Rmd

parent 81549004
......@@ -14,9 +14,8 @@ attach(Component_Data)
#detach(Component_Data)
```
```{r}
#rename variables
```{r}
starch = `Starch (%)`
protein = `Protein (%)`
fibre = `Fibre (%)`
......@@ -28,7 +27,6 @@ viscosity= log(`Final viscosity (mPa.s)`)
## Load libraries
```{r}
library(MASS)
library(tidyverse)
library(ggplot2)
......@@ -38,14 +36,10 @@ library(cowplot)
library(car)
library(R2HTML)
library(readxl)
```
# Create all possible formulas
```{r}
terms <- c("protein", "starch", "fibre", "rest",
"protein:starch", "protein:fibre", "starch:fibre",
"protein:starch:fibre")
......@@ -59,7 +53,6 @@ right_formulas <- lapply(model_terms, function(x) {
```
#Fitting the models with multiple linear regression
```{r}
Viscosity_formulas <- lapply(right_formulas, function(x) {
lapply(x, function(y) paste0("viscosity ~ ", y))
......@@ -73,7 +66,6 @@ Viscosity_models <- lapply(Viscosity_formulas, function(x) {
```
# Extract the AICs and the adjusted $R^2 to see which model is the best
```{r}
Viscosity_AIC <- lapply(Viscosity_models, function(x) {
lapply(x, AIC)
......@@ -108,7 +100,6 @@ Viscosity_quality <- lapply(1:length(Viscosity_R2), function(x) {
#Aikaike versus R2
```{r}
ggplot(Viscosity_quality) +
geom_point(aes(x = R.squared, y = AIC, colour = as.factor(n_terms)))
......@@ -130,7 +121,6 @@ AIC_arranged
```
# Print the summary of the 5 best models by AIC.
```{r}
print_models_AIC <- lapply(1:2, function(x) {
......@@ -144,7 +134,6 @@ HTML2clip(print_models_AIC) #to copy results to clipboard
```
# Print 5 best models according to the adjusted $R^2$.
```{r}
#print_models_R2 <-
lapply(1:5, function(x) {
......@@ -155,11 +144,9 @@ lapply(1:5, function(x) {
})
#HTML2clip(print_models_R2) #to copy results to clipboard
```
# Residuals vs fitted values for the top 5 models according to AIC.
```{r}
lapply(1:1, function(x) {
my_models <- Viscosity_models[[AIC_arranged$n_terms[x]]]
......@@ -170,7 +157,6 @@ lapply(1:1, function(x) {
})
```
# Histograms of residuals
```{r}
lapply(1:1, function(x) {
......@@ -188,7 +174,6 @@ lapply(1:1, function(x) {
```
#Plot parity plot
```{r}
lapply(1:1, function(x){
my_models <- Viscosity_models[[AIC_arranged$n_terms[x]]]
models_AIC <- lapply(my_models, AIC)
......@@ -207,5 +192,3 @@ lapply(1:1, function(x){
})
```
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment