library(DataExplorer)
library(skimr)
library(corrplot)
library(tidyverse)
library(splines)
library(ISLR)
par(mar = c(3, 3, 3, 3))
attach(Auto) # Data dari library ISLR, mpg = mile.per.gallon, horsepower
## The following object is masked from package:lubridate:
##
## origin
## The following object is masked from package:ggplot2:
##
## mpg
str(Auto)
## 'data.frame': 392 obs. of 9 variables:
## $ mpg : num 18 15 18 16 17 15 14 14 14 15 ...
## $ cylinders : num 8 8 8 8 8 8 8 8 8 8 ...
## $ displacement: num 307 350 318 304 302 429 454 440 455 390 ...
## $ horsepower : num 130 165 150 150 140 198 220 215 225 190 ...
## $ weight : num 3504 3693 3436 3433 3449 ...
## $ acceleration: num 12 11.5 11 12 10.5 10 9 8.5 10 8.5 ...
## $ year : num 70 70 70 70 70 70 70 70 70 70 ...
## $ origin : num 1 1 1 1 1 1 1 1 1 1 ...
## $ name : Factor w/ 304 levels "amc ambassador brougham",..: 49 36 231 14 161 141 54 223 241 2 ...
plot_intro(data = Auto, geom_label_args = list(size=2.5)) ##Info data

skim_without_charts(data = Auto)
Data summary
Name |
Auto |
Number of rows |
392 |
Number of columns |
9 |
_______________________ |
|
Column type frequency: |
|
factor |
1 |
numeric |
8 |
________________________ |
|
Group variables |
None |
Variable type: factor
name |
0 |
1 |
FALSE |
301 |
amc: 5, for: 5, toy: 5, amc: 4 |
Variable type: numeric
mpg |
0 |
1 |
23.45 |
7.81 |
9 |
17.00 |
22.75 |
29.00 |
46.6 |
cylinders |
0 |
1 |
5.47 |
1.71 |
3 |
4.00 |
4.00 |
8.00 |
8.0 |
displacement |
0 |
1 |
194.41 |
104.64 |
68 |
105.00 |
151.00 |
275.75 |
455.0 |
horsepower |
0 |
1 |
104.47 |
38.49 |
46 |
75.00 |
93.50 |
126.00 |
230.0 |
weight |
0 |
1 |
2977.58 |
849.40 |
1613 |
2225.25 |
2803.50 |
3614.75 |
5140.0 |
acceleration |
0 |
1 |
15.54 |
2.76 |
8 |
13.78 |
15.50 |
17.02 |
24.8 |
year |
0 |
1 |
75.98 |
3.68 |
70 |
73.00 |
76.00 |
79.00 |
82.0 |
origin |
0 |
1 |
1.58 |
0.81 |
1 |
1.00 |
1.00 |
2.00 |
3.0 |
plot_scatterplot(data = Auto,by="mpg",
geom_point_args = list(color="coral3")
)

Melihat Hubungan “mpg” dengan “horsepower”
ggplot(Auto,aes(x=horsepower, y=mpg)) +
geom_point(alpha=0.55, color="black") +
theme_bw()

Regresi Linear
fit.lin <- lm(mpg ~ horsepower ,data =Auto)
coef(summary(fit.lin))
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 39.9358610 0.717498656 55.65984 1.220362e-187
## horsepower -0.1578447 0.006445501 -24.48914 7.031989e-81
ggplot(Auto,aes(x=horsepower, y=mpg)) +
geom_point(alpha=0.55, color="black") +
stat_smooth(method = "lm",
formula = y ~ x,
lty = 1, col = "blue",se = FALSE)+
theme_bw()

Regresi Polynomial Ordo 4
fit.pol <- lm(mpg ~ poly(horsepower,4, raw = TRUE) ,data =Auto)
coef(summary(fit.pol))
## Estimate Std. Error t value
## (Intercept) 4.756768e+01 1.195992e+01 3.9772578
## poly(horsepower, 4, raw = TRUE)1 -7.667214e-02 4.312613e-01 -0.1777858
## poly(horsepower, 4, raw = TRUE)2 -4.344641e-03 5.496593e-03 -0.7904242
## poly(horsepower, 4, raw = TRUE)3 3.245115e-05 2.925826e-05 1.1091279
## poly(horsepower, 4, raw = TRUE)4 -6.530363e-08 5.504268e-08 -1.1864180
## Pr(>|t|)
## (Intercept) 8.321165e-05
## poly(horsepower, 4, raw = TRUE)1 8.589842e-01
## poly(horsepower, 4, raw = TRUE)2 4.297641e-01
## poly(horsepower, 4, raw = TRUE)3 2.680638e-01
## poly(horsepower, 4, raw = TRUE)4 2.361851e-01
ggplot(Auto,aes(x=horsepower, y=mpg)) +
geom_point(alpha=0.55, color="black") +
stat_smooth(method = "lm",
formula = y ~ poly(x,4,raw=TRUE),
lty = 1, col = "blue",se = FALSE)+
theme_bw()

