require(tidyverse)## Loading required package: tidyverse
## -- Attaching packages ----------------------------------------------- tidyverse 1.2.1 --
## √ ggplot2 2.2.1 √ purrr 0.2.4
## √ tibble 1.3.4 √ dplyr 0.7.4
## √ tidyr 0.7.2 √ stringr 1.2.0
## √ readr 1.1.1 √ forcats 0.2.0
## -- Conflicts -------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
require(effects)## Loading required package: effects
## Loading required package: carData
## lattice theme set by effectsTheme()
## See ?effectsTheme for details.
require(corrplot)## Loading required package: corrplot
## corrplot 0.84 loaded
dta <- read.csv("D:/EDU MIS/project-research/new_dta20180314.csv",header = T)
str(dta)## 'data.frame': 1347 obs. of 29 variables:
## $ sub : int 1 2 3 5 5 6 7 8 9 10 ...
## $ 性別 : Factor w/ 2 levels "女","男": 1 2 2 2 2 2 1 1 1 1 ...
## $ 出生年 : int 1992 1990 1989 1987 1987 1987 1992 1993 1988 1984 ...
## $ 年齡 : int 27 29 30 32 32 32 27 26 31 35 ...
## $ 學歷 : Factor w/ 10 levels "二專","五專",..: 10 9 10 9 9 10 9 9 10 10 ...
## $ 公私立 : Factor w/ 3 levels "私立","國外學校",..: 3 1 3 1 1 3 3 3 3 3 ...
## $ 學群 : Factor w/ 18 levels "大眾傳播學群",..: 12 2 12 7 7 2 9 3 2 13 ...
## $ 學類 : Factor w/ 160 levels "13-經營與財務運作相關職類",..: 103 128 91 147 147 12 67 21 128 120 ...
## $ 大類 : Factor w/ 30 levels "11-主管職類",..: 11 29 11 5 5 5 3 11 28 23 ...
## $ 中類 : Factor w/ 124 levels "","/","11-1000 高階主管",..: 25 82 25 13 13 13 7 25 71 60 ...
## $ 小類 : Factor w/ 373 levels "","11-1011.00 執行長(Chief Executives)",..: 118 282 125 67 67 67 28 118 256 227 ...
## $ 地區 : Factor w/ 21 levels "台南市","宜蘭縣",..: 21 18 20 3 3 18 3 8 15 18 ...
## $ 就業性質 : Factor w/ 3 levels "自營者","受雇於公營機關",..: 2 2 3 3 3 3 3 2 3 2 ...
## $ 每週工時 : num 48 40 40 40 40 40 50 40 50 40 ...
## $ 現職年資 : num 2 1 1 3 3 5 1 3 5 8 ...
## $ 總年資 : int 2 3 2 4 4 6 1 3 5 8 ...
## $ 自評過量 : Factor w/ 3 levels "低於工作要求",..: 3 2 3 3 3 2 3 3 3 2 ...
## $ 自評需求 : int 5 5 4 4 4 4 4 4 4 2 ...
## $ 自評學用 : int 4 3 5 2 2 2 4 3 5 2 ...
## $ 工作滿意 : int 6 6 6 4 4 5 5 3 5 4 ...
## $ salary : int 20000 35000 25000 35000 35000 55000 35000 45000 65000 25000 ...
## $ 學歷級區 : int 5 4 5 4 4 5 4 4 5 5 ...
## $ 職業碼 : Factor w/ 373 levels "","11-1011.00",..: 118 282 125 67 67 67 28 118 256 227 ...
## $ 學類職業 : Factor w/ 867 levels "25-教育、訓練、圖書館相關職類25-3099.02",..: 502 702 438 804 804 10 320 49 695 640 ...
## $ 關聯編碼 : int 3 1 1 2 2 3 1 1 1 1 ...
## $ 工作級區 : int 4 2 4 4 4 4 4 4 2 3 ...
## $ 六大區域 : Factor w/ 6 levels "中彰投","北北基",..: 3 1 3 3 3 1 3 4 6 1 ...
## $ 學歷check : int 5 4 5 4 4 5 4 4 5 5 ...
## $ 自評過量check: int 1 0 1 1 1 0 1 1 1 0 ...
t <- dta[,c(2,4:8,9,12:19,21:23,25:27)]
t$級區差 <- t$學歷級區 - t$工作級區
t$自評過量 <- recode_factor(t$自評過量,
"1" = "符合工作要求",
"2" = "高於工作要求",
"3" = "低於工作要求")
t <- t %>% mutate( salary = as.numeric(salary),
年齡 = as.numeric(年齡))
str(t)## 'data.frame': 1347 obs. of 22 variables:
## $ 性別 : Factor w/ 2 levels "女","男": 1 2 2 2 2 2 1 1 1 1 ...
## $ 年齡 : num 27 29 30 32 32 32 27 26 31 35 ...
## $ 學歷 : Factor w/ 10 levels "二專","五專",..: 10 9 10 9 9 10 9 9 10 10 ...
## $ 公私立 : Factor w/ 3 levels "私立","國外學校",..: 3 1 3 1 1 3 3 3 3 3 ...
## $ 學群 : Factor w/ 18 levels "大眾傳播學群",..: 12 2 12 7 7 2 9 3 2 13 ...
## $ 學類 : Factor w/ 160 levels "13-經營與財務運作相關職類",..: 103 128 91 147 147 12 67 21 128 120 ...
## $ 大類 : Factor w/ 30 levels "11-主管職類",..: 11 29 11 5 5 5 3 11 28 23 ...
## $ 地區 : Factor w/ 21 levels "台南市","宜蘭縣",..: 21 18 20 3 3 18 3 8 15 18 ...
## $ 就業性質: Factor w/ 3 levels "自營者","受雇於公營機關",..: 2 2 3 3 3 3 3 2 3 2 ...
## $ 每週工時: num 48 40 40 40 40 40 50 40 50 40 ...
## $ 現職年資: num 2 1 1 3 3 5 1 3 5 8 ...
## $ 總年資 : int 2 3 2 4 4 6 1 3 5 8 ...
## $ 自評過量: Factor w/ 3 levels "符合工作要求",..: 1 2 1 1 1 2 1 1 1 2 ...
## $ 自評需求: int 5 5 4 4 4 4 4 4 4 2 ...
## $ 自評學用: int 4 3 5 2 2 2 4 3 5 2 ...
## $ salary : num 20000 35000 25000 35000 35000 55000 35000 45000 65000 25000 ...
## $ 學歷級區: int 5 4 5 4 4 5 4 4 5 5 ...
## $ 職業碼 : Factor w/ 373 levels "","11-1011.00",..: 118 282 125 67 67 67 28 118 256 227 ...
## $ 關聯編碼: int 3 1 1 2 2 3 1 1 1 1 ...
## $ 工作級區: int 4 2 4 4 4 4 4 4 2 3 ...
## $ 六大區域: Factor w/ 6 levels "中彰投","北北基",..: 3 1 3 3 3 1 3 4 6 1 ...
## $ 級區差 : int 1 2 1 0 0 1 0 0 3 2 ...
# 級區差
ggplot(t, aes(x = 級區差))+
geom_bar()+
geom_text(stat = "count", aes(label = ..count.., y = ..count.. , vjust = -.75))+
scale_x_continuous(limits=c(-5,5), breaks=seq(-5,5, by = 1))+
labs(x = "客評過量")+
theme_bw()## Warning: Removed 139 rows containing non-finite values (stat_count).
## Warning: Removed 139 rows containing non-finite values (stat_count).
# scatter plot
t1 <- t[,c(2,6:8,13)]
pairs(t1, pch = '.', upper.panel = panel.smooth, lower.panel = NULL)# another way: corrplot(cor(t1), method = 'ellipse', order = 'hclust', addrect = 4, type = 'upper', tl.pos = 'tp')
# corrplot(cor(t1), add = TRUE, type = 'lower', method = 'number', order = 'hclust', col = 'black', diag = FALSE, tl.pos = 'n', cl.pos = 'n')
t2 <- t[,c(10:16,18)]
pairs(t2, pch = '.', upper.panel = panel.smooth, lower.panel = NULL)女生,私立,中彰投,自評符合工作要求 為對照組
lm0 <- lm(salary ~ 性別 + 年齡 +公私立 +六大區域 , data = t)
summary(lm0)##
## Call:
## lm(formula = salary ~ 性別 + 年齡 + 公私立 + 六大區域, data = t)
##
## Residuals:
## Min 1Q Median 3Q Max
## -59570 -11724 -3029 6358 260288
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2846.63 3569.64 -0.797 0.42533
## 性別男 10007.48 1361.49 7.350 3.43e-13 ***
## 年齡 1164.73 97.92 11.895 < 2e-16 ***
## 公私立國外學校 24211.17 6030.99 4.014 6.29e-05 ***
## 公私立國立(公立) 8780.95 1381.60 6.356 2.84e-10 ***
## 六大區域北北基 11110.95 4257.96 2.609 0.00917 **
## 六大區域宜花東離島 2370.07 1584.96 1.495 0.13506
## 六大區域桃竹苗 1321.45 2331.84 0.567 0.57101
## 六大區域高高屏 6507.86 4019.25 1.619 0.10565
## 六大區域雲嘉南 16904.93 2783.63 6.073 1.63e-09 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 24420 on 1337 degrees of freedom
## Multiple R-squared: 0.1917, Adjusted R-squared: 0.1863
## F-statistic: 35.24 on 9 and 1337 DF, p-value: < 2.2e-16
plot(allEffects(lm0))lm1 <- lm(salary ~ 性別 + 年齡 +公私立 +六大區域 +關聯編碼 +級區差 , data = t)
summary(lm1)##
## Call:
## lm(formula = salary ~ 性別 + 年齡 + 公私立 + 六大區域 + 關聯編碼 +
## 級區差, data = t)
##
## Residuals:
## Min 1Q Median 3Q Max
## -60142 -11356 -3080 6839 253575
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -8856.7 4301.7 -2.059 0.0397 *
## 性別男 10153.3 1465.6 6.928 6.98e-12 ***
## 年齡 1181.1 107.2 11.019 < 2e-16 ***
## 公私立國外學校 28341.7 6537.7 4.335 1.58e-05 ***
## 公私立國立(公立) 8260.5 1497.4 5.516 4.24e-08 ***
## 六大區域北北基 12151.9 4595.9 2.644 0.0083 **
## 六大區域宜花東離島 2633.3 1714.6 1.536 0.1248
## 六大區域桃竹苗 1371.9 2490.6 0.551 0.5818
## 六大區域高高屏 6310.7 4208.3 1.500 0.1340
## 六大區域雲嘉南 18711.9 3013.8 6.209 7.35e-10 ***
## 關聯編碼 3917.6 889.7 4.403 1.16e-05 ***
## 級區差 -512.1 748.4 -0.684 0.4940
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 24820 on 1196 degrees of freedom
## (139 observations deleted due to missingness)
## Multiple R-squared: 0.2009, Adjusted R-squared: 0.1935
## F-statistic: 27.33 on 11 and 1196 DF, p-value: < 2.2e-16
plot(allEffects(lm1)[1:2],rows=2,cols=1)plot(allEffects(lm1)[3:4],rows=2,cols=1)plot(allEffects(lm1)[5:6],rows=2,cols=1)lm2 <- lm(salary ~ 性別 + 年齡 +公私立 +六大區域 +自評學用 +自評過量 , data = t)
summary(lm2)##
## Call:
## lm(formula = salary ~ 性別 + 年齡 + 公私立 + 六大區域 + 自評學用 +
## 自評過量, data = t)
##
## Residuals:
## Min 1Q Median 3Q Max
## -60532 -11121 -2997 6299 256182
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -8134.80 4051.06 -2.008 0.044838 *
## 性別男 11039.12 1350.02 8.177 6.71e-16 ***
## 年齡 1157.26 96.41 12.003 < 2e-16 ***
## 公私立國外學校 27166.56 5965.91 4.554 5.75e-06 ***
## 公私立國立(公立) 7719.64 1385.11 5.573 3.02e-08 ***
## 六大區域北北基 11106.67 4191.25 2.650 0.008145 **
## 六大區域宜花東離島 2083.44 1560.71 1.335 0.182126
## 六大區域桃竹苗 1311.46 2293.59 0.572 0.567556
## 六大區域高高屏 5986.95 3953.47 1.514 0.130173
## 六大區域雲嘉南 17138.54 2737.77 6.260 5.18e-10 ***
## 自評學用 2400.10 561.73 4.273 2.07e-05 ***
## 自評過量高於工作要求 -6208.07 1776.93 -3.494 0.000492 ***
## 自評過量低於工作要求 -6345.99 2262.29 -2.805 0.005103 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 24000 on 1334 degrees of freedom
## Multiple R-squared: 0.2207, Adjusted R-squared: 0.2137
## F-statistic: 31.49 on 12 and 1334 DF, p-value: < 2.2e-16
plot(allEffects(lm2)[1:2],rows=2,cols=1)plot(allEffects(lm2)[3:4],rows=2,cols=1)plot(allEffects(lm2)[5:6],rows=2,cols=1)lm3 <- lm(salary ~ 性別 + 年齡 +公私立 +六大區域 +自評學用 +自評過量 +關聯編碼 +級區差, data = t)
summary(lm3)##
## Call:
## lm(formula = salary ~ 性別 + 年齡 + 公私立 + 六大區域 + 自評學用 +
## 自評過量 + 關聯編碼 + 級區差, data = t)
##
## Residuals:
## Min 1Q Median 3Q Max
## -57921 -11090 -3194 6307 251363
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -11742.0 4680.0 -2.509 0.01224 *
## 性別男 10980.2 1459.7 7.522 1.06e-13 ***
## 年齡 1167.4 106.2 10.996 < 2e-16 ***
## 公私立國外學校 30011.8 6492.1 4.623 4.20e-06 ***
## 公私立國立(公立) 7386.5 1508.5 4.897 1.11e-06 ***
## 六大區域北北基 12255.4 4552.6 2.692 0.00720 **
## 六大區域宜花東離島 2392.7 1698.5 1.409 0.15917
## 六大區域桃竹苗 1336.3 2464.0 0.542 0.58770
## 六大區域高高屏 5845.5 4163.6 1.404 0.16059
## 六大區域雲嘉南 18541.9 2980.9 6.220 6.86e-10 ***
## 自評學用 2024.7 641.1 3.158 0.00163 **
## 自評過量高於工作要求 -5502.7 1943.7 -2.831 0.00472 **
## 自評過量低於工作要求 -6526.2 2428.4 -2.687 0.00730 **
## 關聯編碼 2782.7 917.8 3.032 0.00248 **
## 級區差 156.7 752.6 0.208 0.83509
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 24540 on 1193 degrees of freedom
## (139 observations deleted due to missingness)
## Multiple R-squared: 0.2206, Adjusted R-squared: 0.2115
## F-statistic: 24.12 on 14 and 1193 DF, p-value: < 2.2e-16
plot(allEffects(lm3),4)plot(allEffects(lm3),5)plot(allEffects(lm3),6)plot(allEffects(lm3),7)plot(allEffects(lm3),8)不同學歷對薪資有顯著,但級區差卻沒有
lm <- lm(salary ~ 性別 + 年齡, data = t)
add1(lm,scope = ~ 性別+年齡+公私立+六大區域+學群+就業性質+每週工時+現職年資+
總年資+自評過量+自評需求+自評學用+學歷級區+關聯編碼+級區差, test = "F" )## Warning in add1.lm(lm, scope = ~性別 + 年齡 + 公私立 + 六大區域 + 學群 + :
## using the 1204/1347 rows from a combined fit
## Single term additions
##
## Model:
## salary ~ 性別 + 年齡
## Df Sum of Sq RSS AIC F value Pr(>F)
## <none> 8.0873e+11 24478
## 公私立 2 3.1712e+10 7.7702e+11 24434 27.3852 2.203e-12 ***
## 六大區域 5 3.0509e+10 7.7822e+11 24441 10.4986 6.679e-10 ***
## 學群 17 2.0476e+10 7.8826e+11 24481 2.0277 0.0078582 **
## 就業性質 2 2.7928e+09 8.0594e+11 24478 2.3252 0.0981557 .
## 每週工時 1 8.4416e+09 8.0029e+11 24467 14.1662 0.0001746 ***
## 現職年資 1 2.7394e+09 8.0599e+11 24476 4.5646 0.0328200 *
## 總年資 1 4.2022e+09 8.0453e+11 24473 7.0148 0.0081788 **
## 自評過量 2 1.5718e+10 7.9301e+11 24458 13.2997 1.908e-06 ***
## 自評需求 1 5.1740e+10 7.5699e+11 24400 91.7941 < 2.2e-16 ***
## 自評學用 1 2.2761e+10 7.8597e+11 24445 38.8924 5.987e-10 ***
## 學歷級區 1 6.1012e+10 7.4772e+11 24385 109.5853 < 2.2e-16 ***
## 關聯編碼 1 1.4675e+10 7.9406e+11 24458 24.8193 7.115e-07 ***
## 級區差 1 4.7423e+08 8.0826e+11 24479 0.7880 0.3748695
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1