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(MASS)
## Loading required package: MASS
## 
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
## 
##     select

data

將級區差區分為過量(over);符合(match);限縮(under)

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 ...
t4 <- dta[,c(1:7,12:19,21,22,25:27)]
t4$級區差 <- t4$學歷級區 - t4$工作級區
t4$自評過量 <- recode_factor(t4$自評過量,
                        "1" = "符合工作要求",
                        "2" = "高於工作要求",
                        "3" = "低於工作要求")

# 使用區差區分垂直相符程度
unique(t4$級區差)
## [1]  1  2  0  3 NA -1  4 -2
t4$垂直相符 <- ifelse(t4$級區差==0 , "match" ,
                 ifelse(t4$級區差 < 0 , "under" , 
                        ifelse(t4$級區差 > 0 , "over", NA)))


t4 <- t4 %>% mutate( salary = as.numeric(salary), 
                     年齡 = as.numeric(年齡),
                     垂直相符 = as.factor(垂直相符)) 
str(t4)
## 'data.frame':    1347 obs. of  22 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 ...
##  $ 年齡    : 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/ 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 ...
##  $ 關聯編碼: 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 ...
##  $ 垂直相符: Factor w/ 3 levels "match","over",..: 2 2 2 1 1 2 1 1 2 2 ...

plot

#
t4_s <- as.data.frame(with(t4, prop.table(table(salary, 垂直相符), 2)))

#
ggplot(t4_s, aes(x = salary, y = Freq, group = 垂直相符, color = 垂直相符)) + 
  geom_point() +
  geom_line()+
  labs(x = "薪資", y = "Frequency of response") +
  theme_bw() + 
  theme(axis.text.x = element_text(hjust = 1, angle =30))

model

model1 垂直相符

投入變項: 性別 + 年齡 +公私立 +六大區域(中彰投為對照) +垂直相符(match為對照組)

lm1 <- lm(salary ~ 性別 + 年齡 +公私立 +六大區域 +垂直相符, data = t4)
summary(lm1)
## 
## Call:
## lm(formula = salary ~ 性別 + 年齡 + 公私立 + 六大區域 + 垂直相符, 
##     data = t4)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -60392 -11798  -3307   6144 259410 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)         -1667.2     3963.3  -0.421  0.67409    
## 性別男              10060.7     1479.4   6.801 1.64e-11 ***
## 年齡                 1150.0      108.3  10.620  < 2e-16 ***
## 公私立國外學校      27034.8     6595.1   4.099 4.43e-05 ***
## 公私立國立(公立)   8604.0     1520.1   5.660 1.89e-08 ***
## 六大區域北北基      12303.3     4639.3   2.652  0.00811 ** 
## 六大區域宜花東離島   2566.1     1734.8   1.479  0.13936    
## 六大區域桃竹苗       1538.2     2517.0   0.611  0.54124    
## 六大區域高高屏       6726.4     4247.7   1.584  0.11357    
## 六大區域雲嘉南      18447.7     3053.0   6.042 2.02e-09 ***
## 垂直相符over        -1095.9     1579.8  -0.694  0.48799    
## 垂直相符under        -941.7     3285.9  -0.287  0.77448    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 25050 on 1196 degrees of freedom
##   (139 observations deleted due to missingness)
## Multiple R-squared:  0.1856, Adjusted R-squared:  0.1781 
## F-statistic: 24.78 on 11 and 1196 DF,  p-value: < 2.2e-16
plot(allEffects(lm1),5)

model2 垂直+關聯

投入變項: 性別 + 年齡 +公私立 +六大區域 +關聯編碼(中彰投為對照) +垂直相符(match為對照組)

lm2 <- lm(salary ~ 性別 + 年齡 +公私立 +六大區域 +關聯編碼 +垂直相符, data = t4)
summary(lm2)
## 
## Call:
## lm(formula = salary ~ 性別 + 年齡 + 公私立 + 六大區域 + 關聯編碼 + 
##     垂直相符, data = t4)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -58444 -11417  -3114   6618 252745 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)         -9818.0     4288.4  -2.289  0.02223 *  
## 性別男              10072.7     1466.3   6.869 1.03e-11 ***
## 年齡                 1185.3      107.6  11.017  < 2e-16 ***
## 公私立國外學校      28145.6     6541.0   4.303 1.82e-05 ***
## 公私立國立(公立)   8107.8     1510.3   5.368 9.54e-08 ***
## 六大區域北北基      12198.6     4598.3   2.653  0.00809 ** 
## 六大區域宜花東離島   2522.3     1719.5   1.467  0.14267    
## 六大區域桃竹苗       1258.8     2495.4   0.504  0.61406    
## 六大區域高高屏       6236.7     4211.4   1.481  0.13889    
## 六大區域雲嘉南      18425.4     3026.0   6.089 1.53e-09 ***
## 關聯編碼             4140.0      873.8   4.738 2.42e-06 ***
## 垂直相符over          452.3     1599.5   0.283  0.77738    
## 垂直相符under        -230.4     3260.3  -0.071  0.94367    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 24830 on 1195 degrees of freedom
##   (139 observations deleted due to missingness)
## Multiple R-squared:  0.2006, Adjusted R-squared:  0.1926 
## F-statistic:    25 on 12 and 1195 DF,  p-value: < 2.2e-16
plot(allEffects(lm2)[5:6])