Regres Fungsi Tangga
fit.tangga <- lm(mpg ~ cut(horsepower,5) ,data =Auto)
coef(summary(fit.tangga))
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 31.303279 0.4272125 73.27332 5.778755e-229
## cut(horsepower, 5)(82.8,120] -8.281327 0.5641636 -14.67895 4.299840e-39
## cut(horsepower, 5)(120,156] -15.242673 0.7210260 -21.14025 1.689525e-66
## cut(horsepower, 5)(156,193] -17.592168 1.0035874 -17.52928 4.667022e-51
## cut(horsepower, 5)(193,230] -18.534048 1.3766995 -13.46267 3.743262e-34
ggplot(Auto,aes(x=horsepower, y=mpg)) +
geom_point(alpha=0.55, color="black") +
stat_smooth(method = "lm",
formula = y ~ cut(x,5),
lty = 1, col = "blue",se = FALSE)+
theme_bw()

Regresi Splines : Cubic Splines
fit.cb.spline <- lm(mpg ~ bs(horsepower, knots = c(75, 100, 125, 150, 175, 200)),
data =Auto)
coef(summary(fit.cb.spline))
## Estimate Std. Error
## (Intercept) 32.943821 1.917611
## bs(horsepower, knots = c(75, 100, 125, 150, 175, 200))1 4.508934 3.196670
## bs(horsepower, knots = c(75, 100, 125, 150, 175, 200))2 -3.019578 2.045188
## bs(horsepower, knots = c(75, 100, 125, 150, 175, 200))3 -13.182880 2.439451
## bs(horsepower, knots = c(75, 100, 125, 150, 175, 200))4 -12.291726 2.359226
## bs(horsepower, knots = c(75, 100, 125, 150, 175, 200))5 -19.767519 2.465359
## bs(horsepower, knots = c(75, 100, 125, 150, 175, 200))6 -18.234179 2.834607
## bs(horsepower, knots = c(75, 100, 125, 150, 175, 200))7 -21.557173 4.361744
## bs(horsepower, knots = c(75, 100, 125, 150, 175, 200))8 -21.567155 4.645299
## bs(horsepower, knots = c(75, 100, 125, 150, 175, 200))9 -17.328495 3.977378
## t value Pr(>|t|)
## (Intercept) 17.179618 2.014191e-49
## bs(horsepower, knots = c(75, 100, 125, 150, 175, 200))1 1.410510 1.592030e-01
## bs(horsepower, knots = c(75, 100, 125, 150, 175, 200))2 -1.476431 1.406522e-01
## bs(horsepower, knots = c(75, 100, 125, 150, 175, 200))3 -5.404034 1.149367e-07
## bs(horsepower, knots = c(75, 100, 125, 150, 175, 200))4 -5.210066 3.094816e-07
## bs(horsepower, knots = c(75, 100, 125, 150, 175, 200))5 -8.018110 1.324614e-14
## bs(horsepower, knots = c(75, 100, 125, 150, 175, 200))6 -6.432701 3.753133e-10
## bs(horsepower, knots = c(75, 100, 125, 150, 175, 200))7 -4.942329 1.157496e-06
## bs(horsepower, knots = c(75, 100, 125, 150, 175, 200))8 -4.642791 4.734027e-06
## bs(horsepower, knots = c(75, 100, 125, 150, 175, 200))9 -4.356764 1.698392e-05
ggplot(Auto,aes(x=horsepower, y=mpg))+
geom_point(alpha=0.55, color="black")+
stat_smooth(method = "lm",
formula = y ~ bs(x, knots = c(75, 100, 125, 150, 175, 200)),
lty = 1, col = "blue",se = FALSE)+
theme_bw()

