# nhap lieu
dulieu=file.choose()
datachungkhoan=read.csv(dulieu, header = TRUE, sep = ";", dec = ".")
save(datachungkhoan, file = "datachungkhoan.rda")
attach(datachungkhoan)
is.data.frame(datachungkhoan)
## [1] TRUE
head(datachungkhoan)
## Data HNX VN30 VNI
## 1 09/10/2026 261.60 1873.43 1735.09
## 2 08/10/2026 256.22 1877.00 1738.97
## 3 07/10/2026 259.82 1894.20 1753.39
## 4 06/10/2026 265.53 1898.82 1759.08
## 5 05/10/2026 269.62 1894.46 1753.20
## 6 02/10/2026 266.75 1875.99 1737.71
dim(datachungkhoan)
## [1] 290 4
# Câu A
library(psych)
abcde=data.frame(HNX,VN30,VNI)
describe(abcde)
## vars n mean sd median trimmed mad min max range skew
## HNX 1 290 270.16 18.99 267.12 267.97 18.43 235.36 336.16 100.80 0.96
## VN30 2 290 1935.87 78.69 1939.17 1936.69 93.83 1741.05 2096.76 355.71 -0.11
## VNI 3 290 1757.84 85.94 1760.07 1757.27 112.51 1580.54 1927.94 347.40 0.02
## kurtosis se
## HNX 0.74 1.12
## VN30 -0.68 4.62
## VNI -1.15 5.05
summary(HNX)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 235.4 255.1 267.1 270.2 279.9 336.2
summary(VN30)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1741 1873 1939 1936 1997 2097
summary(VNI)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1581 1679 1760 1758 1828 1928
var(HNX)
## [1] 360.626
var(VN30)
## [1] 6192.73
var(VNI)
## [1] 7385.119
sd(HNX)
## [1] 18.99015
sd(VN30)
## [1] 78.6939
sd(VNI)
## [1] 85.93672
# Câu B
HNXMH=cut(HNX, breaks=3, labels=c("Thap","Trung binh","Cao"))
VN30MH=cut(VN30, breaks=3, labels=c("Thap","Trung binh","Cao"))
VNIMH=cut(VNI, breaks=3, labels=c("Thap","Trung binh","Cao"))
table(HNXMH)
## HNXMH
## Thap Trung binh Cao
## 153 115 22
table(VN30MH)
## VN30MH
## Thap Trung binh Cao
## 52 144 94
table(VNIMH)
## VNIMH
## Thap Trung binh Cao
## 95 103 92
# Câu C
# Thong ke mo ta Ratio Scale
library(psych)
abcde=data.frame(HNX,VN30,VNI)
describe(abcde)
## vars n mean sd median trimmed mad min max range skew
## HNX 1 290 270.16 18.99 267.12 267.97 18.43 235.36 336.16 100.80 0.96
## VN30 2 290 1935.87 78.69 1939.17 1936.69 93.83 1741.05 2096.76 355.71 -0.11
## VNI 3 290 1757.84 85.94 1760.07 1757.27 112.51 1580.54 1927.94 347.40 0.02
## kurtosis se
## HNX 0.74 1.12
## VN30 -0.68 4.62
## VNI -1.15 5.05
summary(abcde)
## HNX VN30 VNI
## Min. :235.4 Min. :1741 Min. :1581
## 1st Qu.:255.1 1st Qu.:1873 1st Qu.:1679
## Median :267.1 Median :1939 Median :1760
## Mean :270.2 Mean :1936 Mean :1758
## 3rd Qu.:279.9 3rd Qu.:1997 3rd Qu.:1828
## Max. :336.2 Max. :2097 Max. :1928
var(HNX)
## [1] 360.626
var(VN30)
## [1] 6192.73
var(VNI)
## [1] 7385.119
sd(HNX)
## [1] 18.99015
sd(VN30)
## [1] 78.6939
sd(VNI)
## [1] 85.93672
#Nhận xét: Dựa vào kết quả thống kê mô tả, nhận xét giá trị trung bình, giá trị nhỏ nhất, lớn nhất và độ lệch chuẩn của ba chỉ số HNX, VN30 và VNI.
# Thong ke mo ta Ordinal Scale
table(HNXMH)
## HNXMH
## Thap Trung binh Cao
## 153 115 22
prop.table(table(HNXMH))*100
## HNXMH
## Thap Trung binh Cao
## 52.758621 39.655172 7.586207
table(VN30MH)
## VN30MH
## Thap Trung binh Cao
## 52 144 94
prop.table(table(VN30MH))*100
## VN30MH
## Thap Trung binh Cao
## 17.93103 49.65517 32.41379
table(VNIMH)
## VNIMH
## Thap Trung binh Cao
## 95 103 92
prop.table(table(VNIMH))*100
## VNIMH
## Thap Trung binh Cao
## 32.75862 35.51724 31.72414
#Nhận xét: Dựa vào bảng tần số và tỷ lệ phần trăm để xác định nhóm thấp, trung bình hay cao chiếm tỷ trọng lớn nhất ở từng chỉ số.
# Câu D
# VE BIEU DO TRON
pie(table(HNXMH), col=c("green","blue","pink"), main="Bieu do tron cua HNX")

