library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5 ✓ purrr 0.3.4
## ✓ tibble 3.1.6 ✓ dplyr 1.0.8
## ✓ tidyr 1.2.0 ✓ stringr 1.4.0
## ✓ readr 2.1.2 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(ggplot2)
library(MASS)
##
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
##
## select
library(stargazer)
##
## Please cite as:
## Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
## R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
library(foreign)
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
##
## recode
## The following object is masked from 'package:purrr':
##
## some
library(gvlma)
library(effects)
## lattice theme set by effectsTheme()
## See ?effectsTheme for details.
library(sjPlot)
## Registered S3 method overwritten by 'parameters':
## method from
## format.parameters_distribution datawizard
## Learn more about sjPlot with 'browseVignettes("sjPlot")'.
library(relaimpo)
## Loading required package: boot
##
## Attaching package: 'boot'
## The following object is masked from 'package:car':
##
## logit
## Loading required package: survey
## Loading required package: grid
## Loading required package: Matrix
##
## Attaching package: 'Matrix'
## The following objects are masked from 'package:tidyr':
##
## expand, pack, unpack
## Loading required package: survival
##
## Attaching package: 'survival'
## The following object is masked from 'package:boot':
##
## aml
##
## Attaching package: 'survey'
## The following object is masked from 'package:graphics':
##
## dotchart
## Loading required package: mitools
## This is the global version of package relaimpo.
## If you are a non-US user, a version with the interesting additional metric pmvd is available
## from Ulrike Groempings web site at prof.beuth-hochschule.de/groemping.
library(ggplot2)
library(lmtest)
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(readxl)
library(kableExtra)
##
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
##
## group_rows
library(agricolae)
library(tseries)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(corrplot)
## corrplot 0.92 loaded
library(readxl)
ratio<-read_excel("~/Downloads/ABDA2.xlsx")
## New names:
## * `` -> ...1
head(ratio)
## # A tibble: 6 × 7
## ...1 Price ROA ROE DER PER CR
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2017 6900 0.0149 0.0329 1.21 100. 1.83
## 2 2 6800 0.0186 0.0420 1.26 77.9 1.79
## 3 3 6900 0.0115 0.0251 1.18 128. 1.85
## 4 4 7250 0.0102 0.0220 1.16 148. 1.86
## 5 2018 7500 0.0144 0.0301 1.10 108. 1.91
## 6 2 7600 0.0195 0.0400 1.05 82.3 1.95
y=ratio$Price #dependen
x1= ratio$ROA #independen
x2= ratio$ROE #independen
x3= ratio$DER #independen
x4= ratio$PER #independen
x5= ratio$CR #independen
scat1=ggplot(ratio,aes(x1,y))+geom_point()+geom_smooth(method="lm",se=T)
scat1
## `geom_smooth()` using formula 'y ~ x'
Berdasarkan pola diatas dimana titik-titik berada di sekitar suatu garis lurus, diduga variabel ROA memiliki hubungan dengan Variabel Harga Closing Saham.
scat2=ggplot(ratio,aes(x2,y))+geom_point()+geom_smooth(method="lm",se=T)
scat2
## `geom_smooth()` using formula 'y ~ x'
Berdasarkan pola diatas dimana titik-titik berada di sekitar suatu garis lurus, diduga variabel ROE memiliki hubungan dengan Variabel Harga Closing Saham.
scat3=ggplot(ratio,aes(x3,y))+geom_point()+geom_smooth(method="lm",se=T)
scat3
## `geom_smooth()` using formula 'y ~ x'
Berdasarkan pola diatas dimana titik-titik berada di sekitar suatu garis lurus, diduga variabel DER memiliki hubungan dengan Variabel Harga Closing Saham.
scat4=ggplot(ratio,aes(x4,y))+geom_point()+geom_smooth(method="lm",se=T)
scat4
## `geom_smooth()` using formula 'y ~ x'
Berdasarkan pola diatas dimana titik-titik berada di sekitar suatu garis lurus, diduga variabel PER memiliki hubungan dengan Variabel Harga Closing Saham.
scat5=ggplot(ratio,aes(x5,y))+geom_point()+geom_smooth(method="lm",se=T)
scat5
## `geom_smooth()` using formula 'y ~ x'
Berdasarkan pola diatas dimana titik-titik berada di sekitar suatu garis lurus, diduga variabel CR memiliki hubungan dengan Variabel Harga Closing Saham.
model <- lm(y ~ x1 + x2 + x3 + x4 + x5, data = ratio)
summary(model)
##
## Call:
## lm(formula = y ~ x1 + x2 + x3 + x4 + x5, data = ratio)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1166.0 -117.8 107.3 196.5 668.5
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 50001.43 40783.36 1.226 0.248
## x1 725376.27 661731.66 1.096 0.299
## x2 -336754.37 309548.66 -1.088 0.302
## x3 -8265.60 11925.48 -0.693 0.504
## x4 1.68 2.61 0.644 0.534
## x5 -18033.86 14895.69 -1.211 0.254
##
## Residual standard error: 619.1 on 10 degrees of freedom
## Multiple R-squared: 0.3799, Adjusted R-squared: 0.06983
## F-statistic: 1.225 on 5 and 10 DF, p-value: 0.3656
ks.test(model$residuals, ecdf(model$residuals))
##
## One-sample Kolmogorov-Smirnov test
##
## data: model$residuals
## D = 0.0625, p-value = 1
## alternative hypothesis: two-sided
shapiro.test(residuals(model))
##
## Shapiro-Wilk normality test
##
## data: residuals(model)
## W = 0.84327, p-value = 0.01086
# analisis residual
residual=resid(model) #menampilkan residual dari model
jarque.bera.test(residual) #normalitas
##
## Jarque Bera Test
##
## data: residual
## X-squared = 4.1997, df = 2, p-value = 0.1225
qqPlot(residual,distribution="norm",main="Normal QQ Plot") #normalitas dengan plot
## [1] 13 9
qqPlot(residual,distribution="norm",main="Normal QQ Plot") #normalitas dengan plot
## [1] 13 9
bptest(model, data=ratio)
##
## studentized Breusch-Pagan test
##
## data: model
## BP = 6.2581, df = 5, p-value = 0.2819
dwtest(model)
##
## Durbin-Watson test
##
## data: model
## DW = 1.8409, p-value = 0.1676
## alternative hypothesis: true autocorrelation is greater than 0
vif(model)
## x1 x2 x3 x4 x5
## 1310.824708 1224.842433 72.515462 2.200826 111.718274
fundamental <- ratio[c(2,3,4,5,6,7)]
mk <- cor(fundamental)
round(mk,2) #Membulatkan 2 angka di belakang koma
## Price ROA ROE DER PER CR
## Price 1.00 -0.15 -0.09 0.50 0.07 -0.53
## ROA -0.15 1.00 0.99 -0.27 0.15 0.33
## ROE -0.09 0.99 1.00 -0.17 0.17 0.22
## DER 0.50 -0.27 -0.17 1.00 -0.15 -0.99
## PER 0.07 0.15 0.17 -0.15 1.00 0.07
## CR -0.53 0.33 0.22 -0.99 0.07 1.00
corrplot(mk, type="lower",
order = "hclust", # mengurutkan berdasarkan hierarchical clustering
tl.col= "black", # warna tulisan
addCoef.col = "black", # tambahkan koefisien korelasi
diag=FALSE, #menyembunyikan koefisien pada diagonal
tl.srt= 45, # kemiringan tulisan 45 derajat
method = "circle") # Bentuk Visualisasi
model <- lm(y ~ x1 + x2 + x3 + x4 + x5, data = ratio)
summary(model)
##
## Call:
## lm(formula = y ~ x1 + x2 + x3 + x4 + x5, data = ratio)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1166.0 -117.8 107.3 196.5 668.5
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 50001.43 40783.36 1.226 0.248
## x1 725376.27 661731.66 1.096 0.299
## x2 -336754.37 309548.66 -1.088 0.302
## x3 -8265.60 11925.48 -0.693 0.504
## x4 1.68 2.61 0.644 0.534
## x5 -18033.86 14895.69 -1.211 0.254
##
## Residual standard error: 619.1 on 10 degrees of freedom
## Multiple R-squared: 0.3799, Adjusted R-squared: 0.06983
## F-statistic: 1.225 on 5 and 10 DF, p-value: 0.3656
vif(model)
## x1 x2 x3 x4 x5
## 1310.824708 1224.842433 72.515462 2.200826 111.718274
model2 <- lm(y ~ x1 + x2 + x3 + x5, data = ratio)
summary(model2)
##
## Call:
## lm(formula = y ~ x1 + x2 + x3 + x5, data = ratio)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1253.26 -69.24 63.91 308.63 554.55
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 54532 39088 1.395 0.191
## x1 505709 551709 0.917 0.379
## x2 -231696 255957 -0.905 0.385
## x3 -10990 10849 -1.013 0.333
## x5 -18717 14457 -1.295 0.222
##
## Residual standard error: 602.4 on 11 degrees of freedom
## Multiple R-squared: 0.3542, Adjusted R-squared: 0.1193
## F-statistic: 1.508 on 4 and 11 DF, p-value: 0.2662
vif(model2)
## x1 x2 x3 x5
## 962.39384 884.52180 63.38461 111.15115
model3 <- lm(y ~ x1 + x3 + x5, data = ratio)
summary(model3)
##
## Call:
## lm(formula = y ~ x1 + x3 + x5, data = ratio)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1191.9 -114.6 153.3 248.6 801.3
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 29345 27245 1.077 0.303
## x1 6629 20040 0.331 0.747
## x3 -5506 8931 -0.616 0.549
## x5 -8650 9167 -0.944 0.364
##
## Residual standard error: 597.9 on 12 degrees of freedom
## Multiple R-squared: 0.3061, Adjusted R-squared: 0.1326
## F-statistic: 1.764 on 3 and 12 DF, p-value: 0.2074
vif(model3)
## x1 x3 x5
## 1.289248 43.616434 45.374178
model4 <- lm(y ~ x3 + x5, data = ratio)
summary(model4)
##
## Call:
## lm(formula = y ~ x3 + x5, data = ratio)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1169.38 -82.97 84.06 235.34 875.11
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 25916 24317 1.066 0.306
## x3 -4451 8052 -0.553 0.590
## x5 -7432 8103 -0.917 0.376
##
## Residual standard error: 577 on 13 degrees of freedom
## Multiple R-squared: 0.2997, Adjusted R-squared: 0.192
## F-statistic: 2.782 on 2 and 13 DF, p-value: 0.09867
vif(model4)
## x3 x5
## 38.0566 38.0566
model5 <- lm(y ~ x5, data = ratio)
summary(model5)
##
## Call:
## lm(formula = y ~ x5, data = ratio)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1106.7 -188.3 67.1 296.1 941.6
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 12546 2485 5.049 0.000178 ***
## x5 -3012 1280 -2.352 0.033814 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 562.5 on 14 degrees of freedom
## Multiple R-squared: 0.2833, Adjusted R-squared: 0.2321
## F-statistic: 5.533 on 1 and 14 DF, p-value: 0.03381
par(mfrow=c(2,2))
plot(model5)
par(mfrow=c(1,1))
ks.test(model5$residuals, ecdf(model5$residuals))
##
## One-sample Kolmogorov-Smirnov test
##
## data: model5$residuals
## D = 0.0625, p-value = 1
## alternative hypothesis: two-sided
shapiro.test(residuals(model5))
##
## Shapiro-Wilk normality test
##
## data: residuals(model5)
## W = 0.94326, p-value = 0.3909
# analisis residual
residual1=resid(model5) #menampilkan residual dari model
jarque.bera.test(residual1) #normalitas
##
## Jarque Bera Test
##
## data: residual1
## X-squared = 0.73276, df = 2, p-value = 0.6932
qqPlot(residual1,distribution="norm",main="Normal QQ Plot") #normalitas dengan plot
## [1] 13 9
qqPlot(residual1,distribution="norm",main="Normal QQ Plot") #normalitas dengan plot
## [1] 13 9
bptest(model5, data=ratio)
##
## studentized Breusch-Pagan test
##
## data: model5
## BP = 0.00010966, df = 1, p-value = 0.9916
dwtest(model5)
##
## Durbin-Watson test
##
## data: model5
## DW = 1.4364, p-value = 0.07588
## alternative hypothesis: true autocorrelation is greater than 0
model5 <- lm(y ~ x5, data = ratio)
summary(model5)
##
## Call:
## lm(formula = y ~ x5, data = ratio)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1106.7 -188.3 67.1 296.1 941.6
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 12546 2485 5.049 0.000178 ***
## x5 -3012 1280 -2.352 0.033814 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 562.5 on 14 degrees of freedom
## Multiple R-squared: 0.2833, Adjusted R-squared: 0.2321
## F-statistic: 5.533 on 1 and 14 DF, p-value: 0.03381