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
## Install package "strengejacke" from GitHub (`devtools::install_github("strengejacke/strengejacke")`) to load all sj-packages at once!
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/ASRM3.xlsx")
head(ratio)
## # A tibble: 6 × 6
## Date Price DER PBV PE EPS
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2017 (Q1) 1692 3.38 1.7 8.1 67.6
## 2 2017 (Q2) 1728 3.16 1.6 8.3 112.
## 3 2017 (Q3) 1706 3.32 1.5 8.3 -12.2
## 4 2017 (Q4) 1608 2.98 1.4 8.9 32.6
## 5 2018 (Q1) 1749 3.07 1.5 8.7 64.4
## 6 2018 (Q2) 1678 3.27 1.4 8.5 67.6
summary(ratio)
## Date Price DER PBV
## Length:16 Min. :1485 Min. :0.2642 Min. :1.000
## Class :character 1st Qu.:1618 1st Qu.:2.6004 1st Qu.:1.100
## Mode :character Median :1663 Median :2.7557 Median :1.250
## Mean :1646 Mean :2.6759 Mean :1.281
## 3rd Qu.:1696 3rd Qu.:3.0916 3rd Qu.:1.425
## Max. :1749 Max. :3.3806 Max. :1.700
## PE EPS
## Min. : 6.200 Min. :-12.17
## 1st Qu.: 6.575 1st Qu.: 35.53
## Median : 8.150 Median : 59.82
## Mean : 7.825 Mean : 54.65
## 3rd Qu.: 8.425 3rd Qu.: 67.61
## Max. :10.900 Max. :112.20
y=ratio$Price #dependen
x1= ratio$DER #independen
x2= ratio$PBV #independen
x3= ratio$PE #independen
x4= ratio$EPS #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 pada membentuk suatu garis lurus, diduga variabel DER 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 pada membentuk suatu garis lurus, diduga variabel PBV 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 PE 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 EPS memiliki hubungan dengan Variabel Harga Closing Saham.
model <- lm(y ~ x1 + x2 + x3 + x4, data = ratio)
summary(model)
##
## Call:
## lm(formula = y ~ x1 + x2 + x3 + x4, data = ratio)
##
## Residuals:
## Min 1Q Median 3Q Max
## -83.652 -38.716 1.096 43.944 103.087
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1316.1875 121.0362 10.874 3.18e-07 ***
## x1 -14.7039 23.7860 -0.618 0.5490
## x2 220.5117 90.3322 2.441 0.0328 *
## x3 13.3968 14.9421 0.897 0.3891
## x4 -0.3296 0.5515 -0.598 0.5621
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 62.76 on 11 degrees of freedom
## Multiple R-squared: 0.5073, Adjusted R-squared: 0.3281
## F-statistic: 2.831 on 4 and 11 DF, p-value: 0.07727
vif(model)
## x1 x2 x3 x4
## 1.173131 1.459452 1.313560 1.020999
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
# analisis residual
residual=resid(model) #menampilkan residual dari model
jarque.bera.test(residual) #normalitas
##
## Jarque Bera Test
##
## data: residual
## X-squared = 0.53812, df = 2, p-value = 0.7641
qqPlot(residual,distribution="norm",main="Normal QQ Plot") #normalitas dengan plot
## [1] 15 14
qqPlot(residual,distribution="norm",main="Normal QQ Plot") #normalitas dengan plot
## [1] 15 14
bptest(model, data=ratio)
##
## studentized Breusch-Pagan test
##
## data: model
## BP = 4.8811, df = 4, p-value = 0.2997
dwtest(model)
##
## Durbin-Watson test
##
## data: model
## DW = 1.9263, p-value = 0.2966
## alternative hypothesis: true autocorrelation is greater than 0
vif(model)
## x1 x2 x3 x4
## 1.173131 1.459452 1.313560 1.020999
fundamental <- ratio[c(2,3,4,5,6)]
mk <- cor(fundamental)
round(mk,2) #Membulatkan 2 angka di belakang koma
## Price DER PBV PE EPS
## Price 1.00 0.15 0.66 0.49 -0.07
## DER 0.15 1.00 0.37 0.24 -0.03
## PBV 0.66 0.37 1.00 0.48 0.10
## PE 0.49 0.24 0.48 1.00 -0.02
## EPS -0.07 -0.03 0.10 -0.02 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
summary(model)
##
## Call:
## lm(formula = y ~ x1 + x2 + x3 + x4, data = ratio)
##
## Residuals:
## Min 1Q Median 3Q Max
## -83.652 -38.716 1.096 43.944 103.087
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1316.1875 121.0362 10.874 3.18e-07 ***
## x1 -14.7039 23.7860 -0.618 0.5490
## x2 220.5117 90.3322 2.441 0.0328 *
## x3 13.3968 14.9421 0.897 0.3891
## x4 -0.3296 0.5515 -0.598 0.5621
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 62.76 on 11 degrees of freedom
## Multiple R-squared: 0.5073, Adjusted R-squared: 0.3281
## F-statistic: 2.831 on 4 and 11 DF, p-value: 0.07727
vif(model)
## x1 x2 x3 x4
## 1.173131 1.459452 1.313560 1.020999