pie(table(VN30MH), col=c("orange","blue","pink"), main="Bieu do tron cua VN30")

pie(table(VNIMH), col=c("green","orange","pink"), main="Bieu do tron cua VNI")

# VE BIEU DO COT
HNX.freq=table(HNXMH)
barplot(HNX.freq, xlab="Nhom HNX", ylab="So luong", main="Bieu do cot cua HNX", col=c("lightblue","lightgreen","pink"))

VN30.freq=table(VN30MH)
barplot(VN30.freq, xlab="Nhom VN30", ylab="So luong", main="Bieu do cot cua VN30", col=c("lightblue","orange","pink"))

VNI.freq=table(VNIMH)
barplot(VNI.freq, xlab="Nhom VNI", ylab="So luong", main="Bieu do cot cua VNI", col=c("lightblue","lightgreen","orange"))

#Nhận xét: Biểu đồ cột giúp so sánh số lượng quan sát giữa ba nhóm. Biểu đồ tròn thể hiện tỷ trọng của từng nhóm trong tổng số quan sát.
# Bieu do duong
STT=1:290
plot(STT,HNX,type="o",xlab="Ngay thu", ylab="Gia tri HNX",main="Chi so HNX")

plot(STT,VN30,type="o",xlab="Ngay thu", ylab="Gia tri VN30",main="Chi so VN30")

plot(STT,VNI,type="o",xlab="Ngay thu", ylab="Gia tri VNI",main="Chi so VNI")

#Nhận xét: Biểu đồ đường thể hiện sự biến động của từng chỉ số theo thời gian. M quan sát xu hướng tăng, giảm và những giai đoạn biến động mạnh của HNX, VN30 và VNI trong thời kỳ nghiên cứu.
# Câu E
# Phan tich tuong quan Pearson
vars <- datachungkhoan[, c("HNX", "VN30", "VNI")]
cor(vars, method = "pearson")
## HNX VN30 VNI
## HNX 1.000000000 -0.004160607 0.1577996
## VN30 -0.004160607 1.000000000 0.8929899
## VNI 0.157799552 0.892989893 1.0000000
cor.test(datachungkhoan$HNX, datachungkhoan$VN30)
##
## Pearson's product-moment correlation
##
## data: datachungkhoan$HNX and datachungkhoan$VN30
## t = -0.070608, df = 288, p-value = 0.9438
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.1192830 0.1110722
## sample estimates:
## cor
## -0.004160607
cor.test(datachungkhoan$HNX, datachungkhoan$VNI)
##
## Pearson's product-moment correlation
##
## data: datachungkhoan$HNX and datachungkhoan$VNI
## t = 2.7119, df = 288, p-value = 0.007092
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.04340894 0.26810623
## sample estimates:
## cor
## 0.1577996
cor.test(datachungkhoan$VN30, datachungkhoan$VNI)
##
## Pearson's product-moment correlation
##
## data: datachungkhoan$VN30 and datachungkhoan$VNI
## t = 33.671, df = 288, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.8669832 0.9141457
## sample estimates:
## cor
## 0.8929899
# Biểu đồ tương quan đa biến
psych::pairs.panels(vars, method = "pearson")

