Step 1: MLR of Permeability given all well logs without Facies
karpur_data <- read.csv("karpur.csv")
model1 <- lm(k.core ~ . - Facies , data = karpur_data)
adjusted_r2_model1<- summary(model1)$adj.r.squared
rmse_model1 <- sqrt(mean(residuals(model1)^2))
cat("Adjusted R2:", adjusted_r2_model1, " | RMSE:", rmse_model1, "\n")
## Adjusted R2: 0.5841845 | RMSE: 1430.118
Plot measured vs. predicted permeability respect to depth.
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.2
predicted1 <- predict(model1, newdata = karpur_data)
ggplot(karpur_data) +
geom_line(aes(x = depth , y = k.core, color = "Measured permeability")) +
geom_line(aes(x = depth, y = predicted1, color = "Predicted permeability")) +
labs(title = "Predicted vs Measured Permeability with Respect to Depth",
x = "Depth",
y = "Permeability",
color = "Legend") +
scale_color_manual(values = c("Measured permeability" = "red",
"Predicted permeability" = "black")) +
theme_minimal()
Step 2: Stepwise Elimination (Model 1)
model2 <- step(model1 , direction = "both")
## Start: AIC=11926.91
## k.core ~ (depth + caliper + ind.deep + ind.med + gamma + phi.N +
## R.deep + R.med + SP + density.corr + density + phi.core +
## Facies + phi.core.frac) - Facies
##
##
## Step: AIC=11926.91
## k.core ~ depth + caliper + ind.deep + ind.med + gamma + phi.N +
## R.deep + R.med + SP + density.corr + density + phi.core
##
## Df Sum of Sq RSS AIC
## - density.corr 1 19799 1675068713 11925
## - phi.N 1 3906205 1678955118 11927
## <none> 1675048914 11927
## - SP 1 13394190 1688443104 11931
## - R.deep 1 28897686 1703946599 11939
## - caliper 1 29214826 1704263740 11939
## - depth 1 54372650 1729421563 11951
## - ind.deep 1 76022788 1751071701 11961
## - R.med 1 86603706 1761652619 11966
## - ind.med 1 98823752 1773872666 11972
## - density 1 106221406 1781270319 11975
## - phi.core 1 123125117 1798174031 11983
## - gamma 1 416312526 2091361440 12107
##
## Step: AIC=11924.92
## k.core ~ depth + caliper + ind.deep + ind.med + gamma + phi.N +
## R.deep + R.med + SP + density + phi.core
##
## Df Sum of Sq RSS AIC
## <none> 1675068713 11925
## - phi.N 1 4564880 1679633593 11925
## + density.corr 1 19799 1675048914 11927
## - SP 1 13491079 1688559792 11930
## - R.deep 1 28896144 1703964857 11937
## - caliper 1 29253869 1704322581 11937
## - depth 1 54825159 1729893872 11949
## - ind.deep 1 77573926 1752642639 11960
## - R.med 1 86772220 1761840933 11964
## - ind.med 1 100740701 1775809413 11971
## - density 1 114209586 1789278299 11977
## - phi.core 1 124694278 1799762991 11982
## - gamma 1 417015194 2092083907 12105
adjusted_r2_step2 <- summary(model2)$adj.r.squared
rmse_step2 <- sqrt(mean(residuals(model2)^2))
cat("Adjusted R2:", adjusted_r2_step2, " | RMSE:", rmse_step2, "\n")
## Adjusted R2: 0.5846949 | RMSE: 1430.126
Plot measured vs. predicted permeability respect to depth.
predicted2 <- predict(model2, newdata = karpur_data)
ggplot(karpur_data) +
geom_line(aes(x = depth, y = k.core, color= "Measured permeability")) +
geom_line(aes(x = depth , y = predicted2, color = "Predicted permeability")) +
labs(title = "Predicted vs Measured Permeability with Respect to Depth",
x = "Depth",
y = "Permeability",
color = "Legend") +
scale_color_manual(values = c("Measured permeability" = "blue",
"Predicted permeability" = "black")) +
theme_minimal()
Step 3: MLR of Permeability given all well logs with Facies
model3 <- lm(k.core ~ . , data = karpur_data)
adjusted_r2_model3 <- summary(model3)$adj.r.squared
rmse_model3 <- sqrt(mean(residuals(model3)^2))
cat("Adjusted R2:", adjusted_r2_model3, " | RMSE:", rmse_model3, "\n")
## Adjusted R2: 0.6814911 | RMSE: 1246.201
Plot measured vs. predicted permeability respect to depth.
predicted3 <- predict(model3, newdata = karpur_data)
ggplot(karpur_data) +
geom_line(aes(x = depth, y = k.core, color = "Measured permeability")) +
geom_line(aes(x = depth, y = predicted3, color = "Predicted permeability")) +
labs(title = "Predicted vs Measured Permeability with Respect to Depth",
x = "Depth",
y = "Permeability",
color = "Legend") +
scale_color_manual(values = c("Measured permeability" = "green",
"Predicted permeability" = "black")) +
theme_minimal()
Step 4: Stepwise Elimination (Model 3)
model4 <- step(model3, direction = "both")
## Start: AIC=11715.43
## k.core ~ depth + caliper + ind.deep + ind.med + gamma + phi.N +
## R.deep + R.med + SP + density.corr + density + phi.core +
## Facies + phi.core.frac
##
##
## Step: AIC=11715.43
## k.core ~ depth + caliper + ind.deep + ind.med + gamma + phi.N +
## R.deep + R.med + SP + density.corr + density + phi.core +
## Facies
##
## Df Sum of Sq RSS AIC
## - ind.deep 1 16793 1271937992 11713
## - ind.med 1 356746 1272277945 11714
## - density.corr 1 453661 1272374861 11714
## - phi.N 1 2953609 1274874809 11715
## - caliper 1 3063007 1274984206 11715
## <none> 1271921199 11715
## - density 1 6217927 1278139127 11717
## - SP 1 8171834 1280093033 11719
## - R.deep 1 22117394 1294038593 11728
## - depth 1 36466976 1308388176 11737
## - R.med 1 61690461 1333611660 11752
## - gamma 1 92579723 1364500923 11771
## - phi.core 1 112793101 1384714301 11783
## - Facies 7 403127714 1675048914 11927
##
## Step: AIC=11713.44
## k.core ~ depth + caliper + ind.med + gamma + phi.N + R.deep +
## R.med + SP + density.corr + density + phi.core + Facies
##
## Df Sum of Sq RSS AIC
## - density.corr 1 437546 1272375538 11712
## - phi.N 1 2938766 1274876758 11713
## - caliper 1 3074396 1275012389 11713
## <none> 1271937992 11713
## + ind.deep 1 16793 1271921199 11715
## - density 1 6228928 1278166920 11715
## - ind.med 1 6905855 1278843848 11716
## - SP 1 8191802 1280129794 11717
## - R.deep 1 22125695 1294063687 11726
## - depth 1 39139470 1311077462 11736
## - R.med 1 61773953 1333711946 11750
## - gamma 1 92865220 1364803212 11769
## - phi.core 1 112960440 1384898432 11781
## - Facies 7 479133709 1751071701 11961
##
## Step: AIC=11711.72
## k.core ~ depth + caliper + ind.med + gamma + phi.N + R.deep +
## R.med + SP + density + phi.core + Facies
##
## Df Sum of Sq RSS AIC
## - caliper 1 2980713 1275356252 11712
## <none> 1272375538 11712
## - phi.N 1 3279032 1275654571 11712
## + density.corr 1 437546 1271937992 11713
## - density 1 5792837 1278168375 11713
## + ind.deep 1 677 1272374861 11714
## - ind.med 1 6813959 1279189497 11714
## - SP 1 8391302 1280766840 11715
## - R.deep 1 22009402 1294384940 11724
## - depth 1 38705776 1311081314 11734
## - R.med 1 61436819 1333812357 11748
## - gamma 1 93974329 1366349868 11768
## - phi.core 1 115336515 1387712053 11781
## - Facies 7 480267100 1752642639 11960
##
## Step: AIC=11711.64
## k.core ~ depth + ind.med + gamma + phi.N + R.deep + R.med + SP +
## density + phi.core + Facies
##
## Df Sum of Sq RSS AIC
## - phi.N 1 2534906 1277891157 11711
## <none> 1275356252 11712
## + caliper 1 2980713 1272375538 11712
## + density.corr 1 343863 1275012389 11713
## + ind.deep 1 5597 1275350654 11714
## - density 1 7270311 1282626562 11714
## - SP 1 8733336 1284089587 11715
## - ind.med 1 12924050 1288280301 11718
## - R.deep 1 22449117 1297805369 11724
## - depth 1 51507476 1326863728 11742
## - R.med 1 60137982 1335494234 11747
## - phi.core 1 112564835 1387921086 11779
## - gamma 1 141535555 1416891807 11796
## - Facies 7 520094756 1795451008 11978
##
## Step: AIC=11711.26
## k.core ~ depth + ind.med + gamma + R.deep + R.med + SP + density +
## phi.core + Facies
##
## Df Sum of Sq RSS AIC
## <none> 1277891157 11711
## + phi.N 1 2534906 1275356252 11712
## + caliper 1 2236587 1275654571 11712
## - density 1 5155969 1283047127 11713
## + density.corr 1 624807 1277266351 11713
## + ind.deep 1 1762 1277889395 11713
## - SP 1 8515796 1286406953 11715
## - ind.med 1 10944937 1288836095 11716
## - R.deep 1 23273312 1301164469 11724
## - depth 1 49725248 1327616405 11740
## - R.med 1 59454645 1337345802 11746
## - phi.core 1 110154394 1388045551 11777
## - gamma 1 219059092 1496950249 11839
## - Facies 7 526383446 1804274603 11980
adjusted_r2_step4 <- summary(model4)$adj.r.squared
rmse_step4 <- sqrt(mean(residuals(model4)^2))
cat("Adjusted R2:", adjusted_r2_step4, " | RMSE:", rmse_step4, "\n")
## Adjusted R2: 0.6815901 | RMSE: 1249.122
Plot measured vs. predicted permeability respect to depth.
predicted4 <- predict(model4, newdata = karpur_data)
ggplot(karpur_data) +
geom_line(aes(x = depth, y = k.core, color = "Measured permeability")) +
geom_line(aes(x = depth, y = predicted4, color = "Predicted permeability")) +
labs(title = "Predicted vs Measured Permeability with Respect to Depth",
x = "Depth",
y = "Permeability",
color = "Legend") +
scale_color_manual(values = c("Measured permeability" = "orange",
"Predicted permeability" = "black")) +
theme_minimal()
Step 5: MLR of Log10(Permeability) with all well logs and Facies
karpur_data$log10_Permeability <-log10(karpur_data$k.core)
model5<- lm(log10_Permeability~.-k.core,data=karpur_data)
adjusted_r2_model5<- summary(model5)$adj.r.squared
rmse_model5 <- sqrt(mean(residuals(model5)^2))
cat("Adjusted R2:", adjusted_r2_model5, " | RMSE:", rmse_model1, "\n")
## Adjusted R2: 0.6729783 | RMSE: 1430.118
Plot measured vs. predicted log10(permeability) respect to depth.
predicted5 <-predict(model5,data=Karpur)
Predicted_k_5<-10^predicted5
ggplot(karpur_data) +
geom_line(aes(x = depth, y = k.core, color = "Measured permeability")) +
geom_line(aes(x = depth, y = Predicted_k_5, color = "Predicted permeability")) +
labs(title = "Predicted vs Measured Permeability with Respect to Depth",
x = "Depth",
y = "Permeability",
color = "Legend") +
scale_color_manual(values = c("Measured permeability" = "red",
"Predicted permeability" = "black")) +
theme_minimal()
Step 6: Stepwise Elimination (Model 5)
model6 <- step(model5, direction = "both")
## Start: AIC=-1779.02
## log10_Permeability ~ (depth + caliper + ind.deep + ind.med +
## gamma + phi.N + R.deep + R.med + SP + density.corr + density +
## phi.core + k.core + Facies + phi.core.frac) - k.core
##
##
## Step: AIC=-1779.02
## log10_Permeability ~ depth + caliper + ind.deep + ind.med + gamma +
## phi.N + R.deep + R.med + SP + density.corr + density + phi.core +
## Facies
##
## Df Sum of Sq RSS AIC
## - ind.med 1 0.1213 88.981 -1779.9
## - density.corr 1 0.1440 89.004 -1779.7
## - ind.deep 1 0.1816 89.042 -1779.3
## <none> 88.860 -1779.0
## - R.deep 1 0.2696 89.130 -1778.5
## - depth 1 0.2754 89.135 -1778.5
## - caliper 1 0.3253 89.185 -1778.0
## - R.med 1 0.3763 89.236 -1777.6
## - SP 1 0.4617 89.322 -1776.8
## - phi.N 1 2.2710 91.131 -1760.3
## - density 1 3.0160 91.876 -1753.7
## - gamma 1 3.6713 92.531 -1747.9
## - Facies 7 7.0758 95.936 -1730.3
## - phi.core 1 27.4982 116.358 -1560.2
##
## Step: AIC=-1779.9
## log10_Permeability ~ depth + caliper + ind.deep + gamma + phi.N +
## R.deep + R.med + SP + density.corr + density + phi.core +
## Facies
##
## Df Sum of Sq RSS AIC
## - density.corr 1 0.1931 89.174 -1780.1
## <none> 88.981 -1779.9
## - ind.deep 1 0.2179 89.199 -1779.9
## - R.deep 1 0.2447 89.226 -1779.7
## - caliper 1 0.2921 89.273 -1779.2
## + ind.med 1 0.1213 88.860 -1779.0
## - R.med 1 0.3397 89.321 -1778.8
## - SP 1 0.4101 89.391 -1778.1
## - depth 1 0.4622 89.444 -1777.7
## - phi.N 1 2.2035 91.185 -1761.9
## - density 1 3.0113 91.993 -1754.6
## - gamma 1 3.5761 92.557 -1749.6
## - Facies 7 9.1242 98.106 -1714.0
## - phi.core 1 27.4190 116.400 -1561.9
##
## Step: AIC=-1780.12
## log10_Permeability ~ depth + caliper + ind.deep + gamma + phi.N +
## R.deep + R.med + SP + density + phi.core + Facies
##
## Df Sum of Sq RSS AIC
## - ind.deep 1 0.2180 89.392 -1780.1
## <none> 89.174 -1780.1
## + density.corr 1 0.1931 88.981 -1779.9
## - R.deep 1 0.2526 89.427 -1779.8
## + ind.med 1 0.1705 89.004 -1779.7
## - caliper 1 0.2676 89.442 -1779.7
## - R.med 1 0.3598 89.534 -1778.8
## - SP 1 0.3832 89.558 -1778.6
## - depth 1 0.5404 89.715 -1777.2
## - phi.N 1 2.0726 91.247 -1763.3
## - gamma 1 3.4838 92.658 -1750.7
## - density 1 3.6220 92.796 -1749.5
## - Facies 7 9.3567 98.531 -1712.4
## - phi.core 1 27.2273 116.402 -1563.9
##
## Step: AIC=-1780.12
## log10_Permeability ~ depth + caliper + gamma + phi.N + R.deep +
## R.med + SP + density + phi.core + Facies
##
## Df Sum of Sq RSS AIC
## <none> 89.392 -1780.1
## + ind.deep 1 0.2180 89.174 -1780.1
## + density.corr 1 0.1932 89.199 -1779.9
## - R.deep 1 0.2869 89.679 -1779.5
## + ind.med 1 0.1478 89.245 -1779.5
## - depth 1 0.3332 89.726 -1779.1
## - SP 1 0.4296 89.822 -1778.2
## - R.med 1 0.5085 89.901 -1777.5
## - caliper 1 0.5746 89.967 -1776.9
## - phi.N 1 2.3337 91.726 -1761.0
## - gamma 1 3.8214 93.214 -1747.8
## - density 1 3.8626 93.255 -1747.5
## - Facies 7 9.2100 98.602 -1713.8
## - phi.core 1 27.0935 116.486 -1565.3
adjusted_r2_step6 <- summary(model6)$adj.r.squared
rmse_step6 <- sqrt(mean(residuals(model6)^2))
cat("Adjusted R2:", adjusted_r2_step6, " | RMSE:", rmse_step6, "\n")
## Adjusted R2: 0.6722495 | RMSE: 0.3303759
Plot measured vs. predicted log10(permeability) respect to depth.
predicted6 <- predict(model6, newdata = karpur_data)
Predicted_k_6<-10^predicted6
ggplot(karpur_data) +
geom_line(aes(x = depth, y = k.core, color = "Measured permeability")) +
geom_line(aes(x = depth, y = Predicted_k_6, color = "Predicted permeability")) +
labs(title = "Predicted vs Measured Permeability with Respect to Depth",
x = "Depth",
y = "Permeability",
color = "Legend") +
scale_color_manual(values = c("Measured permeability" = "red",
"Predicted permeability" = "black")) +
theme_minimal()
karpur_data$log_k_core <- log10(karpur_data$k.core)
library(caret)
## Warning: package 'caret' was built under R version 4.4.2
## Loading required package: lattice
library(conflicted)
## Warning: package 'conflicted' was built under R version 4.4.2
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.4.2
## Warning: package 'tibble' was built under R version 4.4.2
## Warning: package 'tidyr' was built under R version 4.4.2
## Warning: package 'readr' was built under R version 4.4.2
## Warning: package 'purrr' was built under R version 4.4.2
## Warning: package 'dplyr' was built under R version 4.4.2
## Warning: package 'forcats' was built under R version 4.4.2
## Warning: package 'lubridate' was built under R version 4.4.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ lubridate 1.9.3 ✔ tibble 3.2.1
## ✔ purrr 1.0.2 ✔ tidyr 1.3.1
set.seed(123)
train_index = createDataPartition(karpur_data$log_k_core, p = 0.69, list = FALSE)
train_data = karpur_data[train_index, ]
test_data = karpur_data[-train_index, ]
cv_model = lm(log_k_core ~ ., data = train_data)
cv_pred = predict(cv_model, test_data)
compute Adjusted R2 and RMSE
library(caret)
cv_adj_r2 = summary(cv_model)$adj.r.squared
## Warning in summary.lm(cv_model): essentially perfect fit: summary may be
## unreliable
cv_rmse = RMSE(10^cv_pred, test_data$k.core)
cat("R2:", cv_adj_r2, "\nRMSE:", cv_rmse, "\n")
## R2: 1
## RMSE: 2.09845e-12
library(ggplot2)
Predicted_log10_permeability_cv<-predict(cv_model,newdata=test_data)
Predicted_permeability_cv<-10^Predicted_log10_permeability_cv
ggplot(test_data) +
geom_line(aes(x = depth, y = k.core, color = "Measured permeability")) +
geom_line(aes(x = depth, y = Predicted_permeability_cv, color = "Predicted permeability")) +
labs(title = "Predicted vs Measured Permeability with Respect to Depth",
x = "Depth",
y = "Permeability",
color = "Legend") +
scale_color_manual(values = c("Measured permeability" = "red",
"Predicted permeability" = "black")) +
theme_minimal()
Apply Step-wise Elimination on the previous model
step_cv_model = step(cv_model, direction = "both")
## Start: AIC=-41425.55
## log_k_core ~ depth + caliper + ind.deep + ind.med + gamma + phi.N +
## R.deep + R.med + SP + density.corr + density + phi.core +
## k.core + Facies + phi.core.frac + log10_Permeability
## Warning: attempting model selection on an essentially perfect fit is nonsense
##
## Step: AIC=-41425.55
## log_k_core ~ depth + caliper + ind.deep + ind.med + gamma + phi.N +
## R.deep + R.med + SP + density.corr + density + phi.core +
## k.core + Facies + log10_Permeability
## Warning: attempting model selection on an essentially perfect fit is nonsense
## Warning: attempting model selection on an essentially perfect fit is nonsense
## Df Sum of Sq RSS AIC
## - ind.med 1 0.00 0.00 -43465
## - Facies 7 0.00 0.00 -42728
## - density 1 0.00 0.00 -42651
## - caliper 1 0.00 0.00 -42508
## - SP 1 0.00 0.00 -42473
## - density.corr 1 0.00 0.00 -42473
## <none> 0.00 -41426
## - ind.deep 1 0.00 0.00 -41222
## - depth 1 0.00 0.00 -40803
## - phi.N 1 0.00 0.00 -40766
## - phi.core 1 0.00 0.00 -40593
## - R.deep 1 0.00 0.00 -40167
## - gamma 1 0.00 0.00 -40158
## - R.med 1 0.00 0.00 -40051
## - k.core 1 0.00 0.00 -39708
## - log10_Permeability 1 51.77 51.77 -1315
##
## Step: AIC=-43465.18
## log_k_core ~ depth + caliper + ind.deep + gamma + phi.N + R.deep +
## R.med + SP + density.corr + density + phi.core + k.core +
## Facies + log10_Permeability
## Warning: attempting model selection on an essentially perfect fit is nonsense
## Warning: attempting model selection on an essentially perfect fit is nonsense
## Df Sum of Sq RSS AIC
## <none> 0.000 -43465
## + ind.med 1 0.000 0.000 -43463
## - phi.core 1 0.000 0.000 -43068
## - k.core 1 0.000 0.000 -42927
## - phi.N 1 0.000 0.000 -41744
## - density.corr 1 0.000 0.000 -41612
## - R.med 1 0.000 0.000 -41484
## - Facies 7 0.000 0.000 -41428
## - depth 1 0.000 0.000 -41051
## - ind.deep 1 0.000 0.000 -40404
## - density 1 0.000 0.000 -40025
## - R.deep 1 0.000 0.000 -39900
## - SP 1 0.000 0.000 -39851
## - gamma 1 0.000 0.000 -39624
## - caliper 1 0.000 0.000 -39500
## - log10_Permeability 1 51.876 51.876 -1316
cv_step_pred = predict(step_cv_model, test_data)
compute Adjusted R2 and RMSE
library(caret)
cv_step_adj_r2 <- summary(step_cv_model)$adj.r.squared
## Warning in summary.lm(step_cv_model): essentially perfect fit: summary may be
## unreliable
cv_step_rmse <- RMSE(10^cv_step_pred, test_data$k.core)
cat("R2:", cv_step_adj_r2, "\nRMSE:", cv_step_rmse, "\n")
## R2: 1
## RMSE: 1.512907e-12
Predicted_log10_permeability_cv2 <-predict(step_cv_model,newdata=test_data)
Predicted_permeability_cv2<-10^Predicted_log10_permeability_cv2
ggplot(test_data) +
geom_line(aes(x = depth, y = k.core, color = "Measured permeability")) +
geom_line(aes(x = depth, y = Predicted_permeability_cv2, color = "Predicted permeability")) +
labs(title = "Predicted vs Measured Permeability with Respect to Depth",
x = "Depth",
y = "Permeability",
color = "Legend") +
scale_color_manual(values = c("Measured permeability" = "red",
"Predicted permeability" = "blue")) +
theme_minimal()