list.files()
## [1] "~$Data Rapi.xlsx" "Data Final.xlsx" "Data Rapi.xlsx"
## [4] "Kode-R-Regresi.html" "Kode-R-Regresi.Rmd" "Kode R Regresi.nb.html"
## [7] "Kode R Regresi.Rmd"
library(readxl)
dat <- read_excel("Data Rapi.xlsx")
dat <- as.data.frame(dat)
dat
#Multiple Linear Regression: T Test, F Test, R-Square
regress <- lm(lnY ~ X1 + X2 + X3 + X4 + X5, data = dat)
summary(regress)
##
## Call:
## lm(formula = lnY ~ X1 + X2 + X3 + X4 + X5, data = dat)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.3699 -0.7610 -0.1102 0.8262 3.3689
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2.422e+00 7.105e-01 -3.409 0.000759 ***
## X1 -4.588e-02 5.585e-02 -0.821 0.412143
## X2 1.667e-05 3.613e-05 0.461 0.644935
## X3 3.628e-05 1.290e-04 0.281 0.778753
## X4 1.467e+00 8.143e-01 1.802 0.072770 .
## X5 4.230e+00 1.487e+00 2.845 0.004799 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.399 on 253 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.05405, Adjusted R-squared: 0.03535
## F-statistic: 2.891 on 5 and 253 DF, p-value: 0.01475
#Normality Test with Kolmogorov-Smirnov
residual <- regress$residuals
KS_asymp <- ks.test(residual,"pnorm", mean(residual), sd(residual), exact = FALSE)
## Warning in ks.test(residual, "pnorm", mean(residual), sd(residual), exact =
## FALSE): ties should not be present for the Kolmogorov-Smirnov test
KS_asymp
##
## One-sample Kolmogorov-Smirnov test
##
## data: residual
## D = 0.067862, p-value = 0.1839
## alternative hypothesis: two-sided
#Normality Test with Q-Qplot
qqnorm(residual, pch = 1, frame = FALSE)
qqline(residual, col = "steelblue", lwd = 2)
#Multicolinearity Test with VIF
library(car)
## Loading required package: carData
car::vif(regress)
## X1 X2 X3 X4 X5
## 1.353265 1.027379 1.019133 1.053864 1.364893
#Auto-Correlation Test with Durbin-Watson test
car::durbinWatsonTest(regress)
## lag Autocorrelation D-W Statistic p-value
## 1 0.004544272 1.978166 0.826
## Alternative hypothesis: rho != 0
#Heteroskedasticity Test with Goldfeld-Quandt test
library(lmtest)
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
gqtest(regress)
##
## Goldfeld-Quandt test
##
## data: regress
## GQ = 1.0783, df1 = 124, df2 = 123, p-value = 0.3381
## alternative hypothesis: variance increases from segment 1 to 2
#Moderating Test
regress <- lm(lnY ~ X1 + X2 + X3 + X4 + X5 + X1Z + X2Z + X3Z + X4Z + X5Z + Z, data = dat)
summary(regress)
##
## Call:
## lm(formula = lnY ~ X1 + X2 + X3 + X4 + X5 + X1Z + X2Z + X3Z +
## X4Z + X5Z + Z, data = dat)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.8989 -0.7130 -0.1170 0.7116 3.4648
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -4.165e+00 8.181e-01 -5.091 7.06e-07 ***
## X1 -1.303e-01 6.192e-02 -2.105 0.036327 *
## X2 -9.513e-06 2.003e-04 -0.047 0.962158
## X3 -2.560e-05 4.687e-04 -0.055 0.956479
## X4 1.466e+00 8.778e-01 1.670 0.096179 .
## X5 8.124e+00 1.738e+00 4.675 4.84e-06 ***
## X1Z 1.321e+00 8.780e-01 1.504 0.133745
## X2Z -1.095e-04 1.494e-03 -0.073 0.941625
## X3Z 5.481e-04 3.822e-03 0.143 0.886078
## X4Z 5.836e-01 1.192e+01 0.049 0.960989
## X5Z -8.525e+01 2.608e+01 -3.269 0.001233 **
## Z 3.989e+01 1.158e+01 3.445 0.000671 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.342 on 247 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.1504, Adjusted R-squared: 0.1126
## F-statistic: 3.975 on 11 and 247 DF, p-value: 2.434e-05