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
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/LPGI3.xlsx")
head(ratio)
## # A tibble: 6 × 6
## Date Price DER PBV PE EPS
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2017 (Q1) 5700 1.00 0.7 10.3 62.1
## 2 2017 (Q2) 5575 0.929 0.7 10 222.
## 3 2017 (Q3) 4990 0.922 0.6 4.9 27.4
## 4 2017 (Q4) 4870 1.21 0.6 5.5 301.
## 5 2018 (Q1) 4000 1.41 0.6 6.5 108.
## 6 2018 (Q2) 4000 1.46 0.6 6.1 34.4
summary(ratio)
## Date Price DER PBV
## Length:16 Min. :2800 Min. :0.9223 Min. :0.5000
## Class :character 1st Qu.:3575 1st Qu.:1.3024 1st Qu.:0.6000
## Mode :character Median :3950 Median :1.8097 Median :0.6000
## Mean :4096 Mean :1.6335 Mean :0.6312
## 3rd Qu.:4442 3rd Qu.:1.9241 3rd Qu.:0.7000
## Max. :5700 Max. :2.2698 Max. :0.7000
## PE EPS
## Min. : 3.700 Min. :-60.54
## 1st Qu.: 5.650 1st Qu.: 60.66
## Median : 6.650 Median :121.89
## Mean : 6.900 Mean :138.95
## 3rd Qu.: 7.925 3rd Qu.:223.78
## Max. :10.300 Max. :300.97
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
## -746.30 -130.58 2.26 172.62 512.92
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2181.2679 1131.8967 1.927 0.080182 .
## x1 -1361.2921 230.1421 -5.915 0.000101 ***
## x2 6770.7895 2079.5992 3.256 0.007656 **
## x3 -37.3365 70.7150 -0.528 0.607996
## x4 0.8777 0.9570 0.917 0.378764
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 370 on 11 degrees of freedom
## Multiple R-squared: 0.8473, Adjusted R-squared: 0.7918
## F-statistic: 15.26 on 4 and 11 DF, p-value: 0.0001836
vif(model)
## x1 x2 x3 x4
## 1.218438 1.717354 1.940646 1.077591
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.73354, df = 2, p-value = 0.693
qqPlot(residual,distribution="norm",main="Normal QQ Plot") #normalitas dengan plot
## [1] 7 13
qqPlot(residual,distribution="norm",main="Normal QQ Plot") #normalitas dengan plot
## [1] 7 13
bptest(model, data=ratio)
##
## studentized Breusch-Pagan test
##
## data: model
## BP = 1.0387, df = 4, p-value = 0.9039
dwtest(model)
##
## Durbin-Watson test
##
## data: model
## DW = 1.8621, p-value = 0.2652
## alternative hypothesis: true autocorrelation is greater than 0
vif(model)
## x1 x2 x3 x4
## 1.218438 1.717354 1.940646 1.077591
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.78 0.56 0.52 0.10
## DER -0.78 1.00 -0.12 -0.36 0.13
## PBV 0.56 -0.12 1.00 0.63 0.20
## PE 0.52 -0.36 0.63 1.00 0.14
## EPS 0.10 0.13 0.20 0.14 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
## -746.30 -130.58 2.26 172.62 512.92
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2181.2679 1131.8967 1.927 0.080182 .
## x1 -1361.2921 230.1421 -5.915 0.000101 ***
## x2 6770.7895 2079.5992 3.256 0.007656 **
## x3 -37.3365 70.7150 -0.528 0.607996
## x4 0.8777 0.9570 0.917 0.378764
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 370 on 11 degrees of freedom
## Multiple R-squared: 0.8473, Adjusted R-squared: 0.7918
## F-statistic: 15.26 on 4 and 11 DF, p-value: 0.0001836
vif(model)
## x1 x2 x3 x4
## 1.218438 1.717354 1.940646 1.077591