options(repos = c(CRAN = "https://cran.naftaliharris.com"))
install.packages("epitools")
## Installing package into 'C:/Users/HP/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## package 'epitools' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\HP\AppData\Local\Temp\Rtmp0wYSYR\downloaded_packages
library(epitools)
install.packages("dplyr")
## Installing package into 'C:/Users/HP/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## package 'dplyr' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\HP\AppData\Local\Temp\Rtmp0wYSYR\downloaded_packages
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.3.1
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
install.packages("pROC")
## Installing package into 'C:/Users/HP/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## package 'pROC' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\HP\AppData\Local\Temp\Rtmp0wYSYR\downloaded_packages
library(pROC)
## Warning: package 'pROC' was built under R version 4.3.1
## Type 'citation("pROC")' for a citation.
##
## Attaching package: 'pROC'
## The following objects are masked from 'package:stats':
##
## cov, smooth, var
library(data.table)
## Warning: package 'data.table' was built under R version 4.3.1
##
## Attaching package: 'data.table'
## The following objects are masked from 'package:dplyr':
##
## between, first, last
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.1
install.packages("mdscore")
## Installing package into 'C:/Users/HP/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## package 'mdscore' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\HP\AppData\Local\Temp\Rtmp0wYSYR\downloaded_packages
install.packages("mass")
## Installing package into 'C:/Users/HP/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## Warning: package 'mass' is not available for this version of R
##
## A version of this package for your version of R might be available elsewhere,
## see the ideas at
## https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
## Warning: Perhaps you meant 'MASS' ?
library(mdscore)
## Warning: package 'mdscore' was built under R version 4.3.1
## Loading required package: MASS
##
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
##
## select
install.packages("caret")
## Installing package into 'C:/Users/HP/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## package 'caret' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\HP\AppData\Local\Temp\Rtmp0wYSYR\downloaded_packages
library(caret)
## Warning: package 'caret' was built under R version 4.3.1
## Loading required package: lattice
install.packages("DescTools")
## Installing package into 'C:/Users/HP/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## package 'DescTools' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\HP\AppData\Local\Temp\Rtmp0wYSYR\downloaded_packages
library(DescTools)
## Warning: package 'DescTools' was built under R version 4.3.1
##
## Attaching package: 'DescTools'
## The following objects are masked from 'package:caret':
##
## MAE, RMSE
## The following object is masked from 'package:data.table':
##
## %like%
install.packages("caret")
## Warning: package 'caret' is in use and will not be installed
library(caret)
# Datasets
data <- read.csv("D:/PTDLDT/BT.csv")
str(data)
## 'data.frame': 17417 obs. of 13 variables:
## $ employee_id : int 8724 74430 72255 38562 64486 46232 54542 67269 66174 76303 ...
## $ department : chr "Technology" "HR" "Sales & Marketing" "Procurement" ...
## $ region : chr "region_26" "region_4" "region_13" "region_2" ...
## $ education : chr "Bachelors" "Bachelors" "Bachelors" "Bachelors" ...
## $ gender : chr "m" "f" "m" "f" ...
## $ recruitment_channel : chr "sourcing" "other" "other" "other" ...
## $ no_of_trainings : int 1 1 1 3 1 1 1 2 1 1 ...
## $ age : int 24 31 31 31 30 36 33 36 51 29 ...
## $ previous_year_rating : int 0 3 1 2 4 3 5 3 4 5 ...
## $ length_of_service : int 1 5 4 9 7 2 3 3 11 2 ...
## $ KPIs_met_more_than_8N: chr "Y" "N" "N" "N" ...
## $ awards_won : chr "N" "N" "N" "N" ...
## $ avg_training_score : int 77 51 47 65 61 68 57 85 75 76 ...
KPIs_met_more_than_8N <- data$KPIs_met_more_than_8N
gender <- data$gender
m <- data.frame(data$employee_id, data$department, data$region, data$education, data$gender, data$recruitment_channel, data$no_of_trainings, data$age, data$previous_year_rating, data$length_of_service, data$KPIs_met_more_than_8N, data$awards_won, data$avg_training_score, KPIs_met_more_than_8N)
not <- m %>% mutate(soluong = case_when(data$no_of_trainings == "1" ~ 3, data$no_of_trainings == "2" ~ 3, data$no_of_trainings == "3" ~ 3, data$no_of_trainings == "4" ~ 3, data$no_of_trainings == "5" ~ 4, data$no_of_trainings == "6" ~ 4, data$no_of_trainings == "7" ~ 4, data$no_of_trainings == "8" ~ 4, data$no_of_trainings == "9" ~ 4))
no_of_trainings <-cut(not$soluong, breaks=c(0,3,4), labels=c('Ít', 'Nhiều'))
awards_won <- data$awards_won
avg_training_score <-cut(data$avg_training_score, breaks=c(0,50,100), labels=c('thấp', 'cao'))
Chạy mô hình hồi quy cho biến định tính trong câu 2, thức hiện các bài toán liên quan
Phân tích các yếu tố tác động đến mức độ hoàn thành KPIs của nhân viên
Thông qua kiểm định, các yếu tố có liên quan đến mức độ hoàn thành KPIs trên 80% của nhân viên (KPIs_met_more_than_8N) có liên quan đến giới tính (gender), số khóa học nhân viên đã tham gia (no_of_trainings), giải thương của nhân viên (awards_won), điểm trung bình của các khóa học đào tạo mà nhân viên đã tham gia (avg_training_score).
K <- data.frame(data$employee_id, data$department, data$region, data$education, data$gender, data$recruitment_channel, data$no_of_trainings, data$age, data$previous_year_rating, data$length_of_service, data$KPIs_met_more_than_8N, data$awards_won, data$avg_training_score, KPIs_met_more_than_8N, gender, no_of_trainings, awards_won, avg_training_score)
K$K <- factor(K$K, levels = c(0, 1))
# Xây dựng mô hình logit
mh1 <- glm(data = K, formula = factor(KPIs_met_more_than_8N) ~ gender + no_of_trainings + awards_won + avg_training_score, family = binomial(link = "logit"))
levels(factor(KPIs_met_more_than_8N))
## [1] "N" "Y"
summary(mh1)
##
## Call:
## glm(formula = factor(KPIs_met_more_than_8N) ~ gender + no_of_trainings +
## awards_won + avg_training_score, family = binomial(link = "logit"),
## data = K)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -0.80279 0.04418 -18.170 < 2e-16 ***
## genderm -0.15234 0.03480 -4.378 1.2e-05 ***
## no_of_trainingsNhiều -0.78301 0.34500 -2.270 0.0232 *
## awards_wonY 1.37109 0.10831 12.659 < 2e-16 ***
## avg_training_scorecao 0.38085 0.03951 9.640 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 22738 on 17416 degrees of freedom
## Residual deviance: 22426 on 17412 degrees of freedom
## AIC: 22436
##
## Number of Fisher Scoring iterations: 4
# Câu lệnh tính e mũ cho các hệ số hồi quy mẫu trong mô hình
exp(mh1$coef)
## (Intercept) genderm no_of_trainingsNhiều
## 0.4480762 0.8587004 0.4570295
## awards_wonY avg_training_scorecao
## 3.9396515 1.4635266
BrierScore(mh1)
## [1] 0.2258762
Mô hình tổng quát của logit:
logit(π) = log (π/1-π) = β0 + β1X1 + β2X2 + ⋯ + βkXk
Sau khi chạy mô hình logit ta có hàm hồi quy sau:
logit(π) = log (π/1-π) = -0.80279 -0.15234gender - 0.78301no_of_training + 1.37109awards_won + 0.38085avg_training_score
mh2 <- glm(data = K, formula = factor(KPIs_met_more_than_8N) ~ gender + no_of_trainings + awards_won + avg_training_score, family = binomial(link = "probit"))
levels(factor(KPIs_met_more_than_8N))
## [1] "N" "Y"
summary(mh2)
##
## Call:
## glm(formula = factor(KPIs_met_more_than_8N) ~ gender + no_of_trainings +
## awards_won + avg_training_score, family = binomial(link = "probit"),
## data = K)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -0.49623 0.02684 -18.487 < 2e-16 ***
## genderm -0.09359 0.02144 -4.365 1.27e-05 ***
## no_of_trainingsNhiều -0.47253 0.19841 -2.382 0.0172 *
## awards_wonY 0.84878 0.06571 12.917 < 2e-16 ***
## avg_training_scorecao 0.23224 0.02387 9.731 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 22738 on 17416 degrees of freedom
## Residual deviance: 22426 on 17412 degrees of freedom
## AIC: 22436
##
## Number of Fisher Scoring iterations: 4
# Câu lệnh tính e mũ cho các hệ số hồi quy mẫu trong mô hình
exp(mh2$coef)
## (Intercept) genderm no_of_trainingsNhiều
## 0.6088202 0.9106600 0.6234203
## awards_wonY avg_training_scorecao
## 2.3367976 1.2614227
BrierScore(mh2)
## [1] 0.225876
Mô hình tổng quát của probit:
probit(π) = Φ^(-1)(π) = β0 + β1X1 + β2X2 + ⋯ + βkXk
Sau khi chạy mô hình probit ta có hàm hồi quy sau:
probit(π) = Φ^(-1)(π) = -0.49623 - 0.09359gender - 0.47253no_of_training + 0.84878awards_won + 0.23224avg_training_score
mh3 <- glm(data = K, formula = factor(KPIs_met_more_than_8N) ~ gender + no_of_trainings + awards_won + avg_training_score, family = binomial(link = "cloglog"))
summary(mh3)
##
## Call:
## glm(formula = factor(KPIs_met_more_than_8N) ~ gender + no_of_trainings +
## awards_won + avg_training_score, family = binomial(link = "cloglog"),
## data = K)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -0.99552 0.03635 -27.387 < 2e-16 ***
## genderm -0.12008 0.02758 -4.353 1.34e-05 ***
## no_of_trainingsNhiều -0.65215 0.30200 -2.159 0.0308 *
## awards_wonY 0.95372 0.06488 14.700 < 2e-16 ***
## avg_training_scorecao 0.30912 0.03290 9.395 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 22738 on 17416 degrees of freedom
## Residual deviance: 22429 on 17412 degrees of freedom
## AIC: 22439
##
## Number of Fisher Scoring iterations: 5
# Câu lệnh tính e mũ cho các hệ số hồi quy mẫu trong mô hình
exp(mh3$coef)
## (Intercept) genderm no_of_trainingsNhiều
## 0.3695296 0.8868506 0.5209249
## awards_wonY avg_training_scorecao
## 2.5953363 1.3622206
BrierScore(mh3)
## [1] 0.2259142
Mô hình tổng quát của cloglog:
cloglog(π)=log(−log(1−π)) = β0 + β1X1 + β2X2 + ⋯ + βkXk
Sau khi chạy mô hình cloglog ta có hàm hồi quy sau:
cloglog(π)=log(−log(1−π)) = -0.99552 - 0.12008gender - 0.65215no_of_training + 0.95372awards_won + 0.30912avg_training_score
AIC (logit) = 22436
AIC (probit) = 22436
AIC (cloglog) = 22439
Mô hình logit và probit có AIC bằng 22436 nên ta chọn 2 mô hình này.
Deviance (logit) = 22426
Deviance (probit) = 22426
Deviance (cloglog) = 22429
Giá trị của Deviance càng nhỏ thì mô hình càng tốt. Trong 3 mô hình thì mô hình logit và mô hình probit tốt hơn mô hình cloglog.
BrierScore(logit) = 0.2258762
BrierScore(probit) = 0.225876
BrierScore(cloglog) = 0.2259142
Giá trị của Brier Score càng nhỏ nghĩa là chênh lệch giữa xác suất thực tế và xác suất tính từ mô hình càng nhỏ, nghĩa là mô hình càng tốt. Trong 3 mô hình thì mô hình probit là tốt nhất.
Phân tích thống kê mô tả của 2 biến phụ thuộc ở câu 2 với 5 biến còn lại trong câu 3, nhận xét về kết quả phân tích này
Ver <- data %>% mutate(education = case_when(education == "Bachelors" ~ 4, education == "Bachelors" ~ 4, education == "Below_Secondary" ~ 3, education == "Other" ~ 3))
Ver <-cut(Ver$education, breaks=c(0,3,4), labels=c('Dưới trình độ Cử nhân', 'Trình độ Cử nhân trở lên'))
table(Ver)
## Ver
## Dưới trình độ Cử nhân Trình độ Cử nhân trở lên
## 771 11519
e <- table(Ver,data$KPIs_met_more_than_8N)
e
##
## Ver N Y
## Dưới trình độ Cử nhân 560 211
## Trình độ Cử nhân trở lên 7396 4123
e1 <- prop.table(e)
e1
##
## Ver N Y
## Dưới trình độ Cử nhân 0.04556550 0.01716843
## Trình độ Cử nhân trở lên 0.60179007 0.33547600
Có 560 nhân viên không đạt KPIs dưới trình độ Cử nhân và 7396 nhân viên trên trình độ cử nhân.
Có 211 nhân viên đạt KPIs dưới trình độ Cử nhân và 4123 nhân viên trên trình độ cử nhân.
addmargins(e)
##
## Ver N Y Sum
## Dưới trình độ Cử nhân 560 211 771
## Trình độ Cử nhân trở lên 7396 4123 11519
## Sum 7956 4334 12290
barplot(e, beside = TRUE, legend.text = TRUE,
col = c("lavenderblush", "whitesmoke"),
xlab = "l", ylab = "Frequency",
main = "Frequency of education and KPIs_met_more_than_8N ")
riskratio(e)
## $data
##
## Ver N Y Total
## Dưới trình độ Cử nhân 560 211 771
## Trình độ Cử nhân trở lên 7396 4123 11519
## Total 7956 4334 12290
##
## $measure
## risk ratio with 95% C.I.
## Ver estimate lower upper
## Dưới trình độ Cử nhân 1.000000 NA NA
## Trình độ Cử nhân trở lên 1.307888 1.162819 1.471054
##
## $p.value
## two-sided
## Ver midp.exact fisher.exact chi.square
## Dưới trình độ Cử nhân NA NA NA
## Trình độ Cử nhân trở lên 1.414992e-06 1.598619e-06 2.130187e-06
##
## $correction
## [1] FALSE
##
## attr(,"method")
## [1] "Unconditional MLE & normal approximation (Wald) CI"
Tỷ lệ người không hoàn thành KPIs trên 80% và có trình độ Cử nhân trở lên cao hơn gấp 1.3 lần người không hoàn thành KPIs trên 80% và dưới trình độ Cử nhân.
riskratio(e, rev = 'c')
## $data
##
## Ver Y N Total
## Dưới trình độ Cử nhân 211 560 771
## Trình độ Cử nhân trở lên 4123 7396 11519
## Total 4334 7956 12290
##
## $measure
## risk ratio with 95% C.I.
## Ver estimate lower upper
## Dưới trình độ Cử nhân 1.0000000 NA NA
## Trình độ Cử nhân trở lên 0.8839923 0.8447373 0.9250715
##
## $p.value
## two-sided
## Ver midp.exact fisher.exact chi.square
## Dưới trình độ Cử nhân NA NA NA
## Trình độ Cử nhân trở lên 1.414992e-06 1.598619e-06 2.130187e-06
##
## $correction
## [1] FALSE
##
## attr(,"method")
## [1] "Unconditional MLE & normal approximation (Wald) CI"
OddsRatio(e)
## [1] 1.479524
Nhân viên không đạt KPIs trên 80% so với nhân viên đạt KPIs trên 80% dưới trình độ cử nhân gần bằng 1.5 nhân viên không đạt KPIs trên 80% so với nhân viên đạt KPIs trên 80% thuộc trình độ Cử nhân trở lên.
OddsRatio(e, rev = "r")
## [1] 1.479524
Kiểm định tính độc lập cho 2 biến (KPIs_met_more_than_8N) và (education)
Giả thuyết
H0: KPIs_met_more_than_8N và education độc lập
H1: KPIs_met_more_than_8N và education không độc lập
chisq.test(e)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: e
## X-squared = 22.106, df = 1, p-value = 2.58e-06
Kết quả kiểm định cho thấy p_value = 2.58e-06 < 5%. Do đó, KPIs của nhân viên (KPIs_met_more_than_8N) và trình độ học vấn (education) độc lập nhau.
g <- table(data$gender,data$KPIs_met_more_than_8N)
g
##
## N Y
## f 3117 1986
## m 8050 4264
g1 <- prop.table(g)
g1
##
## N Y
## f 0.1789631 0.1140265
## m 0.4621921 0.2448183
Có 3117 nhân viên không đạt KPIs là giới tính nam và 8050 là giới tính nữ.
Có 1986 nhân viên đạt KPIs là giới tính nam và 4264 là giới tính nữ.
addmargins(g)
##
## N Y Sum
## f 3117 1986 5103
## m 8050 4264 12314
## Sum 11167 6250 17417
barplot(g, beside = TRUE, legend.text = TRUE,
col = c("lavenderblush", "whitesmoke"),
xlab = "l", ylab = "Frequency",
main = "Frequency of gender and KPIs_met_more_than_8N ")
riskratio(g)
## $data
##
## N Y Total
## f 3117 1986 5103
## m 8050 4264 12314
## Total 11167 6250 17417
##
## $measure
## risk ratio with 95% C.I.
## estimate lower upper
## f 1.0000000 NA NA
## m 0.8897426 0.853082 0.9279786
##
## $p.value
## two-sided
## midp.exact fisher.exact chi.square
## f NA NA NA
## m 8.53312e-08 8.961127e-08 7.724906e-08
##
## $correction
## [1] FALSE
##
## attr(,"method")
## [1] "Unconditional MLE & normal approximation (Wald) CI"
Tỷ lệ người không hoàn thành KPIs trên 80% và có giới tính nữ cao hơn gấp 0.9 lần người không hoàn thành KPIs trên 80% là nam.
riskratio(g, rev = 'c')
## $data
##
## Y N Total
## f 1986 3117 5103
## m 4264 8050 12314
## Total 6250 11167 17417
##
## $measure
## risk ratio with 95% C.I.
## estimate lower upper
## f 1.000000 NA NA
## m 1.070251 1.043414 1.097777
##
## $p.value
## two-sided
## midp.exact fisher.exact chi.square
## f NA NA NA
## m 8.53312e-08 8.961127e-08 7.724906e-08
##
## $correction
## [1] FALSE
##
## attr(,"method")
## [1] "Unconditional MLE & normal approximation (Wald) CI"
OddsRatio(g)
## [1] 0.8313404
Nhân viên không đạt KPIs trên 80% so với nhân viên đạt KPIs trên 80% giới tính nữ gần bằng 0.83 nhân viên không đạt KPIs trên 80% so với nhân viên đạt KPIs trên 80% thuộc giới tính nam.
OddsRatio(g, rev = "r")
## [1] 0.8313404
Kiểm định tính độc lập cho 2 biến (KPIs_met_more_than_8N) và (gender)
Giả thuyết
H0: KPIs_met_more_than_8N và gender độc lập
H1: KPIs_met_more_than_8N và gender không độc lập
chisq.test(g)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: g
## X-squared = 28.688, df = 1, p-value = 8.504e-08
Kết quả kiểm định cho thấy p_value = 8.504e-08 < 5%. Do đó, KPIs của nhân viên (KPIs_met_more_than_8N) và giới tính (gender) có liên quan đến nhau.
Ver1 <- data %>% mutate(previous_year_rating = case_when(previous_year_rating == "0" ~ 3, previous_year_rating == "1" ~ 3, previous_year_rating == "2" ~ 3, previous_year_rating == "3" ~ 4, previous_year_rating == "4" ~ 4, previous_year_rating == "5" ~ 4))
Ver1 <-cut(Ver1$previous_year_rating, breaks=c(0,3,4), labels=c('Thấp', 'Cao'))
table(Ver1)
## Ver1
## Thấp Cao
## 60 162
p <- table(Ver1,data$KPIs_met_more_than_8N)
p
##
## Ver1 N Y
## Thấp 40 20
## Cao 92 70
p1 <- prop.table(p)
p1
##
## Ver1 N Y
## Thấp 0.18018018 0.09009009
## Cao 0.41441441 0.31531532
addmargins(p)
##
## Ver1 N Y Sum
## Thấp 40 20 60
## Cao 92 70 162
## Sum 132 90 222
barplot(p, beside = TRUE, legend.text = TRUE,
col = c("lavenderblush", "whitesmoke"),
xlab = "l", ylab = "Frequency",
main = "Frequency of previous_year_rating and KPIs_met_more_than_8N ")
riskratio(p)
## $data
##
## Ver1 N Y Total
## Thấp 40 20 60
## Cao 92 70 162
## Total 132 90 222
##
## $measure
## risk ratio with 95% C.I.
## Ver1 estimate lower upper
## Thấp 1.000000 NA NA
## Cao 1.296296 0.8697887 1.931945
##
## $p.value
## two-sided
## Ver1 midp.exact fisher.exact chi.square
## Thấp NA NA NA
## Cao 0.1869859 0.2188602 0.1831605
##
## $correction
## [1] FALSE
##
## attr(,"method")
## [1] "Unconditional MLE & normal approximation (Wald) CI"
OddsRatio(p)
## [1] 1.521739
OddsRatio(p, rev = "r")
## [1] 1.521739
Kiểm định tính độc lập cho 2 biến (KPIs_met_more_than_8N) và (previous_year_rating)
Giả thuyết
H0: KPIs_met_more_than_8N và previous_year_rating độc lập
H1: KPIs_met_more_than_8N và previous_year_rating không độc lập
chisq.test(p)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: p
## X-squared = 1.3858, df = 1, p-value = 0.2391
Kết quả kiểm định cho thấy p_value = 0.2391 > 5%. Do đó, KPIs của nhân viên (KPIs_met_more_than_8N) và điểm đánh giá của nhân viên năm trước đó (previous_year_rating) độc lập nhau.
Ver2 <- data %>% mutate(no_of_trainings = case_when(no_of_trainings == "1" ~ 3, no_of_trainings == "2" ~ 3, no_of_trainings == "3" ~ 3, no_of_trainings == "4" ~ 3, no_of_trainings == "5" ~ 4, no_of_trainings == "6" ~ 4, no_of_trainings == "7" ~ 4, no_of_trainings == "8" ~ 4, no_of_trainings == "9" ~ 4))
Ver2 <-cut(Ver2$no_of_trainings, breaks=c(0,3,4), labels=c('Ít', 'Nhiều'))
table(Ver2)
## Ver2
## Ít Nhiều
## 17365 52
n <- table(Ver2,data$KPIs_met_more_than_8N)
n
##
## Ver2 N Y
## Ít 11126 6239
## Nhiều 41 11
n1 <- prop.table(n)
n1
##
## Ver2 N Y
## Ít 0.6388011713 0.3582132399
## Nhiều 0.0023540219 0.0006315669
addmargins(n)
##
## Ver2 N Y Sum
## Ít 11126 6239 17365
## Nhiều 41 11 52
## Sum 11167 6250 17417
barplot(n, beside = TRUE, legend.text = TRUE,
col = c("lavenderblush", "whitesmoke"),
xlab = "l", ylab = "Frequency",
main = "Frequency of no_of_trainings and KPIs_met_more_than_8N ")
riskratio(n)
## $data
##
## Ver2 N Y Total
## Ít 11126 6239 17365
## Nhiều 41 11 52
## Total 11167 6250 17417
##
## $measure
## risk ratio with 95% C.I.
## Ver2 estimate lower upper
## Ít 1.0000000 NA NA
## Nhiều 0.5887747 0.3482534 0.995412
##
## $p.value
## two-sided
## Ver2 midp.exact fisher.exact chi.square
## Ít NA NA NA
## Nhiều 0.02342558 0.02919587 0.02656321
##
## $correction
## [1] FALSE
##
## attr(,"method")
## [1] "Unconditional MLE & normal approximation (Wald) CI"
OddsRatio(n)
## [1] 0.478446
OddsRatio(n, rev = "r")
## [1] 0.478446
Kiểm định tính độc lập cho 2 biến (KPIs_met_more_than_8N) và (no_of_trainings)
Giả thuyết
H0: KPIs_met_more_than_8N và no_of_trainings độc lập
H1: KPIs_met_more_than_8N và no_of_trainings không độc lập
chisq.test(n)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: n
## X-squared = 4.2978, df = 1, p-value = 0.03816
Kết quả kiểm định cho thấy p_value = 0.03816 < 5%. Do đó, KPIs của nhân viên (KPIs_met_more_than_8N) và số khóa học nhân viên đã tham gia (no_of_trainings) có liên quan đến nhau.
a <- table(data$awards_won,data$KPIs_met_more_than_8N)
a
##
## N Y
## N 11039 5971
## Y 128 279
a1 <- prop.table(a)
a1
##
## N Y
## N 0.633806052 0.342825975
## Y 0.007349142 0.016018832
addmargins(a)
##
## N Y Sum
## N 11039 5971 17010
## Y 128 279 407
## Sum 11167 6250 17417
barplot(a, beside = TRUE, legend.text = TRUE,
col = c("lavenderblush", "whitesmoke"),
xlab = "l", ylab = "Frequency",
main = "Frequency of awards_won and KPIs_met_more_than_8N ")
riskratio(a)
## $data
##
## N Y Total
## N 11039 5971 17010
## Y 128 279 407
## Total 11167 6250 17417
##
## $measure
## risk ratio with 95% C.I.
## estimate lower upper
## N 1.000000 NA NA
## Y 1.952842 1.822815 2.092144
##
## $p.value
## two-sided
## midp.exact fisher.exact chi.square
## N NA NA NA
## Y 0 1.261333e-41 6.121154e-44
##
## $correction
## [1] FALSE
##
## attr(,"method")
## [1] "Unconditional MLE & normal approximation (Wald) CI"
OddsRatio(a)
## [1] 4.029739
OddsRatio(a, rev = "r")
## [1] 4.029739
Kiểm định tính độc lập cho 2 biến (KPIs_met_more_than_8N) và (awards_won)
Giả thuyết
H0: KPIs_met_more_than_8N và awards_won độc lập
H1: KPIs_met_more_than_8N và awards_won không độc lập
chisq.test(a)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: a
## X-squared = 191.83, df = 1, p-value < 2.2e-16
Kết quả kiểm định cho thấy p_value = 2.2e-16 < 5%. Do đó, KPIs của nhân viên (KPIs_met_more_than_8N) và giải thương của nhân viên (awards_won) có liên quan với nhau.
s<-cut(data$avg_training_score, breaks=c(0,50,100), labels=c('thấp', 'cao'))
table(s)
## s
## thấp cao
## 3990 13427
t <- table(s,data$KPIs_met_more_than_8N)
t
##
## s N Y
## thấp 2835 1155
## cao 8332 5095
t1 <- prop.table(t)
t1
##
## s N Y
## thấp 0.16277200 0.06631452
## cao 0.47838319 0.29253029
addmargins(t)
##
## s N Y Sum
## thấp 2835 1155 3990
## cao 8332 5095 13427
## Sum 11167 6250 17417
barplot(t, beside = TRUE, legend.text = TRUE,
col = c("lavenderblush", "whitesmoke"),
xlab = "l", ylab = "Frequency",
main = "Frequency of avg_training_score and KPIs_met_more_than_8N ")
riskratio(t)
## $data
##
## s N Y Total
## thấp 2835 1155 3990
## cao 8332 5095 13427
## Total 11167 6250 17417
##
## $measure
## risk ratio with 95% C.I.
## s estimate lower upper
## thấp 1.000000 NA NA
## cao 1.310859 1.242935 1.382496
##
## $p.value
## two-sided
## s midp.exact fisher.exact chi.square
## thấp NA NA NA
## cao 0 6.821523e-26 2.361245e-25
##
## $correction
## [1] FALSE
##
## attr(,"method")
## [1] "Unconditional MLE & normal approximation (Wald) CI"
OddsRatio(t)
## [1] 1.500949
OddsRatio(t, rev = "r")
## [1] 1.500949
Kiểm định tính độc lập cho 2 biến (KPIs_met_more_than_8N) và (avg_training_score)
Giả thuyết
H0: KPIs_met_more_than_8N và avg_training_score độc lập
H1: KPIs_met_more_than_8N và avg_training_score không độc lập
chisq.test(t)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: t
## X-squared = 107.87, df = 1, p-value < 2.2e-16
Kết quả kiểm định cho thấy p_value = 2.2e-16 < 5%. Do đó, KPIs của nhân viên (KPIs_met_more_than_8N) và điểm trung bình của các khóa học đào tạo mà nhân viên đã tham gia (avg_training_score) có liên quan đến nhau.
Làm thống kê mô tả để phân tích cho ít nhất 5 biến (vừa định tính định lượng và có 2 biến đã chọn ở câu 2), nhận xét về kết quả phân tích này.
data.table(data)
## employee_id department region education gender
## 1: 8724 Technology region_26 Bachelors m
## 2: 74430 HR region_4 Bachelors f
## 3: 72255 Sales & Marketing region_13 Bachelors m
## 4: 38562 Procurement region_2 Bachelors f
## 5: 64486 Finance region_29 Bachelors m
## ---
## 17413: 64573 Technology region_7 Bachelors f
## 17414: 49584 HR region_7 Bachelors m
## 17415: 49584 HR region_7 Bachelors m
## 17416: 49584 HR region_7 Bachelors m
## 17417: 64573 HR region_7 Bachelors f
## recruitment_channel no_of_trainings age previous_year_rating
## 1: sourcing 1 24 0
## 2: other 1 31 3
## 3: other 1 31 1
## 4: other 3 31 2
## 5: sourcing 1 30 4
## ---
## 17413: referred 2 30 NA
## 17414: other 1 33 NA
## 17415: other 1 33 NA
## 17416: other 1 33 NA
## 17417: referred 1 35 NA
## length_of_service KPIs_met_more_than_8N awards_won avg_training_score
## 1: 1 Y N 77
## 2: 5 N N 51
## 3: 4 N N 47
## 4: 9 N N 65
## 5: 7 N N 61
## ---
## 17413: 6 Y N 81
## 17414: 9 N N 51
## 17415: 9 N N 51
## 17416: 9 N N 51
## 17417: 4 Y N 81
table(data$department)
##
## Analytics Finance HR Legal
## 1697 802 833 332
## Operations Procurement R&D Sales & Marketing
## 3524 2240 332 5458
## Technology
## 2199
table(data$department)/sum(table(data$department))
##
## Analytics Finance HR Legal
## 0.09743354 0.04604697 0.04782684 0.01906184
## Operations Procurement R&D Sales & Marketing
## 0.20233106 0.12860998 0.01906184 0.31337199
## Technology
## 0.12625596
# Biểu đồ cột dựa trên số lượng nhân viên theo phòng ban
department_plot <- ggplot(data = data, aes(x = department, fill = department))
department_plot + geom_bar(color = "mintcream", fill = "powderblue")
table(data$education)
##
## Bachelors Below Secondary Masters & above Other
## 11519 286 4841 771
table(data$education)/sum(table(data$education))
##
## Bachelors Below Secondary Masters & above Other
## 0.66136533 0.01642074 0.27794683 0.04426710
# Biểu đồ cột dựa trên số lượng nhân viên theo phòng ban
education_plot <- ggplot(data = data, aes(x = education, fill = education))
education_plot + geom_bar(color = "mintcream", fill = "powderblue")
table(data$gender)
##
## f m
## 5103 12314
table(data$gender)/sum(table(data$gender))
##
## f m
## 0.2929896 0.7070104
gender_plot <- ggplot(data = data, aes(x = gender, fill = gender))
gender_plot + geom_bar(color = "mintcream", fill = "powderblue")
table(data$previous_year_rating)
##
## 0 1 2 3 4 5
## 22 22 16 69 45 48
table(data$previous_year_rating)/sum(table(data$previous_year_rating))
##
## 0 1 2 3 4 5
## 0.09909910 0.09909910 0.07207207 0.31081081 0.20270270 0.21621622
pie(table(data$previous_year_rating), col = rainbow(5), main = "Biểu đồ điểm đánh giá của nhân viên trong năm trước đó")
table(data$no_of_trainings)
##
## 1 2 3 4 5 6 7 8 9
## 14061 2628 539 137 26 16 6 2 2
table(data$no_of_trainings)/sum(table(data$no_of_trainings))
##
## 1 2 3 4 5 6
## 0.8073146925 0.1508870644 0.0309467761 0.0078658782 0.0014927944 0.0009186427
## 7 8 9
## 0.0003444910 0.0001148303 0.0001148303
no_of_trainings_plot <- ggplot(data = data, aes(x = no_of_trainings, fill = no_of_trainings))
no_of_trainings_plot + geom_bar(color = "mintcream", fill = "powderblue")
table(data$KPIs_met_more_than_8N)
##
## N Y
## 11167 6250
table(data$KPIs_met_more_than_8N)/sum(table(data$KPIs_met_more_than_8N))
##
## N Y
## 0.6411552 0.3588448
KPIs_met_more_than_8N_plot <- ggplot(data = data, aes(x = KPIs_met_more_than_8N, fill = KPIs_met_more_than_8N))
KPIs_met_more_than_8N_plot + geom_bar(color = "mintcream", fill = "powderblue")
table(data$awards_won)
##
## N Y
## 17010 407
table(data$awards_won)/sum(table(data$awards_won))
##
## N Y
## 0.97663203 0.02336797
awards_won_plot <- ggplot(data = data, aes(x = awards_won, fill = awards_won))
awards_won_plot + geom_bar(color = "mintcream", fill = "powderblue")
table(data$avg_training_score)
##
## 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
## 1 3 7 12 46 123 245 381 595 831 856 890 775 593 405 307 278 290 465 589
## 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
## 663 658 573 461 318 251 170 163 219 277 335 370 294 223 179 128 129 170 215 293
## 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
## 329 399 405 396 402 407 332 286 210 132 100 61 28 27 21 23 18 21 21 8
## 99
## 10
table(data$avg_training_score)/sum(table(data$avg_training_score))
##
## 39 40 41 42 43 44
## 5.741517e-05 1.722455e-04 4.019062e-04 6.889820e-04 2.641098e-03 7.062066e-03
## 45 46 47 48 49 50
## 1.406672e-02 2.187518e-02 3.416203e-02 4.771201e-02 4.914738e-02 5.109950e-02
## 51 52 53 54 55 56
## 4.449676e-02 3.404720e-02 2.325314e-02 1.762646e-02 1.596142e-02 1.665040e-02
## 57 58 59 60 61 62
## 2.669805e-02 3.381753e-02 3.806626e-02 3.777918e-02 3.289889e-02 2.646839e-02
## 63 64 65 66 67 68
## 1.825802e-02 1.441121e-02 9.760579e-03 9.358673e-03 1.257392e-02 1.590400e-02
## 69 70 71 72 73 74
## 1.923408e-02 2.124361e-02 1.688006e-02 1.280358e-02 1.027732e-02 7.349142e-03
## 75 76 77 78 79 80
## 7.406557e-03 9.760579e-03 1.234426e-02 1.682264e-02 1.888959e-02 2.290865e-02
## 81 82 83 84 85 86
## 2.325314e-02 2.273641e-02 2.308090e-02 2.336797e-02 1.906184e-02 1.642074e-02
## 87 88 89 90 91 92
## 1.205719e-02 7.578802e-03 5.741517e-03 3.502325e-03 1.607625e-03 1.550210e-03
## 93 94 95 96 97 98
## 1.205719e-03 1.320549e-03 1.033473e-03 1.205719e-03 1.205719e-03 4.593214e-04
## 99
## 5.741517e-04
avg_training_score_plot <- ggplot(data = data, aes(x = avg_training_score, fill = avg_training_score))
avg_training_score_plot + geom_bar(color = "mintcream", fill = "powderblue")
Phân tích các yếu tố tác động đến mức độ hoàn thành KPIs của nhân viên
KPIs là các chỉ số quan trọng được sử dụng để đo lường hiệu suất và thành công trong công việc. Chúng thường được thiết lập dưới dạng mục tiêu cụ thể mà một nhân viên hoặc một tổ chức muốn đạt được. Việc đạt được KPIs quan trọng giúp đảm bảo rằng nhân viên hoặc tổ chức đang thực hiện công việc hiệu quả và đóng góp đáng kể vào mục tiêu tổng thể của họ.
Một cách thông thường để theo dõi việc đạt được KPIs là sử dụng biến KPIs_met_more_than_80, là một biến phụ thuộc (dependent variable) trong một mô hình. Biến này có hai giá trị “N” và “Y”. “Y” biểu thị rằng nhân viên đã đạt được KPI cao hơn 80%, trong khi “N” biểu thị rằng họ không đạt được KPIs đó.
Phân tích các yếu tố ảnh hưởng đến điểm trung bình các khóa học đào tạo nhân viên tham gia
Khóa học đào tạo là một phần quan trọng trong việc phát triển nhân viên và nâng cao năng lực công việc. Điểm trung bình của các khóa học đào tạo mà nhân viên đã tham gia là một chỉ số tổng quan về khả năng học tập và tiếp thu kiến thức mới của họ. Điểm số này phản ánh mức độ hiểu biết và thành thạo các kiến thức, kỹ năng và công nghệ mới mà nhân viên đã được đào tạo.
Tìm một dataset có dữ liệu định tính, dữ liệu định lượng, có trên 5 biến và nhiều hơn 150 quan sát.
Datasets được lấy từ website: https://www.kaggle.com/datasets/sanjanchaudhari/employees-performance-for-hr-analytics
Data có 13 biến với 17417 quan sát.
employee_id: Mã nhân viên.
department: Phòng ban.
region: Khu vực làm việc.
education: Trình độ học vấn.
gender: Giới tính.
recruitment_channel: Kênh được tuyển dụng.
no_of_trainings: Số lượng khóa học nhân viên đã tham gia.
age: Tuổi của nhân viên.
previous_year_rating: Điểm đánh giá của nhân viên trong năm trước đó.
length_of_service: Thời gian làm việc tính bằng số năm của nhân viên trong công ty.
KPIs_met_more_than_8N: Nhân viên có đạt KPIs (Key Performance Indicators) cao hơn 80% hay không ( Có: “Y”, Không “N”).
awards_won: Nhân viên có nhận giải thưởng trong công ty không ( Có: “Y”, Không “N”).
avg_training_score: Điểm trung bình của các khóa học đào tạo mà nhân viên đã tham gia.
# Datasets
data <- read.csv("D:/PTDLDT/BT.csv")
str(data)
## 'data.frame': 17417 obs. of 13 variables:
## $ employee_id : int 8724 74430 72255 38562 64486 46232 54542 67269 66174 76303 ...
## $ department : chr "Technology" "HR" "Sales & Marketing" "Procurement" ...
## $ region : chr "region_26" "region_4" "region_13" "region_2" ...
## $ education : chr "Bachelors" "Bachelors" "Bachelors" "Bachelors" ...
## $ gender : chr "m" "f" "m" "f" ...
## $ recruitment_channel : chr "sourcing" "other" "other" "other" ...
## $ no_of_trainings : int 1 1 1 3 1 1 1 2 1 1 ...
## $ age : int 24 31 31 31 30 36 33 36 51 29 ...
## $ previous_year_rating : int 0 3 1 2 4 3 5 3 4 5 ...
## $ length_of_service : int 1 5 4 9 7 2 3 3 11 2 ...
## $ KPIs_met_more_than_8N: chr "Y" "N" "N" "N" ...
## $ awards_won : chr "N" "N" "N" "N" ...
## $ avg_training_score : int 77 51 47 65 61 68 57 85 75 76 ...