Syntax

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 29

install.packages("minpack.

lm")
install.packages("MASS")
install.packages("fitdistrpluss")
install.packages("ggplot2")
install.packages("gridExtra")
library(minpack.lm)
library(MASS)
library(fitdistrplus)
library(ggplot2)
library(gridExtra)

##########Gompertz Q1
xI <- c(0,1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,
51,52,53,54,55,56,57,58,59,60,
61,62,63,64,65,66,67,68,69,70,
71,72,73,74,75,76,77,78,79,80,
81,82,83,84,85,86,87,88,89,90,
91,92,93,94,95,96,97,98,99,100,
101,102,103,104,105,106,107,108,109,110,111)
qxI <-
c(0.00802,0.00079,0.00063,0.00051,0.00043,0.00038,0.00034,0.00031,0.00029,0.00028,
0.00027,0.00027,0.00026,0.00026,0.00027,0.00029,0.00003,0.00032,0.00036,0.00041,
0.00049,0.00059,0.00069,0.00077,0.00083,0.00085,0.00083,0.00079,0.00075,0.00074,
0.00076,0.00008,0.00083,0.00084,0.00086,0.00091,0.00099,0.00109,0.00012,0.00135,
0.00153,0.00175,0.00196,0.00219,0.00246,0.00279,0.00318,0.00363,0.00414,0.00471,
0.00538,0.00615,0.00699,0.00784,0.00872,0.00961,0.01051,0.01142,0.01232,0.01322,
0.01417,0.01521,0.01639,0.01773,0.01926,0.02100,0.02288,0.02486,0.02702,0.02921,
0.03182,0.03473,0.03861,0.04264,0.04687,0.05155,0.05664,0.06254,0.06942,0.07734,
0.08597,0.09577,0.10593,0.11683,0.12888,0.14241,0.15738,0.17368,0.19110,0.20945,
0.22853,0.24638,0.26496,0.28450,0.30511,0.32682,0.34662,0.36770,0.39016,0.41413,
0.43974,0.45994,0.48143,0.50431,0.52864,0.55450,0.58198,0.61119,0.64222,0.67518,
0.71016,1.00000)
# Model Gompertz
gompertz_model <- function(xI, bI, cI) {
bI * cI^xI
}
# Tebakan awal parameter
b_guess <- 0.1
c_guess <- 0.9
# Fungsi least square
ls_function <- function(params) {
bI <- params[1]
cI <- params[2]
predicted_qxI <- gompertz_model(xI, bI, cI)
sum_residuals <- sum((predicted_qxI - qxI)^2)
return(sum_residuals)
}
# Optimisasi parameter menggunakan optim()
optim_result <- optim(c(b_guess, c_guess), ls_function)
# Parameter yang diestimasi
estimated_params <- optim_result$par
print("Estimated Parameters:")
print(estimated_params)

##########Gompertz Q2
xII <- c(0,1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,
51,52,53,54,55,56,57,58,59,60,
61,62,63,64,65,66,67,68,69,70,
71,72,73,74,75,76,77,78,79,80,
81,82,83,84,85,86,87,88,89,90,
91,92,93,94,95,96,97,98,99,100,
101,102,103,104,105,106,107,108,109,110,111) # Usia
qxII <-
c(0.00037,0.00056,0.00042,0.00033,0.00028,0.00027,0.00003,0.00031,0.00003,0.00028,

0.00025,0.00024,0.00026,0.00028,0.00029,0.00028,0.00025,0.00024,0.00023,0.00024,

0.00026,0.00029,0.00033,0.00037,0.00039,0.00042,0.00044,0.00046,0.00048,0.00051,

0.00054,0.00057,0.00006,0.00062,0.00064,0.00067,0.00074,0.00084,0.00093,0.00104,

0.00114,0.00126,0.00141,0.00158,0.00175,0.00193,0.00214,0.00239,0.00268,0.00299,

0.00334,0.00374,0.00422,0.00479,0.00542,0.00607,0.00669,0.00725,0.00776,0.00826,

0.00877,0.00936,0.01004,0.01104,0.01214,0.01334,0.01466,0.01612,0.01771,0.01947,

0.02121,0.02319,0.02539,0.02778,0.03042,0.03330,0.03646,0.03991,0.04372,0.04789,

0.05247,0.05877,0.06579,0.07284,0.08061,0.08925,0.09713,0.10893,0.12131,0.13450,

0.14645,0.15243,0.16454,0.18235,0.20488,0.23305,0.25962,0.28720,0.29173,0.30759,

0.33241,0.40956,0.43507,0.46278,0.49285,0.52515,0.55876,0.59373,0.62974,0.66757,
0.70691,1.00000)
# Model Gompertz
gompertz_model <- function(xII, bII, cII) {
bII * cII^xII
}
# Tebakan awal parameter
b_guess <- 0.005
c_guess <- 0.995
# Fungsi least square
ls_function <- function(params) {
bII <- params[1]
cII <- params[2]
predicted_qxII <- gompertz_model(xII, bII, cII)
sum_residuals <- sum((predicted_qxII - qxII)^2)
return(sum_residuals)
}
# Optimisasi parameter menggunakan optim()
optim_result <- optim(c(b_guess, c_guess), ls_function)
# Parameter yang diestimasi
estimated_params <- optim_result$par
print("Estimated Parameters:")
print(estimated_params)

##########Makeham Q1
xI <- c(0,1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,
51,52,53,54,55,56,57,58,59,60,
61,62,63,64,65,66,67,68,69,70,
71,72,73,74,75,76,77,78,79,80,
81,82,83,84,85,86,87,88,89,90,
91,92,93,94,95,96,97,98,99,100,
101,102,103,104,105,106,107,108,109,110,111)
qxI <-
c(0.00802,0.00079,0.00063,0.00051,0.00043,0.00038,0.00034,0.00031,0.00029,0.00028,
0.00027,0.00027,0.00026,0.00026,0.00027,0.00029,0.00003,0.00032,0.00036,0.00041,
0.00049,0.00059,0.00069,0.00077,0.00083,0.00085,0.00083,0.00079,0.00075,0.00074,
0.00076,0.00008,0.00083,0.00084,0.00086,0.00091,0.00099,0.00109,0.00012,0.00135,
0.00153,0.00175,0.00196,0.00219,0.00246,0.00279,0.00318,0.00363,0.00414,0.00471,
0.00538,0.00615,0.00699,0.00784,0.00872,0.00961,0.01051,0.01142,0.01232,0.01322,
0.01417,0.01521,0.01639,0.01773,0.01926,0.02100,0.02288,0.02486,0.02702,0.02921,
0.03182,0.03473,0.03861,0.04264,0.04687,0.05155,0.05664,0.06254,0.06942,0.07734,
0.08597,0.09577,0.10593,0.11683,0.12888,0.14241,0.15738,0.17368,0.19110,0.20945,
0.22853,0.24638,0.26496,0.28450,0.30511,0.32682,0.34662,0.36770,0.39016,0.41413,
0.43974,0.45994,0.48143,0.50431,0.52864,0.55450,0.58198,0.61119,0.64222,0.67518,
0.71016,1.00000)
# Model Makeham
makeham_model <- function(xI, aI, bI, cI) {
aI + bI * cI^xI
}
# Tebakan awal parameter
a_guess <- 0.999
b_guess <- 0.00005
c_guess <- 0.00095
# Fungsi least square
ls_function <- function(params) {
aI <- params[1]
bI <- params[2]
cI <- params[3]
predicted_qxI <- makeham_model(xI, aI, bI, cI)
sum_residuals <- sum((predicted_qxI - qxI)^2)
return(sum_residuals)
}
# Optimisasi parameter menggunakan optim()
optim_result <- optim(c(a_guess, b_guess, c_guess), ls_function)
# Parameter yang diestimasi
estimated_params <- optim_result$par
print("Estimated Parameters:")
print(estimated_params)

##########Makeham Q2
xII <- c(0,1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,
51,52,53,54,55,56,57,58,59,60,
61,62,63,64,65,66,67,68,69,70,
71,72,73,74,75,76,77,78,79,80,
81,82,83,84,85,86,87,88,89,90,
91,92,93,94,95,96,97,98,99,100,
101,102,103,104,105,106,107,108,109,110,111)
qxII <-
c(0.00037,0.00056,0.00042,0.00033,0.00028,0.00027,0.00003,0.00031,0.00003,0.00028,

0.00025,0.00024,0.00026,0.00028,0.00029,0.00028,0.00025,0.00024,0.00023,0.00024,

0.00026,0.00029,0.00033,0.00037,0.00039,0.00042,0.00044,0.00046,0.00048,0.00051,

0.00054,0.00057,0.00006,0.00062,0.00064,0.00067,0.00074,0.00084,0.00093,0.00104,

0.00114,0.00126,0.00141,0.00158,0.00175,0.00193,0.00214,0.00239,0.00268,0.00299,

0.00334,0.00374,0.00422,0.00479,0.00542,0.00607,0.00669,0.00725,0.00776,0.00826,
0.00877,0.00936,0.01004,0.01104,0.01214,0.01334,0.01466,0.01612,0.01771,0.01947,

0.02121,0.02319,0.02539,0.02778,0.03042,0.03330,0.03646,0.03991,0.04372,0.04789,

0.05247,0.05877,0.06579,0.07284,0.08061,0.08925,0.09713,0.10893,0.12131,0.13450,

0.14645,0.15243,0.16454,0.18235,0.20488,0.23305,0.25962,0.28720,0.29173,0.30759,

0.33241,0.40956,0.43507,0.46278,0.49285,0.52515,0.55876,0.59373,0.62974,0.66757,
0.70691,1.00000)
# Model Makeham
makeham_model <- function(xII, aII, bII, cII) {
aII + bII * cII^xII
}
# Tebakan awal parameter
a_guess <- 0.000000001
b_guess <- 0.000095
c_guess <- 2.05
# Fungsi least square
ls_function <- function(params) {
aII <- params[1]
bII <- params[2]
cII <- params[3]
predicted_qxII <- makeham_model(xII, aII, bII, cII)
sum_residuals <- sum((predicted_qxII - qxII)^2)
return(sum_residuals)
}
# Optimisasi parameter menggunakan optim()
optim_result <- optim(c(a_guess, b_guess, c_guess), ls_function)
# Parameter yang diestimasi
estimated_params <- optim_result$par
print("Estimated Parameters:")
print(estimated_params)

##########Weibull Q1
xI <- c(0,1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,
51,52,53,54,55,56,57,58,59,60,
61,62,63,64,65,66,67,68,69,70,
71,72,73,74,75,76,77,78,79,80,
81,82,83,84,85,86,87,88,89,90,
91,92,93,94,95,96,97,98,99,100,
101,102,103,104,105,106,107,108,109,110,111)
qxI <-
c(0.00802,0.00079,0.00063,0.00051,0.00043,0.00038,0.00034,0.00031,0.00029,0.00028,
0.00027,0.00027,0.00026,0.00026,0.00027,0.00029,0.00003,0.00032,0.00036,0.00041,
0.00049,0.00059,0.00069,0.00077,0.00083,0.00085,0.00083,0.00079,0.00075,0.00074,
0.00076,0.00008,0.00083,0.00084,0.00086,0.00091,0.00099,0.00109,0.00012,0.00135,
0.00153,0.00175,0.00196,0.00219,0.00246,0.00279,0.00318,0.00363,0.00414,0.00471,
0.00538,0.00615,0.00699,0.00784,0.00872,0.00961,0.01051,0.01142,0.01232,0.01322,
0.01417,0.01521,0.01639,0.01773,0.01926,0.02100,0.02288,0.02486,0.02702,0.02921,
0.03182,0.03473,0.03861,0.04264,0.04687,0.05155,0.05664,0.06254,0.06942,0.07734,
0.08597,0.09577,0.10593,0.11683,0.12888,0.14241,0.15738,0.17368,0.19110,0.20945,
0.22853,0.24638,0.26496,0.28450,0.30511,0.32682,0.34662,0.36770,0.39016,0.41413,
0.43974,0.45994,0.48143,0.50431,0.52864,0.55450,0.58198,0.61119,0.64222,0.67518,
0.71016,1.00000)
# Model Weibull
weibull_model <- function(xI, tI, sI) {
tI*xI^sI
}
# Tebakan awal parameter
t_guess <- 0.925
s_guess <- 0.075
# Fungsi least square
ls_function <- function(params) {
tI <- params[1]
sI <- params[2]
predicted_qxI <- weibull_model(xI, tI, sI)
sum_residuals <- sum((predicted_qxI - qxI)^2)
return(sum_residuals)
}
# Optimisasi parameter menggunakan optim()
optim_result <- optim(c(t_guess, t_guess), ls_function)
# Parameter yang diestimasi
estimated_params <- optim_result$par
print("Estimated Parameters:")
print(estimated_params)

##########Weibull Q2
xII<- c(0,1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,
51,52,53,54,55,56,57,58,59,60,
61,62,63,64,65,66,67,68,69,70,
71,72,73,74,75,76,77,78,79,80,
81,82,83,84,85,86,87,88,89,90,
91,92,93,94,95,96,97,98,99,100,
101,102,103,104,105,106,107,108,109,110,111)
qxII<-
c(0.00037,0.00056,0.00042,0.00033,0.00028,0.00027,0.00003,0.00031,0.00003,0.00028,
0.00025,0.00024,0.00026,0.00028,0.00029,0.00028,0.00025,0.00024,0.00023,0.00024,
0.00026,0.00029,0.00033,0.00037,0.00039,0.00042,0.00044,0.00046,0.00048,0.00051,
0.00054,0.00057,0.00006,0.00062,0.00064,0.00067,0.00074,0.00084,0.00093,0.00104,
0.00114,0.00126,0.00141,0.00158,0.00175,0.00193,0.00214,0.00239,0.00268,0.00299,
0.00334,0.00374,0.00422,0.00479,0.00542,0.00607,0.00669,0.00725,0.00776,0.00826,
0.00877,0.00936,0.01004,0.01104,0.01214,0.01334,0.01466,0.01612,0.01771,0.01947,
0.02121,0.02319,0.02539,0.02778,0.03042,0.03330,0.03646,0.03991,0.04372,0.04789,
0.05247,0.05877,0.06579,0.07284,0.08061,0.08925,0.09713,0.10893,0.12131,0.13450,
0.14645,0.15243,0.16454,0.18235,0.20488,0.23305,0.25962,0.28720,0.29173,0.30759,
0.33241,0.40956,0.43507,0.46278,0.49285,0.52515,0.55876,0.59373,0.62974,0.66757,
0.70691,1.00000)
# Model Weibull
weibull_model <- function(xII, tII, sII) {
tII*xII^sII
}
# Tebakan awal parameter
t_guess <- 0.45
s_guess <- 0.55
# Fungsi least square
ls_function <- function(params) {
tII <- params[1]
sII <- params[2]
predicted_qxI <- weibull_model(xII, tII, sII)
sum_residuals <- sum((predicted_qxI - qxI)^2)
return(sum_residuals)
}
# Optimisasi parameter menggunakan optim()
optim_result <- optim(c(t_guess, t_guess), ls_function)
# Parameter yang diestimasi
estimated_params <- optim_result$par
print("Estimated Parameters:")
print(estimated_params)

#Formula
#Gompertz untuk Q1
GQ1 <- (0.0004745502)*(1.0698723297^xI) #PASSED
GQ1
#Gompertz untuk Q2
GQ2 <- (6.596181e-05)*(1.089209e+00^xII) #PASSED
GQ2
#Makeham untuk Q1
MQ1 <- 0.00175 + 0.0012775*(1.059530^xI) #CROSS CHECK
MQ1
#Makeham untuk Q2
MQ2 <- 0.002568519 + 0.002525407*(1.0525^xII) #CROSS CHECK
MQ2
#Weibull untuk Q1
WQ1 <- 2.027098e-08*xI^3.660350e+00
WQ1
#Weibull untuk Q2
WQ2 <- 1.175304e-09*xII^4.251225e+00
WQ2

#Menampilkan Plot
x <- c(0,1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,
51,52,53,54,55,56,57,58,59,60,
61,62,63,64,65,66,67,68,69,70,
71,72,73,74,75,76,77,78,79,80,
81,82,83,84,85,86,87,88,89,90,
91,92,93,94,95,96,97,98,99,100,
101,102,103,104,105,106,107,108,109,110,111)
y2 <-
c(0.00802,0.00079,0.00063,0.00051,0.00043,0.00038,0.00034,0.00031,0.00029,0.00028,
0.00027,0.00027,0.00026,0.00026,0.00027,0.00029,0.00003,0.00032,0.00036,0.00041,
0.00049,0.00059,0.00069,0.00077,0.00083,0.00085,0.00083,0.00079,0.00075,0.00074,
0.00076,0.00008,0.00083,0.00084,0.00086,0.00091,0.00099,0.00109,0.00012,0.00135,
0.00153,0.00175,0.00196,0.00219,0.00246,0.00279,0.00318,0.00363,0.00414,0.00471,
0.00538,0.00615,0.00699,0.00784,0.00872,0.00961,0.01051,0.01142,0.01232,0.01322,
0.01417,0.01521,0.01639,0.01773,0.01926,0.02100,0.02288,0.02486,0.02702,0.02921,
0.03182,0.03473,0.03861,0.04264,0.04687,0.05155,0.05664,0.06254,0.06942,0.07734,
0.08597,0.09577,0.10593,0.11683,0.12888,0.14241,0.15738,0.17368,0.19110,0.20945,
0.22853,0.24638,0.26496,0.28450,0.30511,0.32682,0.34662,0.36770,0.39016,0.41413,
0.43974,0.45994,0.48143,0.50431,0.52864,0.55450,0.58198,0.61119,0.64222,0.67518,
0.71016,1.00000)
y2 <-
c(0.00037,0.00056,0.00042,0.00033,0.00028,0.00027,0.00003,0.00031,0.00003,0.00028,
0.00025,0.00024,0.00026,0.00028,0.00029,0.00028,0.00025,0.00024,0.00023,0.00024,
0.00026,0.00029,0.00033,0.00037,0.00039,0.00042,0.00044,0.00046,0.00048,0.00051,
0.00054,0.00057,0.00006,0.00062,0.00064,0.00067,0.00074,0.00084,0.00093,0.00104,
0.00114,0.00126,0.00141,0.00158,0.00175,0.00193,0.00214,0.00239,0.00268,0.00299,
0.00334,0.00374,0.00422,0.00479,0.00542,0.00607,0.00669,0.00725,0.00776,0.00826,
0.00877,0.00936,0.01004,0.01104,0.01214,0.01334,0.01466,0.01612,0.01771,0.01947,
0.02121,0.02319,0.02539,0.02778,0.03042,0.03330,0.03646,0.03991,0.04372,0.04789,
0.05247,0.05877,0.06579,0.07284,0.08061,0.08925,0.09713,0.10893,0.12131,0.13450,
0.14645,0.15243,0.16454,0.18235,0.20488,0.23305,0.25962,0.28720,0.29173,0.30759,
0.33241,0.40956,0.43507,0.46278,0.49285,0.52515,0.55876,0.59373,0.62974,0.66757,
0.70691,1.00000)
y1 <- WQ2
data <- data.frame(x = x, y1 = y1, y2 = y2)
# Membuat plot menggunakan ggplot2
ggplot(data, aes(x = x)) +
geom_line(aes(y = y1, color = "Y1"), size = 1) +
geom_line(aes(y = y2, color = "Y2"), size = 1, linetype = "dashed") +
labs(title = "Plot Model dan TMI", x = "X", y = "Y") +
theme_minimal() +
scale_color_manual(values = c("Y1" = "black", "Y2" = "red")) +
theme(legend.position = "top")

########## Partisi Interval Q1


##########Gompertz Q1 (0-15)
xI <- c(0,1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15)
qxI <-
c(0.00802,0.00079,0.00063,0.00051,0.00043,0.00038,0.00034,0.00031,0.00029,0.00028,
0.00027,0.00027,0.00026,0.00026,0.00027,0.00029)
# Model Gompertz
gompertz_model <- function(xI, bI, cI) {
bI * cI^xI
}
# Tebakan awal parameter
b_guess <- 0.1
c_guess <- 0.9
# Fungsi least square
ls_function <- function(params) {
bI <- params[1]
cI <- params[2]
predicted_qxI <- gompertz_model(xI, bI, cI)
sum_residuals <- sum((predicted_qxI - qxI)^2)
return(sum_residuals)
}
# Optimisasi parameter menggunakan optim()
optim_result <- optim(c(b_guess, c_guess), ls_function)
# Parameter yang diestimasi
estimated_params <- optim_result$par
print("Estimated Parameters:")
print(estimated_params)

#########Makeham Q1 (0-15)
xI <- c(0,1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15)
qxI <-
c(0.00802,0.00079,0.00063,0.00051,0.00043,0.00038,0.00034,0.00031,0.00029,0.00028,
0.00027,0.00027,0.00026,0.00026,0.00027,0.00029)
# Model Makeham
makeham_model <- function(xI, aI, bI, cI) {
aI + bI * cI^xI
}
# Tebakan awal parameter
a_guess <- 0.999
b_guess <- 0.00005
c_guess <- 0.00095
# Fungsi least square
ls_function <- function(params) {
aI <- params[1]
bI <- params[2]
cI <- params[3]
predicted_qxI <- makeham_model(xI, aI, bI, cI)
sum_residuals <- sum((predicted_qxI - qxI)^2)
return(sum_residuals)
}
# Optimisasi parameter menggunakan optim()
optim_result <- optim(c(a_guess, b_guess, c_guess), ls_function)
# Parameter yang diestimasi
estimated_params <- optim_result$par
print("Estimated Parameters:")
print(estimated_params)

#########Weibull Q1 (0-15)
xI <- c(0,1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15)
qxI <-
c(0.00802,0.00079,0.00063,0.00051,0.00043,0.00038,0.00034,0.00031,0.00029,0.00028,
0.00027,0.00027,0.00026,0.00026,0.00027,0.00029)
# Model Weibull
weibull_model <- function(xI, tI, sI) {
tI*xI^sI
}
# Tebakan awal parameter
t_guess <- 0.925
s_guess <- 0.075
# Fungsi least square
ls_function <- function(params) {
tI <- params[1]
sI <- params[2]
predicted_qxI <- weibull_model(xI, tI, sI)
sum_residuals <- sum((predicted_qxI - qxI)^2)
return(sum_residuals)
}
# Optimisasi parameter menggunakan optim()
optim_result <- optim(c(t_guess, t_guess), ls_function)
# Parameter yang diestimasi
estimated_params <- optim_result$par
print("Estimated Parameters:")
print(estimated_params)

#Model Q1 (0-15)
GQ1 <- (0.00800925)*(0.114558374^xI) #CROSS CHECK
GQ1
MQ1 <- 7.460104e-05 + 6.799170e-03*(4.753807e-01^xI) #CROSS CHECK
MQ1
WQ1 <- 0.0008648764*xI^0.1094930263 #CROSS CHECK
WQ1

#Menampilkan Plot
x <- c(0,1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15)
y2 <-
c(0.00802,0.00079,0.00063,0.00051,0.00043,0.00038,0.00034,0.00031,0.00029,0.00028,
0.00027,0.00027,0.00026,0.00026,0.00027,0.00029)
y1 <- WQ1
data <- data.frame(x = x, y1 = y1, y2 = y2)
# Membuat plot menggunakan ggplot2
ggplot(data, aes(x = x)) +
geom_line(aes(y = y1, color = "Y1"), size = 1) +
geom_line(aes(y = y2, color = "Y2"), size = 1, linetype = "dashed") +
labs(title = "Plot Model dan TMI", x = "X", y = "Y") +
theme_minimal() +
scale_color_manual(values = c("Y1" = "black", "Y2" = "red")) +
theme(legend.position = "top")

#MSE Model
observed <-
c(0.00802,0.00079,0.00063,0.00051,0.00043,0.00038,0.00034,0.00031,0.00029,0.00028,
0.00027,0.00027,0.00026,0.00026,0.00027,0.00029)
# Data prediksi
predicted1 <- GQ1
predicted2 <- MQ1
predicted3 <- WQ1
# Menghitung Mean Squared Error (MSE)
mse <- mean((observed - predicted3)^2)
# Menampilkan hasil MSE
cat("Mean Squared Error (MSE):", mse)

##########Gompertz Q1 (16-65)
xI <- c(16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,
51,52,53,54,55,56,57,58,59,60,
61,62,63,64,65)
qxI <- c(0.00003,0.00032,0.00036,0.00041,
0.00049,0.00059,0.00069,0.00077,0.00083,0.00085,0.00083,0.00079,0.00075,0.00074,
0.00076,0.00008,0.00083,0.00084,0.00086,0.00091,0.00099,0.00109,0.00012,0.00135,
0.00153,0.00175,0.00196,0.00219,0.00246,0.00279,0.00318,0.00363,0.00414,0.00471,
0.00538,0.00615,0.00699,0.00784,0.00872,0.00961,0.01051,0.01142,0.01232,0.01322,
0.01417,0.01521,0.01639,0.01773,0.01926,0.02100)
# Model Gompertz
gompertz_model <- function(xI, bI, cI) {
bI * cI^xI
}
# Tebakan awal parameter
b_guess <- 0.2
c_guess <- 0.8
# Fungsi least square
ls_function <- function(params) {
bI <- params[1]
cI <- params[2]
predicted_qxI <- gompertz_model(xI, bI, cI)
sum_residuals <- sum((predicted_qxI - qxI)^2)
return(sum_residuals)
}
# Optimisasi parameter menggunakan optim()
optim_result <- optim(c(b_guess, c_guess), ls_function)
# Parameter yang diestimasi
estimated_params <- optim_result$par
print("Estimated Parameters:")
print(estimated_params)

#########Makeham Q1 (16-65)
xI <- c(16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,
51,52,53,54,55,56,57,58,59,60,
61,62,63,64,65)
qxI <- c(0.00003,0.00032,0.00036,0.00041,
0.00049,0.00059,0.00069,0.00077,0.00083,0.00085,0.00083,0.00079,0.00075,0.00074,
0.00076,0.00008,0.00083,0.00084,0.00086,0.00091,0.00099,0.00109,0.00012,0.00135,
0.00153,0.00175,0.00196,0.00219,0.00246,0.00279,0.00318,0.00363,0.00414,0.00471,
0.00538,0.00615,0.00699,0.00784,0.00872,0.00961,0.01051,0.01142,0.01232,0.01322,
0.01417,0.01521,0.01639,0.01773,0.01926,0.02100)
# Model Makeham
makeham_model <- function(xI, aI, bI, cI) {
aI + bI * cI^xI
}
# Tebakan awal parameter
a_guess <- 0.025
b_guess <- 0.001
c_guess <- 0.95
# Fungsi least square
ls_function <- function(params) {
aI <- params[1]
bI <- params[2]
cI <- params[3]
predicted_qxI <- makeham_model(xI, aI, bI, cI)
sum_residuals <- sum((predicted_qxI - qxI)^2)
return(sum_residuals)
}
# Optimisasi parameter menggunakan optim()
optim_result <- optim(c(a_guess, b_guess, c_guess), ls_function)
# Parameter yang diestimasi
estimated_params <- optim_result$par
print("Estimated Parameters:")
print(estimated_params)

#########Weibull Q1 (16-65)
xI <- c(16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,
51,52,53,54,55,56,57,58,59,60,
61,62,63,64,65)
qxI <- c(0.00003,0.00032,0.00036,0.00041,
0.00049,0.00059,0.00069,0.00077,0.00083,0.00085,0.00083,0.00079,0.00075,0.00074,
0.00076,0.00008,0.00083,0.00084,0.00086,0.00091,0.00099,0.00109,0.00012,0.00135,
0.00153,0.00175,0.00196,0.00219,0.00246,0.00279,0.00318,0.00363,0.00414,0.00471,
0.00538,0.00615,0.00699,0.00784,0.00872,0.00961,0.01051,0.01142,0.01232,0.01322,
0.01417,0.01521,0.01639,0.01773,0.01926,0.02100)
# Model Weibull
weibull_model <- function(xI, tI, sI) {
tI*xI^sI
}
# Tebakan awal parameter
t_guess <- 0.19
s_guess <- 0.81
# Fungsi least square
ls_function <- function(params) {
tI <- params[1]
sI <- params[2]
predicted_qxI <- weibull_model(xI, tI, sI)
sum_residuals <- sum((predicted_qxI - qxI)^2)
return(sum_residuals)
}
# Optimisasi parameter menggunakan optim()
optim_result <- optim(c(t_guess, t_guess), ls_function)
# Parameter yang diestimasi
estimated_params <- optim_result$par
print("Estimated Parameters:")
print(estimated_params)

#Model Q1 (15-65)
GQ1 <- (5.224365e-05)*(1.097348e+00^xI) #CROSS CHECK
GQ1
MQ1 <- -3.357912e-04 + 7.070479e-05*(1.092352e+00^xI) #CROSS CHECK
MQ1
WQ1 <- (9.952907e-10)*xI^(4.011920e+00) #CROSS CHECK
WQ1

#Menampilkan Plot
x <- c(16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,
51,52,53,54,55,56,57,58,59,60,
61,62,63,64,65)
y2 <- c(0.00003,0.00032,0.00036,0.00041,
0.00049,0.00059,0.00069,0.00077,0.00083,0.00085,0.00083,0.00079,0.00075,0.00074,
0.00076,0.00008,0.00083,0.00084,0.00086,0.00091,0.00099,0.00109,0.00012,0.00135,
0.00153,0.00175,0.00196,0.00219,0.00246,0.00279,0.00318,0.00363,0.00414,0.00471,
0.00538,0.00615,0.00699,0.00784,0.00872,0.00961,0.01051,0.01142,0.01232,0.01322,
0.01417,0.01521,0.01639,0.01773,0.01926,0.02100)
y1 <- WQ1
data <- data.frame(x = x, y1 = y1, y2 = y2)
# Membuat plot menggunakan ggplot2
ggplot(data, aes(x = x)) +
geom_line(aes(y = y1, color = "Y1"), size = 1) +
geom_line(aes(y = y2, color = "Y2"), size = 1, linetype = "dashed") +
labs(title = "Plot Model dan TMI", x = "X", y = "Y") +
theme_minimal() +
scale_color_manual(values = c("Y1" = "black", "Y2" = "red")) +
theme(legend.position = "top")

#MSE Model
observed <- c(0.00003,0.00032,0.00036,0.00041,
0.00049,0.00059,0.00069,0.00077,0.00083,0.00085,0.00083,0.00079,0.00075,0.00074,

0.00076,0.00008,0.00083,0.00084,0.00086,0.00091,0.00099,0.00109,0.00012,0.00135,

0.00153,0.00175,0.00196,0.00219,0.00246,0.00279,0.00318,0.00363,0.00414,0.00471,

0.00538,0.00615,0.00699,0.00784,0.00872,0.00961,0.01051,0.01142,0.01232,0.01322,
0.01417,0.01521,0.01639,0.01773,0.01926,0.02100)
# Data prediksi
predicted1 <- GQ1
predicted2 <- MQ1
predicted3 <- WQ1
# Menghitung Mean Squared Error (MSE)
mse <- mean((observed - predicted1)^2)
# Menampilkan hasil MSE
cat("Mean Squared Error (MSE):", mse)

##########Gompertz Q1 (65-111)
xI <- c(66,67,68,69,70,
71,72,73,74,75,76,77,78,79,80,
81,82,83,84,85,86,87,88,89,90,
91,92,93,94,95,96,97,98,99,100,
101,102,103,104,105,106,107,108,109,110,111)
qxI <- c(0.02288,0.02486,0.02702,0.02921,
0.03182,0.03473,0.03861,0.04264,0.04687,0.05155,0.05664,0.06254,0.06942,0.07734,
0.08597,0.09577,0.10593,0.11683,0.12888,0.14241,0.15738,0.17368,0.19110,0.20945,
0.22853,0.24638,0.26496,0.28450,0.30511,0.32682,0.34662,0.36770,0.39016,0.41413,
0.43974,0.45994,0.48143,0.50431,0.52864,0.55450,0.58198,0.61119,0.64222,0.67518,
0.71016,1.00000)
# Model Gompertz
gompertz_model <- function(xI, bI, cI) {
bI * cI^xI
}
# Tebakan awal parameter
b_guess <- 0.25
c_guess <- 0.75
# Fungsi least square
ls_function <- function(params) {
bI <- params[1]
cI <- params[2]
predicted_qxI <- gompertz_model(xI, bI, cI)
sum_residuals <- sum((predicted_qxI - qxI)^2)
return(sum_residuals)
}
# Optimisasi parameter menggunakan optim()
optim_result <- optim(c(b_guess, c_guess), ls_function)
# Parameter yang diestimasi
estimated_params <- optim_result$par
print("Estimated Parameters:")
print(estimated_params)

#########Makeham Q1 (65-111)
xI <- c(66,67,68,69,70,
71,72,73,74,75,76,77,78,79,80,
81,82,83,84,85,86,87,88,89,90,
91,92,93,94,95,96,97,98,99,100,
101,102,103,104,105,106,107,108,109,110,111)
qxI <- c(0.02288,0.02486,0.02702,0.02921,
0.03182,0.03473,0.03861,0.04264,0.04687,0.05155,0.05664,0.06254,0.06942,0.07734,
0.08597,0.09577,0.10593,0.11683,0.12888,0.14241,0.15738,0.17368,0.19110,0.20945,
0.22853,0.24638,0.26496,0.28450,0.30511,0.32682,0.34662,0.36770,0.39016,0.41413,
0.43974,0.45994,0.48143,0.50431,0.52864,0.55450,0.58198,0.61119,0.64222,0.67518,
0.71016,1.00000)
# Model Makeham
makeham_model <- function(xI, aI, bI, cI) {
aI + bI * cI^xI
}
# Tebakan awal parameter
a_guess <- 0.0015
b_guess <- 0.2985
c_guess <- 0.9
# Fungsi least square
ls_function <- function(params) {
aI <- params[1]
bI <- params[2]
cI <- params[3]
predicted_qxI <- makeham_model(xI, aI, bI, cI)
sum_residuals <- sum((predicted_qxI - qxI)^2)
return(sum_residuals)
}
# Optimisasi parameter menggunakan optim()
optim_result <- optim(c(a_guess, b_guess, c_guess), ls_function)
# Parameter yang diestimasi
estimated_params <- optim_result$par
print("Estimated Parameters:")
print(estimated_params)

#########Weibull Q1 (65-111)
xI <- c(66,67,68,69,70,
71,72,73,74,75,76,77,78,79,80,
81,82,83,84,85,86,87,88,89,90,
91,92,93,94,95,96,97,98,99,100,
101,102,103,104,105,106,107,108,109,110,111)
qxI <- c(0.02288,0.02486,0.02702,0.02921,
0.03182,0.03473,0.03861,0.04264,0.04687,0.05155,0.05664,0.06254,0.06942,0.07734,
0.08597,0.09577,0.10593,0.11683,0.12888,0.14241,0.15738,0.17368,0.19110,0.20945,
0.22853,0.24638,0.26496,0.28450,0.30511,0.32682,0.34662,0.36770,0.39016,0.41413,
0.43974,0.45994,0.48143,0.50431,0.52864,0.55450,0.58198,0.61119,0.64222,0.67518,
0.71016,1.00000)
# Model Weibull
weibull_model <- function(xI, tI, sI) {
tI*xI^sI
}
# Tebakan awal parameter
t_guess <- 0.05
s_guess <- 9.95
# Fungsi least square
ls_function <- function(params) {
tI <- params[1]
sI <- params[2]
predicted_qxI <- weibull_model(xI, tI, sI)
sum_residuals <- sum((predicted_qxI - qxI)^2)
return(sum_residuals)
}
# Optimisasi parameter menggunakan optim()
optim_result <- optim(c(t_guess, t_guess), ls_function)
# Parameter yang diestimasi
estimated_params <- optim_result$par
print("Estimated Parameters:")
print(estimated_params)

#Model Q1 (65-111)
GQ1 <- (0.0005213631 )*(1.0689171127^xI) #CROSS CHECK
GQ1
MQ1 <- -0.40857367 + 0.06802709*(1.02562921^xI) #CROSS CHECK
MQ1
WQ1 <- (3.219871e-08)*xI^(3.554076e+00) #CROSS CHECK
WQ1

#Menampilkan Plot
x <- c(66,67,68,69,70,
71,72,73,74,75,76,77,78,79,80,
81,82,83,84,85,86,87,88,89,90,
91,92,93,94,95,96,97,98,99,100,
101,102,103,104,105,106,107,108,109,110,111)
y2 <- c(0.02288,0.02486,0.02702,0.02921,
0.03182,0.03473,0.03861,0.04264,0.04687,0.05155,0.05664,0.06254,0.06942,0.07734,
0.08597,0.09577,0.10593,0.11683,0.12888,0.14241,0.15738,0.17368,0.19110,0.20945,
0.22853,0.24638,0.26496,0.28450,0.30511,0.32682,0.34662,0.36770,0.39016,0.41413,
0.43974,0.45994,0.48143,0.50431,0.52864,0.55450,0.58198,0.61119,0.64222,0.67518,
0.71016,1.00000)
y1 <- WQ1
data <- data.frame(x = x, y1 = y1, y2 = y2)
# Membuat plot menggunakan ggplot2
ggplot(data, aes(x = x)) +
geom_line(aes(y = y1, color = "Y1"), size = 1) +
geom_line(aes(y = y2, color = "Y2"), size = 1, linetype = "dashed") +
labs(title = "Plot Model dan TMI", x = "X", y = "Y") +
theme_minimal() +
scale_color_manual(values = c("Y1" = "black", "Y2" = "red")) +
theme(legend.position = "top")

#MSE Model
observed <- c(0.02288,0.02486,0.02702,0.02921,

0.03182,0.03473,0.03861,0.04264,0.04687,0.05155,0.05664,0.06254,0.06942,0.07734,

0.08597,0.09577,0.10593,0.11683,0.12888,0.14241,0.15738,0.17368,0.19110,0.20945,

0.22853,0.24638,0.26496,0.28450,0.30511,0.32682,0.34662,0.36770,0.39016,0.41413,

0.43974,0.45994,0.48143,0.50431,0.52864,0.55450,0.58198,0.61119,0.64222,0.67518,
0.71016,1.00000)
# Data prediksi
predicted1 <- GQ1
predicted2 <- MQ1
predicted3 <- WQ1
# Menghitung Mean Squared Error (MSE)
mse <- mean((observed - predicted3)^2)
# Menampilkan hasil MSE
cat("Mean Squared Error (MSE):", mse)

########## Partisi Interval Q2


##########Gompertz Q2 (0-15)
xII <- c(0,1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15)
qxII <-
c(0.00037,0.00056,0.00042,0.00033,0.00028,0.00027,0.00003,0.00031,0.00003,0.00028,
0.00025,0.00024,0.00026,0.00028,0.00029,0.00028)
# Model Gompertz
gompertz_model <- function(xII, bII, cII) {
bII * cII^xII
}
# Tebakan awal parameter
b_guess <- 0.2
c_guess <- 0.8
# Fungsi least square
ls_function <- function(params) {
bII <- params[1]
cII <- params[2]
predicted_qxII <- gompertz_model(xII, bII, cII)
sum_residuals <- sum((predicted_qxII - qxII)^2)
return(sum_residuals)
}
# Optimisasi parameter menggunakan optim()
optim_result <- optim(c(b_guess, c_guess), ls_function)
# Parameter yang diestimasi
estimated_params <- optim_result$par
print("Estimated Parameters:")
print(estimated_params)

#########Makeham Q2 (0-15)
xII <- c(0,1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15)
qxII <-
c(0.00037,0.00056,0.00042,0.00033,0.00028,0.00027,0.00003,0.00031,0.00003,0.00028,
0.00025,0.00024,0.00026,0.00028,0.00029,0.00028)

# Model Makeham
makeham_model <- function(xII, aII, bII, cII) {
aII + bII * cII^xII
}
# Tebakan awal parameter
a_guess <- 0.00001
b_guess <- 0.05
c_guess <- 1.0
# Fungsi least square
ls_function <- function(params) {
aII <- params[1]
bII <- params[2]
cII <- params[3]
predicted_qxII <- makeham_model(xII, aII, bII, cII)
sum_residuals <- sum((predicted_qxII - qxII)^2)
return(sum_residuals)
}
# Optimisasi parameter menggunakan optim()
optim_result <- optim(c(a_guess, b_guess, c_guess), ls_function)
# Parameter yang diestimasi
estimated_params <- optim_result$par
print("Estimated Parameters:")
print(estimated_params)

#########Weibull Q2 (0-15)
xII <- c(0,1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15)
qxII <-
c(0.00037,0.00056,0.00042,0.00033,0.00028,0.00027,0.00003,0.00031,0.00003,0.00028,
0.00025,0.00024,0.00026,0.00028,0.00029,0.00028)
# Model Weibull
weibull_model <- function(xII, tII, sII) {
tII*xII^sII
}
# Tebakan awal parameter
t_guess <- 0.92
s_guess <- 0.08
# Fungsi least square
ls_function <- function(params) {
tII <- params[1]
sII <- params[2]
predicted_qxII <- weibull_model(xII, tII, sII)
sum_residuals <- sum((predicted_qxII - qxII)^2)
return(sum_residuals)
}
# Optimisasi parameter menggunakan optim()
optim_result <- optim(c(t_guess, t_guess), ls_function)
# Parameter yang diestimasi
estimated_params <- optim_result$par
print("Estimated Parameters:")
print(estimated_params)

#Model Q2 (0-15)
GQ2 <- (0.0003713535)*(0.9569999084^xII) #CROSS CHECK
GQ2
MQ2 <- 0.0009496811 - 0.0005833527*(1.0171345000^xII) #CROSS CHECK
MQ2
WQ2 <- 0.0008602014*xII^0.1089011721 #CROSS CHECK
WQ2

#Menampilkan Plot
x <- c(0,1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15)
y2 <-
c(0.00037,0.00056,0.00042,0.00033,0.00028,0.00027,0.00003,0.00031,0.00003,0.00028,
0.00025,0.00024,0.00026,0.00028,0.00029,0.00028)
y1 <- WQ2
data <- data.frame(x = x, y1 = y1, y2 = y2)
# Membuat plot menggunakan ggplot2
ggplot(data, aes(x = x)) +
geom_line(aes(y = y1, color = "Y1"), size = 1) +
geom_line(aes(y = y2, color = "Y2"), size = 1, linetype = "dashed") +
labs(title = "Plot Model dan TMI", x = "X", y = "Y") +
theme_minimal() +
scale_color_manual(values = c("Y1" = "black", "Y2" = "red")) +
theme(legend.position = "top")

#MSE Model
observed <-
c(0.00037,0.00056,0.00042,0.00033,0.00028,0.00027,0.00003,0.00031,0.00003,0.00028,
0.00025,0.00024,0.00026,0.00028,0.00029,0.00028)
# Data prediksi
predicted1 <- GQ2
predicted2 <- MQ2
predicted3 <- WQ2
# Menghitung Mean Squared Error (MSE)
mse <- mean((observed - predicted1)^2)
# Menampilkan hasil MSE
cat("Mean Squared Error (MSE):", mse)

##########Gompertz Q2 (16-65)
xII <- c(16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,
51,52,53,54,55,56,57,58,59,60,
61,62,63,64,65)
qxII <- c(0.00025,0.00024,0.00023,0.00024,

0.00026,0.00029,0.00033,0.00037,0.00039,0.00042,0.00044,0.00046,0.00048,0.00051,

0.00054,0.00057,0.00006,0.00062,0.00064,0.00067,0.00074,0.00084,0.00093,0.00104,

0.00114,0.00126,0.00141,0.00158,0.00175,0.00193,0.00214,0.00239,0.00268,0.00299,
0.00334,0.00374,0.00422,0.00479,0.00542,0.00607,
0.00669,0.00725,0.00776,0.00826,
0.00877,0.00936,0.01004,0.01104,0.01214,0.01334)
# Model Gompertz
gompertz_model <- function(xII, bII, cII) {
bII * cII^xII
}
# Tebakan awal parameter
b_guess <- 0.1
c_guess <- 0.9
# Fungsi least square
ls_function <- function(params) {
bII <- params[1]
cII <- params[2]
predicted_qxII <- gompertz_model(xII, bII, cII)
sum_residuals <- sum((predicted_qxII - qxII)^2)
return(sum_residuals)
}
# Optimisasi parameter menggunakan optim()
optim_result <- optim(c(b_guess, c_guess), ls_function)
# Parameter yang diestimasi
estimated_params <- optim_result$par
print("Estimated Parameters:")
print(estimated_params)

#########Makeham Q2 (16-65)
xII <- c(16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,
51,52,53,54,55,56,57,58,59,60,
61,62,63,64,65)
qxII <- c(0.00025,0.00024,0.00023,0.00024,

0.00026,0.00029,0.00033,0.00037,0.00039,0.00042,0.00044,0.00046,0.00048,0.00051,

0.00054,0.00057,0.00006,0.00062,0.00064,0.00067,0.00074,0.00084,0.00093,0.00104,

0.00114,0.00126,0.00141,0.00158,0.00175,0.00193,0.00214,0.00239,0.00268,0.00299,
0.00334,0.00374,0.00422,0.00479,0.00542,0.00607,
0.00669,0.00725,0.00776,0.00826,
0.00877,0.00936,0.01004,0.01104,0.01214,0.01334)
# Model Makeham
makeham_model <- function(xII, aII, bII, cII) {
aII + bII * cII^xII
}
# Tebakan awal parameter
a_guess <- 0.000001
b_guess <- 0.0025
c_guess <- 1.0005
# Fungsi least square
ls_function <- function(params) {
aII <- params[1]
bII <- params[2]
cII <- params[3]
predicted_qxII <- makeham_model(xII, aII, bII, cII)
sum_residuals <- sum((predicted_qxII - qxII)^2)
return(sum_residuals)
}
# Optimisasi parameter menggunakan optim()
optim_result <- optim(c(a_guess, b_guess, c_guess), ls_function)
# Parameter yang diestimasi
estimated_params <- optim_result$par
print("Estimated Parameters:")
print(estimated_params)

#########Weibull Q2 (16-65)
xII <- c(16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,
51,52,53,54,55,56,57,58,59,60,
61,62,63,64,65)
qxII <- c(0.00025,0.00024,0.00023,0.00024,

0.00026,0.00029,0.00033,0.00037,0.00039,0.00042,0.00044,0.00046,0.00048,0.00051,

0.00054,0.00057,0.00006,0.00062,0.00064,0.00067,0.00074,0.00084,0.00093,0.00104,

0.00114,0.00126,0.00141,0.00158,0.00175,0.00193,0.00214,0.00239,0.00268,0.00299,
0.00334,0.00374,0.00422,0.00479,0.00542,0.00607,
0.00669,0.00725,0.00776,0.00826,
0.00877,0.00936,0.01004,0.01104,0.01214,0.01334)
# Model Weibull
weibull_model <- function(xII, tII, sII) {
tII*xII^sII
}
# Tebakan awal parameter
t_guess <- 0.001
s_guess <- 2.999
# Fungsi least square
ls_function <- function(params) {
tII <- params[1]
sII <- params[2]
predicted_qxII <- weibull_model(xII, tII, sII)
sum_residuals <- sum((predicted_qxII - qxII)^2)
return(sum_residuals)
}
# Optimisasi parameter menggunakan optim()
optim_result <- optim(c(t_guess, t_guess), ls_function)
# Parameter yang diestimasi
estimated_params <- optim_result$par
print("Estimated Parameters:")
print(estimated_params)

#Model Q2 (15-65)
GQ2 <- (3.679918e-05)*(1.095241e+00^xII) #CROSS CHECK
GQ2
MQ2 <- -1.536990e-04 + 4.629979e-05*(1.091455e+00^xII) #CROSS CHECK
MQ2
WQ2 <- (1.610821e-09)*xII^(3.780328e+00) #CROSS CHECK
WQ2

#Menampilkan Plot
x <- c(16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,
51,52,53,54,55,56,57,58,59,60,
61,62,63,64,65)
y2 <- c(0.00025,0.00024,0.00023,0.00024,
0.00026,0.00029,0.00033,0.00037,0.00039,0.00042,0.00044,0.00046,0.00048,0.00051,
0.00054,0.00057,0.00006,0.00062,0.00064,0.00067,0.00074,0.00084,0.00093,0.00104,
0.00114,0.00126,0.00141,0.00158,0.00175,0.00193,0.00214,0.00239,0.00268,0.00299,
0.00334,0.00374,0.00422,0.00479,0.00542,0.00607, 0.00669,0.00725,0.00776,0.00826,
0.00877,0.00936,0.01004,0.01104,0.01214,0.01334)
y1 <- WQ2
data <- data.frame(x = x, y1 = y1, y2 = y2)
# Membuat plot menggunakan ggplot2
ggplot(data, aes(x = x)) +
geom_line(aes(y = y1, color = "Y1"), size = 1) +
geom_line(aes(y = y2, color = "Y2"), size = 1, linetype = "dashed") +
labs(title = "Plot Model dan TMI", x = "X", y = "Y") +
theme_minimal() +
scale_color_manual(values = c("Y1" = "black", "Y2" = "red")) +
theme(legend.position = "top")

#MSE Model
observed <- c(0.00025,0.00024,0.00023,0.00024,

0.00026,0.00029,0.00033,0.00037,0.00039,0.00042,0.00044,0.00046,0.00048,0.00051,

0.00054,0.00057,0.00006,0.00062,0.00064,0.00067,0.00074,0.00084,0.00093,0.00104,

0.00114,0.00126,0.00141,0.00158,0.00175,0.00193,0.00214,0.00239,0.00268,0.00299,
0.00334,0.00374,0.00422,0.00479,0.00542,0.00607,
0.00669,0.00725,0.00776,0.00826,
0.00877,0.00936,0.01004,0.01104,0.01214,0.01334)
# Data prediksi
predicted1 <- GQ2
predicted2 <- MQ2
predicted3 <- WQ2
# Menghitung Mean Squared Error (MSE)
mse <- mean((observed - predicted1)^2)
# Menampilkan hasil MSE
cat("Mean Squared Error (MSE):", mse)

##########Gompertz Q2 (65-111)
xII <- c(66,67,68,69,70,
71,72,73,74,75,76,77,78,79,80,
81,82,83,84,85,86,87,88,89,90,
91,92,93,94,95,96,97,98,99,100,
101,102,103,104,105,106,107,108,109,110,111)
qxII <- c(0.01466,0.01612,0.01771,0.01947,

0.02121,0.02319,0.02539,0.02778,0.03042,0.03330,0.03646,0.03991,0.04372,0.04789,

0.05247,0.05877,0.06579,0.07284,0.08061,0.08925,0.09713,0.10893,0.12131,0.13450,

0.14645,0.15243,0.16454,0.18235,0.20488,0.23305,0.25962,0.28720,0.29173,0.30759,

0.33241,0.40956,0.43507,0.46278,0.49285,0.52515,0.55876,0.59373,0.62974,0.66757,
0.70691,1.00000)
# Model Gompertz
gompertz_model <- function(xII, bII, cII) {
bII * cII^xII
}
# Tebakan awal parameter
b_guess <- 0.1
c_guess <- 0.9
# Fungsi least square
ls_function <- function(params) {
bII <- params[1]
cII <- params[2]
predicted_qxII <- gompertz_model(xII, bII, cII)
sum_residuals <- sum((predicted_qxII - qxII)^2)
return(sum_residuals)
}
# Optimisasi parameter menggunakan optim()
optim_result <- optim(c(b_guess, c_guess), ls_function)
# Parameter yang diestimasi
estimated_params <- optim_result$par
print("Estimated Parameters:")
print(estimated_params)
#########Makeham Q2 (65-111)
xII <- c(66,67,68,69,70,
71,72,73,74,75,76,77,78,79,80,
81,82,83,84,85,86,87,88,89,90,
91,92,93,94,95,96,97,98,99,100,
101,102,103,104,105,106,107,108,109,110,111)
qxII <- c(0.01466,0.01612,0.01771,0.01947,

0.02121,0.02319,0.02539,0.02778,0.03042,0.03330,0.03646,0.03991,0.04372,0.04789,

0.05247,0.05877,0.06579,0.07284,0.08061,0.08925,0.09713,0.10893,0.12131,0.13450,

0.14645,0.15243,0.16454,0.18235,0.20488,0.23305,0.25962,0.28720,0.29173,0.30759,

0.33241,0.40956,0.43507,0.46278,0.49285,0.52515,0.55876,0.59373,0.62974,0.66757,
0.70691,1.00000)
# Model Makeham
makeham_model <- function(xII, aII, bII, cII) {
aII + bII * cII^xII
}
# Tebakan awal parameter
a_guess <- 0.05
b_guess <- 0.00001
c_guess <- 1.0005
# Fungsi least square
ls_function <- function(params) {
aII <- params[1]
bII <- params[2]
cII <- params[3]
predicted_qxII <- makeham_model(xII, aII, bII, cII)
sum_residuals <- sum((predicted_qxII - qxII)^2)
return(sum_residuals)
}
# Optimisasi parameter menggunakan optim()
optim_result <- optim(c(a_guess, b_guess, c_guess), ls_function)
# Parameter yang diestimasi
estimated_params <- optim_result$par
print("Estimated Parameters:")
print(estimated_params)

#########Weibull Q2 (65-111)
xII <- c(66,67,68,69,70,
71,72,73,74,75,76,77,78,79,80,
81,82,83,84,85,86,87,88,89,90,
91,92,93,94,95,96,97,98,99,100,
101,102,103,104,105,106,107,108,109,110,111)
qxII <- c(0.01466,0.01612,0.01771,0.01947,

0.02121,0.02319,0.02539,0.02778,0.03042,0.03330,0.03646,0.03991,0.04372,0.04789,

0.05247,0.05877,0.06579,0.07284,0.08061,0.08925,0.09713,0.10893,0.12131,0.13450,

0.14645,0.15243,0.16454,0.18235,0.20488,0.23305,0.25962,0.28720,0.29173,0.30759,

0.33241,0.40956,0.43507,0.46278,0.49285,0.52515,0.55876,0.59373,0.62974,0.66757,
0.70691,1.00000)
# Model Weibull
weibull_model <- function(xII, tII, sII) {
tII*xII^sII
}
# Tebakan awal parameter
t_guess <- 0.001
s_guess <- 1.999
# Fungsi least square
ls_function <- function(params) {
tII <- params[1]
sII <- params[2]
predicted_qxII <- weibull_model(xII, tII, sII)
sum_residuals <- sum((predicted_qxII - qxII)^2)
return(sum_residuals)
}
# Optimisasi parameter menggunakan optim()
optim_result <- optim(c(t_guess, t_guess), ls_function)
# Parameter yang diestimasi
estimated_params <- optim_result$par
print("Estimated Parameters:")
print(estimated_params)

#Model Q2 (65-111)
GQ2 <- (6.674761e-05)*(1.089088e+00^xII) #CROSS CHECK
GQ2
MQ2 <- 1.738378e-02 + 2.171957e-05*(1.100212e+00^xII) #CROSS CHECK
MQ2
WQ2 <- (3.536591e-08)*xII^(3.518985e+00) #CROSS CHECK
WQ2

#Menampilkan Plot
x <- c(66,67,68,69,70,
71,72,73,74,75,76,77,78,79,80,
81,82,83,84,85,86,87,88,89,90,
91,92,93,94,95,96,97,98,99,100,
101,102,103,104,105,106,107,108,109,110,111)
y2 <- c(0.01466,0.01612,0.01771,0.01947,
0.02121,0.02319,0.02539,0.02778,0.03042,0.03330,0.03646,0.03991,0.04372,0.04789,
0.05247,0.05877,0.06579,0.07284,0.08061,0.08925,0.09713,0.10893,0.12131,0.13450,
0.14645,0.15243,0.16454,0.18235,0.20488,0.23305,0.25962,0.28720,0.29173,0.30759,
0.33241,0.40956,0.43507,0.46278,0.49285,0.52515,0.55876,0.59373,0.62974,0.66757,
0.70691,1.00000)
y1 <- WQ2
data <- data.frame(x = x, y1 = y1, y2 = y2)
# Membuat plot menggunakan ggplot2
ggplot(data, aes(x = x)) +
geom_line(aes(y = y1, color = "Y1"), size = 1) +
geom_line(aes(y = y2, color = "Y2"), size = 1, linetype = "dashed") +
labs(title = "Plot Model dan TMI", x = "X", y = "Y") +
theme_minimal() +
scale_color_manual(values = c("Y1" = "black", "Y2" = "red")) +
theme(legend.position = "top")

#MSE Model
observed <- c(0.01466,0.01612,0.01771,0.01947,

0.02121,0.02319,0.02539,0.02778,0.03042,0.03330,0.03646,0.03991,0.04372,0.04789,

0.05247,0.05877,0.06579,0.07284,0.08061,0.08925,0.09713,0.10893,0.12131,0.13450,

0.14645,0.15243,0.16454,0.18235,0.20488,0.23305,0.25962,0.28720,0.29173,0.30759,

0.33241,0.40956,0.43507,0.46278,0.49285,0.52515,0.55876,0.59373,0.62974,0.66757,
0.70691,1.00000)
# Data prediksi
predicted1 <- GQ2
predicted2 <- MQ2
predicted3 <- WQ2
# Menghitung Mean Squared Error (MSE)
mse <- mean((observed - predicted1)^2)
# Menampilkan hasil MSE
cat("Mean Squared Error (MSE):", mse)

You might also like