Regresi Splines : Natural Cubic Splines
fit.ncb.spline <- lm(mpg ~ ns(horsepower, knots = c(75, 100, 125, 150, 175, 200)),
data =Auto)
coef(summary(fit.ncb.spline))
## Estimate Std. Error
## (Intercept) 35.50748 1.312311
## ns(horsepower, knots = c(75, 100, 125, 150, 175, 200))1 -16.97462 1.310943
## ns(horsepower, knots = c(75, 100, 125, 150, 175, 200))2 -13.82750 2.190621
## ns(horsepower, knots = c(75, 100, 125, 150, 175, 200))3 -22.94357 1.790913
## ns(horsepower, knots = c(75, 100, 125, 150, 175, 200))4 -20.12330 2.392789
## ns(horsepower, knots = c(75, 100, 125, 150, 175, 200))5 -24.40386 2.873859
## ns(horsepower, knots = c(75, 100, 125, 150, 175, 200))6 -25.43013 3.270841
## ns(horsepower, knots = c(75, 100, 125, 150, 175, 200))7 -18.96067 2.420874
## t value Pr(>|t|)
## (Intercept) 27.057217 5.414910e-91
## ns(horsepower, knots = c(75, 100, 125, 150, 175, 200))1 -12.948402 4.529701e-32
## ns(horsepower, knots = c(75, 100, 125, 150, 175, 200))2 -6.312135 7.601502e-10
## ns(horsepower, knots = c(75, 100, 125, 150, 175, 200))3 -12.811099 1.568816e-31
## ns(horsepower, knots = c(75, 100, 125, 150, 175, 200))4 -8.409977 8.146755e-16
## ns(horsepower, knots = c(75, 100, 125, 150, 175, 200))5 -8.491669 4.515988e-16
## ns(horsepower, knots = c(75, 100, 125, 150, 175, 200))6 -7.774797 7.013088e-14
## ns(horsepower, knots = c(75, 100, 125, 150, 175, 200))7 -7.832159 4.736510e-14
ggplot(Auto,aes(x=horsepower, y=mpg))+
geom_point(alpha=0.55, color="black")+
stat_smooth(method = "lm",
formula = y ~ ns(x, knots = c(75, 100, 125, 150, 175, 200)),
lty = 1, col = "blue",se = FALSE)+
theme_bw()

Plot Gabungan Splines
ggplot(Auto,aes(x=horsepower, y=mpg))+
geom_point(alpha=0.55, color="black")+
stat_smooth(method = "lm",
formula = y ~ bs(x, knots = c(75, 100, 125, 150, 175, 200)),
lty = 1, aes(col = "Cubic Spline"),se = F)+
stat_smooth(method = "lm",
formula = y ~ ns(x, knots = c(75, 100, 125, 150, 175, 200)),
lty = 1, aes(col = "Natural Cubic Spline"),se = F)+
labs(color="Tipe Spline")