# Nhận xét cặp VN30 và VNI: Theo kết quả m đã gửi trước đó, hệ số tương quan Pearson khoảng 0,892, với p-value < 2,2e-16. Hai chỉ số có tương quan tuyến tính thuận rất mạnh và mối tương quan có ý nghĩa thống kê ở mức 5%.Với hai cặp HNX–VN30 và HNX–VNI, m dùng kết quả cor.test() để nhận xét tương tự
# Câu F
mreg = lm(VNI ~ HNX + VN30, data=datachungkhoan)
summary(mreg)
##
## Call:
## lm(formula = VNI ~ HNX + VN30, data = datachungkhoan)
##
## Residuals:
## Min 1Q Median 3Q Max
## -87.953 -26.184 8.393 29.191 73.511
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -328.86871 60.70479 -5.418 1.28e-07 ***
## HNX 0.73092 0.11222 6.513 3.28e-10 ***
## VN30 0.97591 0.02708 36.038 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 36.23 on 287 degrees of freedom
## Multiple R-squared: 0.8235, Adjusted R-squared: 0.8223
## F-statistic: 669.6 on 2 and 287 DF, p-value: < 2.2e-16
anova(mreg)
## Analysis of Variance Table
##
## Response: VNI
## Df Sum Sq Mean Sq F value Pr(>F)
## HNX 1 53146 53146 40.494 7.776e-10 ***
## VN30 1 1704489 1704489 1298.738 < 2.2e-16 ***
## Residuals 287 376664 1312
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
confint(mreg)
## 2.5 % 97.5 %
## (Intercept) -448.3517788 -209.3856436
## HNX 0.5100463 0.9517957
## VN30 0.9226118 1.0292134
#Nhận xét: Dựa vào kết quả hồi quy, xem xét dấu và giá trị hệ số hồi quy để xác định chiều tác động của HNX và VN30 đến VNI; căn cứ vào p-value để đánh giá ý nghĩa thống kê của từng biến và kiểm định F để đánh giá mức độ phù hợp chung của mô hình. Nếu p-value < 0,05 thì kết quả có ý nghĩa thống kê ở mức 5%.
# Câu G
#KIỂM ĐỊNH TƯƠNG QUAN PEARSON - CÂU E
cor.test(HNX, VN30, method = "pearson")
##
## Pearson's product-moment correlation
##
## data: HNX and VN30
## t = -0.070608, df = 288, p-value = 0.9438
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.1192830 0.1110722
## sample estimates:
## cor
## -0.004160607
cor.test(HNX, VNI, method = "pearson")
##
## Pearson's product-moment correlation
##
## data: HNX and VNI
## t = 2.7119, df = 288, p-value = 0.007092
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.04340894 0.26810623
## sample estimates:
## cor
## 0.1577996
cor.test(VN30, VNI, method = "pearson")
##
## Pearson's product-moment correlation
##
## data: VN30 and VNI
## t = 33.671, df = 288, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.8669832 0.9141457
## sample estimates:
## cor
## 0.8929899
# Nhận xét: Dựa vào hệ số tương quan Pearson và p-value của từng cặp biến để đánh giá chiều hướng, mức độ và ý nghĩa thống kê của mối tương quan. Nếu p-value < 0,05, mối tương quan có ý nghĩa thống kê ở mức 5%. Theo kết quả đã có, cặp VN30–VNI có tương quan thuận mạnh với hệ số tương quan khoảng 0,892 và p-value < 0,05.
#KIỂM ĐỊNH MÔ HÌNH HỒI QUY - CÂU F
summary(mreg)
##
## Call:
## lm(formula = VNI ~ HNX + VN30, data = datachungkhoan)
##
## Residuals:
## Min 1Q Median 3Q Max
## -87.953 -26.184 8.393 29.191 73.511
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -328.86871 60.70479 -5.418 1.28e-07 ***
## HNX 0.73092 0.11222 6.513 3.28e-10 ***
## VN30 0.97591 0.02708 36.038 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 36.23 on 287 degrees of freedom
## Multiple R-squared: 0.8235, Adjusted R-squared: 0.8223
## F-statistic: 669.6 on 2 and 287 DF, p-value: < 2.2e-16
anova(mreg)
## Analysis of Variance Table
##
## Response: VNI
## Df Sum Sq Mean Sq F value Pr(>F)
## HNX 1 53146 53146 40.494 7.776e-10 ***
## VN30 1 1704489 1704489 1298.738 < 2.2e-16 ***
## Residuals 287 376664 1312
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
if (!requireNamespace("car", quietly = TRUE)) {install.packages("car")}
car::vif(mreg)
## HNX VN30
## 1.000017 1.000017
if (!requireNamespace("lmtest", quietly = TRUE)) {install.packages("lmtest")}
lmtest::dwtest(mreg)
##
## Durbin-Watson test
##
## data: mreg
## DW = 0.055034, p-value < 2.2e-16
## alternative hypothesis: true autocorrelation is greater than 0
lmtest::bptest(mreg)
##
## studentized Breusch-Pagan test
##
## data: mreg
## BP = 24.731, df = 2, p-value = 4.264e-06
par(mfrow = c(2, 2))
plot(mreg)

par(mfrow = c(1, 1))
# Nhận xét: Dựa vào p-value, VIF, Durbin–Watson, Breusch–Pagan và biểu đồ phần dư để đánh giá ý nghĩa thống kê và mức độ đáp ứng các giả định của mô hình hồi quy.