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