scale_color_manual(values = c("Natural Cubic Spline"="red",
"Cubic Spline"="blue"))
## <ggproto object: Class ScaleDiscrete, Scale, gg>
## aesthetics: colour
## axis_order: function
## break_info: function
## break_positions: function
## breaks: waiver
## call: call
## clone: function
## dimension: function
## drop: TRUE
## expand: waiver
## get_breaks: function
## get_breaks_minor: function
## get_labels: function
## get_limits: function
## get_transformation: function
## guide: legend
## is_discrete: function
## is_empty: function
## labels: waiver
## limits: function
## make_sec_title: function
## make_title: function
## map: function
## map_df: function
## n.breaks.cache: NULL
## na.translate: TRUE
## na.value: grey50
## name: waiver
## palette: function
## palette.cache: NULL
## position: left
## range: environment
## rescale: function
## reset: function
## train: function
## train_df: function
## transform: function
## transform_df: function
## super: <ggproto object: Class ScaleDiscrete, Scale, gg>
theme_bw()
## List of 136
## $ line :List of 6
## ..$ colour : chr "black"
## ..$ linewidth : num 0.5
## ..$ linetype : num 1
## ..$ lineend : chr "butt"
## ..$ arrow : logi FALSE
## ..$ inherit.blank: logi TRUE
## ..- attr(*, "class")= chr [1:2] "element_line" "element"
## $ rect :List of 5
## ..$ fill : chr "white"
## ..$ colour : chr "black"
## ..$ linewidth : num 0.5
## ..$ linetype : num 1
## ..$ inherit.blank: logi TRUE
## ..- attr(*, "class")= chr [1:2] "element_rect" "element"
## $ text :List of 11
## ..$ family : chr ""
## ..$ face : chr "plain"
## ..$ colour : chr "black"
## ..$ size : num 11
## ..$ hjust : num 0.5
## ..$ vjust : num 0.5
## ..$ angle : num 0
## ..$ lineheight : num 0.9
## ..$ margin : 'margin' num [1:4] 0points 0points 0points 0points
## .. ..- attr(*, "unit")= int 8
## ..$ debug : logi FALSE
## ..$ inherit.blank: logi TRUE
## ..- attr(*, "class")= chr [1:2] "element_text" "element"
## $ title : NULL
## $ aspect.ratio : NULL
## $ axis.title : NULL
## $ axis.title.x :List of 11
## ..$ family : NULL
## ..$ face : NULL
## ..$ colour : NULL
## ..$ size : NULL
## ..$ hjust : NULL
## ..$ vjust : num 1
## ..$ angle : NULL
## ..$ lineheight : NULL
## ..$ margin : 'margin' num [1:4] 2.75points 0points 0points 0points
## .. ..- attr(*, "unit")= int 8
## ..$ debug : NULL
## ..$ inherit.blank: logi TRUE
## ..- attr(*, "class")= chr [1:2] "element_text" "element"
## $ axis.title.x.top :List of 11
## ..$ family : NULL
## ..$ face : NULL
## ..$ colour : NULL
## ..$ size : NULL
## ..$ hjust : NULL
## ..$ vjust : num 0
## ..$ angle : NULL
## ..$ lineheight : NULL
## ..$ margin : 'margin' num [1:4] 0points 0points 2.75points 0points
## .. ..- attr(*, "unit")= int 8
## ..$ debug : NULL
## ..$ inherit.blank: logi TRUE
## ..- attr(*, "class")= chr [1:2] "element_text" "element"
## $ axis.title.x.bottom : NULL
## $ axis.title.y :List of 11
## ..$ family : NULL
## ..$ face : NULL
## ..$ colour : NULL
## ..$ size : NULL
## ..$ hjust : NULL
## ..$ vjust : num 1
## ..$ angle : num 90
## ..$ lineheight : NULL
## ..$ margin : 'margin' num [1:4] 0points 2.75points 0points 0points
## .. ..- attr(*, "unit")= int 8
## ..$ debug : NULL
## ..$ inherit.blank: logi TRUE
## ..- attr(*, "class")= chr [1:2] "element_text" "element"
## $ axis.title.y.left : NULL
## $ axis.title.y.right :List of 11
## ..$ family : NULL
## ..$ face : NULL
## ..$ colour : NULL
## ..$ size : NULL
## ..$ hjust : NULL
## ..$ vjust : num 1
## ..$ angle : num -90
## ..$ lineheight : NULL
## ..$ margin : 'margin' num [1:4] 0points 0points 0points 2.75points
## .. ..- attr(*, "unit")= int 8
## ..$ debug : NULL
## ..$ inherit.blank: logi TRUE
## ..- attr(*, "class")= chr [1:2] "element_text" "element"
## $ axis.text :List of 11
## ..$ family : NULL
## ..$ face : NULL
## ..$ colour : chr "grey30"
## ..$ size : 'rel' num 0.8
## ..$ hjust : NULL
## ..$ vjust : NULL
## ..$ angle : NULL
## ..$ lineheight : NULL
## ..$ margin : NULL
## ..$ debug : NULL
## ..$ inherit.blank: logi TRUE
## ..- attr(*, "class")= chr [1:2] "element_text" "element"
## $ axis.text.x :List of 11
## ..$ family : NULL
## ..$ face : NULL
## ..$ colour : NULL
## ..$ size : NULL
## ..$ hjust : NULL
## ..$ vjust : num 1
## ..$ angle : NULL
## ..$ lineheight : NULL
## ..$ margin : 'margin' num [1:4] 2.2points 0points 0points 0points
## .. ..- attr(*, "unit")= int 8
## ..$ debug : NULL
## ..$ inherit.blank: logi TRUE
## ..- attr(*, "class")= chr [1:2] "element_text" "element"
## $ axis.text.x.top :List of 11
## ..$ family : NULL
## ..$ face : NULL
## ..$ colour : NULL
## ..$ size : NULL
## ..$ hjust : NULL
## ..$ vjust : num 0
## ..$ angle : NULL
## ..$ lineheight : NULL
## ..$ margin : 'margin' num [1:4] 0points 0points 2.2points 0points
## .. ..- attr(*, "unit")= int 8
## ..$ debug : NULL
## ..$ inherit.blank: logi TRUE
## ..- attr(*, "class")= chr [1:2] "element_text" "element"
## $ axis.text.x.bottom : NULL
## $ axis.text.y :List of 11
## ..$ family : NULL
## ..$ face : NULL
## ..$ colour : NULL
## ..$ size : NULL
## ..$ hjust : num 1
## ..$ vjust : NULL
## ..$ angle : NULL
## ..$ lineheight : NULL
## ..$ margin : 'margin' num [1:4] 0points 2.2points 0points 0points
## .. ..- attr(*, "unit")= int 8
## ..$ debug : NULL
## ..$ inherit.blank: logi TRUE
## ..- attr(*, "class")= chr [1:2] "element_text" "element"
## $ axis.text.y.left : NULL
## $ axis.text.y.right :List of 11
## ..$ family : NULL
## ..$ face : NULL
## ..$ colour : NULL
## ..$ size : NULL
## ..$ hjust : num 0
## ..$ vjust : NULL
## ..$ angle : NULL
## ..$ lineheight : NULL
## ..$ margin : 'margin' num [1:4] 0points 0points 0points 2.2points
## .. ..- attr(*, "unit")= int 8
## ..$ debug : NULL
## ..$ inherit.blank: logi TRUE
## ..- attr(*, "class")= chr [1:2] "element_text" "element"
## $ axis.text.theta : NULL
## $ axis.text.r :List of 11
## ..$ family : NULL
## ..$ face : NULL
## ..$ colour : NULL
## ..$ size : NULL
## ..$ hjust : num 0.5
## ..$ vjust : NULL
## ..$ angle : NULL
## ..$ lineheight : NULL
## ..$ margin : 'margin' num [1:4] 0points 2.2points 0points 2.2points
## .. ..- attr(*, "unit")= int 8
## ..$ debug : NULL
## ..$ inherit.blank: logi TRUE
## ..- attr(*, "class")= chr [1:2] "element_text" "element"
## $ axis.ticks :List of 6
## ..$ colour : chr "grey20"
## ..$ linewidth : NULL
## ..$ linetype : NULL
## ..$ lineend : NULL
## ..$ arrow : logi FALSE
## ..$ inherit.blank: logi TRUE
## ..- attr(*, "class")= chr [1:2] "element_line" "element"
## $ axis.ticks.x : NULL
## $ axis.ticks.x.top : NULL
## $ axis.ticks.x.bottom : NULL
## $ axis.ticks.y : NULL
## $ axis.ticks.y.left : NULL
## $ axis.ticks.y.right : NULL
## $ axis.ticks.theta : NULL
## $ axis.ticks.r : NULL
## $ axis.minor.ticks.x.top : NULL
## $ axis.minor.ticks.x.bottom : NULL
## $ axis.minor.ticks.y.left : NULL
## $ axis.minor.ticks.y.right : NULL
## $ axis.minor.ticks.theta : NULL
## $ axis.minor.ticks.r : NULL
## $ axis.ticks.length : 'simpleUnit' num 2.75points
## ..- attr(*, "unit")= int 8
## $ axis.ticks.length.x : NULL
## $ axis.ticks.length.x.top : NULL
## $ axis.ticks.length.x.bottom : NULL
## $ axis.ticks.length.y : NULL
## $ axis.ticks.length.y.left : NULL
## $ axis.ticks.length.y.right : NULL
## $ axis.ticks.length.theta : NULL
## $ axis.ticks.length.r : NULL
## $ axis.minor.ticks.length : 'rel' num 0.75
## $ axis.minor.ticks.length.x : NULL
## $ axis.minor.ticks.length.x.top : NULL
## $ axis.minor.ticks.length.x.bottom: NULL
## $ axis.minor.ticks.length.y : NULL
## $ axis.minor.ticks.length.y.left : NULL
## $ axis.minor.ticks.length.y.right : NULL
## $ axis.minor.ticks.length.theta : NULL
## $ axis.minor.ticks.length.r : NULL
## $ axis.line : list()
## ..- attr(*, "class")= chr [1:2] "element_blank" "element"
## $ axis.line.x : NULL
## $ axis.line.x.top : NULL
## $ axis.line.x.bottom : NULL
## $ axis.line.y : NULL
## $ axis.line.y.left : NULL
## $ axis.line.y.right : NULL
## $ axis.line.theta : NULL
## $ axis.line.r : NULL
## $ legend.background :List of 5
## ..$ fill : NULL
## ..$ colour : logi NA
## ..$ linewidth : NULL
## ..$ linetype : NULL
## ..$ inherit.blank: logi TRUE
## ..- attr(*, "class")= chr [1:2] "element_rect" "element"
## $ legend.margin : 'margin' num [1:4] 5.5points 5.5points 5.5points 5.5points
## ..- attr(*, "unit")= int 8
## $ legend.spacing : 'simpleUnit' num 11points
## ..- attr(*, "unit")= int 8
## $ legend.spacing.x : NULL
## $ legend.spacing.y : NULL
## $ legend.key : NULL
## $ legend.key.size : 'simpleUnit' num 1.2lines
## ..- attr(*, "unit")= int 3
## $ legend.key.height : NULL
## $ legend.key.width : NULL
## $ legend.key.spacing : 'simpleUnit' num 5.5points
## ..- attr(*, "unit")= int 8
## $ legend.key.spacing.x : NULL
## $ legend.key.spacing.y : NULL
## $ legend.frame : NULL
## $ legend.ticks : NULL
## $ legend.ticks.length : 'rel' num 0.2
## $ legend.axis.line : NULL
## $ legend.text :List of 11
## ..$ family : NULL
## ..$ face : NULL
## ..$ colour : NULL
## ..$ size : 'rel' num 0.8
## ..$ hjust : NULL
## ..$ vjust : NULL
## ..$ angle : NULL
## ..$ lineheight : NULL
## ..$ margin : NULL
## ..$ debug : NULL
## ..$ inherit.blank: logi TRUE
## ..- attr(*, "class")= chr [1:2] "element_text" "element"
## $ legend.text.position : NULL
## $ legend.title :List of 11
## ..$ family : NULL
## ..$ face : NULL
## ..$ colour : NULL
## ..$ size : NULL
## ..$ hjust : num 0
## ..$ vjust : NULL
## ..$ angle : NULL
## ..$ lineheight : NULL
## ..$ margin : NULL
## ..$ debug : NULL
## ..$ inherit.blank: logi TRUE
## ..- attr(*, "class")= chr [1:2] "element_text" "element"
## $ legend.title.position : NULL
## $ legend.position : chr "right"
## $ legend.position.inside : NULL
## $ legend.direction : NULL
## $ legend.byrow : NULL
## $ legend.justification : chr "center"
## $ legend.justification.top : NULL
## $ legend.justification.bottom : NULL
## $ legend.justification.left : NULL
## $ legend.justification.right : NULL
## $ legend.justification.inside : NULL
## $ legend.location : NULL
## $ legend.box : NULL
## $ legend.box.just : NULL
## $ legend.box.margin : 'margin' num [1:4] 0cm 0cm 0cm 0cm
## ..- attr(*, "unit")= int 1
## $ legend.box.background : list()
## ..- attr(*, "class")= chr [1:2] "element_blank" "element"
## $ legend.box.spacing : 'simpleUnit' num 11points
## ..- attr(*, "unit")= int 8
## [list output truncated]
## - attr(*, "class")= chr [1:2] "theme" "gg"
## - attr(*, "complete")= logi TRUE
## - attr(*, "validate")= logi TRUE
Perbandingan Model Berdasarkan Nilai MSE
MSE = function(y.duga,y.aktual){
mean((y.duga - y.aktual)^2)
}
data.frame(Reg.Linear = MSE(predict(fit.lin),Auto$mpg),
Polynomial = MSE(predict(fit.pol),Auto$mpg),
Fgs.Tangga = MSE(predict(fit.tangga),Auto$mpg),
Cbc.Spline = MSE(predict(fit.cb.spline),Auto$mpg),
NCb.Spline = MSE(predict(fit.ncb.spline),Auto$mpg))
## Reg.Linear Polynomial Fgs.Tangga Cbc.Spline NCb.Spline
## 1 23.94366 18.87633 21.98227 17.95169 18.11617