COBA ASUMSI KLASIKKKK

Rose Dwi Aulia Amaradhani

2025-09-08

library(readxl)
library(lmtest)
## Warning: package 'lmtest' was built under R version 4.3.3
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 4.3.2
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(car)
## Loading required package: carData
margin <- read_excel("C:/Users/Asus/Downloads/cobacoba.xlsx", col_names = TRUE)
margin

1. X1 terhadap Y1

model1 <- lm(y1 ~ x1, data = margin)
summary(model1)
## 
## Call:
## lm(formula = y1 ~ x1, data = margin)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.8187 -1.8184 -0.4917  1.7926  6.6111 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept)   0.3572     1.0014   0.357    0.725
## x1           -0.1870     0.8458  -0.221    0.827
## 
## Residual standard error: 2.88 on 21 degrees of freedom
## Multiple R-squared:  0.002322,   Adjusted R-squared:  -0.04519 
## F-statistic: 0.04887 on 1 and 21 DF,  p-value: 0.8272

2. X2 terhadap Y1

model2 <- lm(y1 ~ x2, data = margin)
summary(model2)
## 
## Call:
## lm(formula = y1 ~ x2, data = margin)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -3.683 -1.873 -0.583  1.720  6.762 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept)  0.26977    1.52513   0.177    0.861
## x2          -0.02104    0.32847  -0.064    0.950
## 
## Residual standard error: 2.883 on 21 degrees of freedom
## Multiple R-squared:  0.0001953,  Adjusted R-squared:  -0.04741 
## F-statistic: 0.004101 on 1 and 21 DF,  p-value: 0.9495

3. X1 terhadap Y2

model3 <- lm(y2 ~ x1, data = margin)
summary(model3)
## 
## Call:
## lm(formula = y2 ~ x1, data = margin)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.1239 -1.3580 -0.1117  1.0900  4.5429 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   2.4440     0.6040   4.046 0.000582 ***
## x1           -0.2593     0.5102  -0.508 0.616529    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.737 on 21 degrees of freedom
## Multiple R-squared:  0.01215,    Adjusted R-squared:  -0.03489 
## F-statistic: 0.2584 on 1 and 21 DF,  p-value: 0.6165

4. X2 terhadap Y2

model4 <- lm(y2 ~ x2, data = margin)
summary(model4)
## 
## Call:
## lm(formula = y2 ~ x2, data = margin)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.8187 -0.8220 -0.2955  0.5084  4.3661 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept)   0.7626     0.8595   0.887   0.3850  
## x2            0.3364     0.1851   1.818   0.0834 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.624 on 21 degrees of freedom
## Multiple R-squared:  0.1359, Adjusted R-squared:  0.09478 
## F-statistic: 3.303 on 1 and 21 DF,  p-value: 0.08343

5. X1 X2 terhadap Y1

model5 <- lm(y1 ~ x1 + x2, data = margin)
summary(model5)
## 
## Call:
## lm(formula = y1 ~ x1 + x2, data = margin)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.8197 -1.8258 -0.5119  1.7878  6.6313 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept)  0.43123    1.73509   0.249    0.806
## x1          -0.18493    0.86753  -0.213    0.833
## x2          -0.01782    0.33654  -0.053    0.958
## 
## Residual standard error: 2.95 on 20 degrees of freedom
## Multiple R-squared:  0.002462,   Adjusted R-squared:  -0.09729 
## F-statistic: 0.02468 on 2 and 20 DF,  p-value: 0.9757

6. X1 X2 terhadap Y2

model6 <- lm(y2 ~ x1 + x2, data = margin)
summary(model6)
## 
## Call:
## lm(formula = y2 ~ x1 + x2, data = margin)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.8243 -0.9726 -0.2356  0.6935  4.1545 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept)   1.0235     0.9697   1.055   0.3038  
## x1           -0.2989     0.4849  -0.616   0.5446  
## x2            0.3417     0.1881   1.816   0.0843 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.649 on 20 degrees of freedom
## Multiple R-squared:  0.152,  Adjusted R-squared:  0.06724 
## F-statistic: 1.793 on 2 and 20 DF,  p-value: 0.1922

uji normalitas

# Shapiro-Wilk Test
shapiro.test(resid(model1))
## 
##  Shapiro-Wilk normality test
## 
## data:  resid(model1)
## W = 0.94767, p-value = 0.2617
# Plot QQ untuk visual
qqnorm(resid(model1))
qqline(resid(model1), col = "red")

H₀ : Residual berdistribusi normal. H₁ : Residual tidak berdistribusi normal. > 0.05, tak tolak H0 kalo tidak normal, bisa menggunakan boxcox

uji heteros

bptest(model1) 
## 
##  studentized Breusch-Pagan test
## 
## data:  model1
## BP = 0.58386, df = 1, p-value = 0.4448

H0: homoskesdas

uji autokol

dwtest(model1)
## 
##  Durbin-Watson test
## 
## data:  model1
## DW = 1.2975, p-value = 0.0409
## alternative hypothesis: true autocorrelation is greater than 0

ada autokol karena data time series HARUS PAKE REGRESI TIME SERIESSS ARRGGHH

uji rataan sisaan = 0

t.test(resid(model1), mu = 0)
## 
##  One Sample t-test
## 
## data:  resid(model1)
## t = 2.0161e-16, df = 22, p-value = 1
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -1.216586  1.216586
## sample estimates:
##    mean of x 
## 1.182723e-16

uji multikol ((dipake untuk lebih dr 1 variabel x))

vif(model5)
##       x1       x2 
## 1.002019 1.002019