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

Replace ComponentModelv2_averages.Rmd

parent e32b6fa2
......@@ -4,13 +4,6 @@ output:
html_notebook: default
html_document: default
---
# Set WD
```{r}
setwd("C:/ModelsLocal")
```
#Import data
```{r}
......@@ -20,17 +13,7 @@ Component_Data <- read_excel("ComponentData_Average_data.xlsx",
attach(Component_Data)
#detach(Component_Data)
```
#Check correlations
```{r}
corcheck <- read.csv("CorrelationCheck.csv")
cor(corcheck)
library(corrplot)
library(RColorBrewer)
M <-cor(corcheck)
corrplot(M, type="upper", order="hclust",
col=brewer.pal(n=8, name="RdYlBu"))
```
```{r}
#rename variables
......@@ -158,12 +141,6 @@ print_models_AIC <- lapply(1:2, function(x) {
})
HTML2clip(print_models_AIC) #to copy results to clipboard
#Other methods
#HTML2clip(summary(my_models[[my_index]]), filename = "cli[p")
#write.csv(as.data.frame(summary(my_models[[my_index]]$)),file = "mymodels_1.csv")
#sink(file = "sinktest.csv")
print(print_models_AIC)
#sink()
```
# Print 5 best models according to the adjusted $R^2$.
......@@ -194,46 +171,6 @@ lapply(1:1, function(x) {
```
#Predict
```{r}
lapply(1:1, function(x) {
my_models <- Viscosity_models[[AIC_arranged$n_terms[x]]]
models_AIC <- lapply(my_models, AIC)
my_index <- which(AIC_arranged$AIC[x] == models_AIC)
predict(my_models[[my_index]], data.frame(viscosity = 10))
})
```
#Extracting data point from QQ plot to see the deviating points
```{r}
lapply(1:1, function(x) {
my_models <- Viscosity_models[[AIC_arranged$n_terms[x]]]
models_AIC <- lapply(my_models, AIC)
my_index <- which(AIC_arranged$AIC[x] == models_AIC)
se <- sqrt(sum(my_models[[my_index]]$residuals^2) / my_models[[my_index]]$df.residual) ## Pearson residual standard error
hii <- lm.influence(my_models[[my_index]], do.coef = FALSE)$hat ## leverage
std.resi <- my_models[[my_index]]$residuals / (se * sqrt(1 - hii)) ## standardized residuals
par(mfrow = c(1,2))
qqnorm(std.resi, main = "my Q-Q"); qqline(std.resi, lty = 2)
plot(my_models[[my_index]], which = 2) ## only display Q-Q plot
x <- sort(abs(std.resi), decreasing = TRUE)
id <- as.integer(names(x))
id[1:20] #fill in the number of amount of data points to be extrated
})
```
# Histograms of residuals
```{r}
lapply(1:1, function(x) {
......@@ -249,23 +186,7 @@ lapply(1:1, function(x) {
})
```
#We check normality of the residuals with the Shapiro-Wilk normality test:
```{r}
lapply(1:5, function(x) {
my_models <- Viscosity_models[[AIC_arranged$n_terms[x]]]
models_AIC <- lapply(my_models, AIC)
my_index <- which(AIC_arranged$AIC[x] == models_AIC)
shapiro.test(residuals(my_models[[my_index]]))
})
```
#Plot parity plot
```{r}
lapply(1:1, function(x){
......@@ -287,16 +208,4 @@ lapply(1:1, function(x){
```
Durbin-Watson test:
```{r}
lapply(1:5, function(x) {
my_models <- Viscosity_models[[AIC_arranged$n_terms[x]]]
models_AIC <- lapply(my_models, AIC)
my_index <- which(AIC_arranged$AIC[x] == models_AIC)
durbinWatsonTest(residuals(my_models[[my_index]]))
})
```
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