目錄

chapter 1. 資料介紹與研究目的

chapter 2. 變數資料視覺化

chapter 3. 選取變數

chapter 4. 初步迴歸模型

chapter 5. 模型診斷

chapter 6. 模型配飾與預測

chapter 7. 結論

chapter 1. 資料介紹與研究目的

報告研究者

統計碩一 李其軒

報告方式以及軟體

書面報告加上R軟體呈現,

淺框框為程式碼

當中若出現“##”表示程式跑出來的結果

報告主題

影響國人綜合所得總額因素

研究動機與目標

了解現階段台灣東部民眾對於影響綜合所得總額的因素,並加以瞭解此些因素背後的統計意涵以及變數關係,利用迴歸分析的結果加上統計模型診斷,了解變數之間的關聯性。最後對政府或民眾提供有效的數據,並改進所得總額影響因素。

研究時間與作業時間

2021/12/22~2022/1/14

檔案名稱

104年內政大數據資料應用組競賽用資料集_村里.csv

樣本數

花蓮縣以及台東縣 共29個鄉鎮,“大武鄉”、“太麻里鄉”、“玉里鎮”、“光復鄉”、“吉安鄉”、“成功鎮”、“池上鄉”、“秀林鄉”、“卑南鄉”、“卓溪鄉”、“延平鄉”、“東河鄉”、“花蓮市”、“金峰鄉”、“長濱鄉”、“海端鄉”、“鹿野鄉”、“富里鄉”、“新城鄉”、“瑞穗鄉”、“萬榮鄉”、“達仁鄉”、“壽豐鄉”、“綠島鄉”、“臺東市”、“鳳林鎮”、“豐濱鄉”、“關山鎮”、“蘭嶼鄉”。

以鄰里劃分鄰里樣本加總共324個樣本

選擇變數

Y(response variable): 綜合所得總額

X1:扶老比

X2:15歲以上有偶人口數

X3:共同事業戶數

X4:薪資淨所得

X5:各類所得金額薪資所得

X6:綜合所得稅各類所得納稅單位

X7:各類所得金額營利所得

X8:各類所得金額執行業務所得

X9:各類所得金額其他所得

X10:單獨生活戶數

getwd()
## [1] "C:/Users/jessie/Downloads"
setwd("C:/Users/jessie/Downloads")
data <- read.csv("104年內政大數據資料應用組競賽用資料集_村里.csv",header = TRUE)
data <- data[-1,]
dim(data) # 7851,182
## [1] 7851  182

完整資料具有7851筆樣本,涵蓋整個台灣以及離島的鄰里,加上182個變數,最終我們從資料中選取10個應變數(independent variables)與1個自變數(response variable/dependent variable)

接著我們選取台灣資料中選取東部包含花蓮縣與台東縣鄰里

library(dplyr)
## Warning: package 'dplyr' was built under R version 4.1.3
## 
## 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
east <- data %>% 
  filter(COUNTY == "臺東縣" | COUNTY == "花蓮縣" )
# east
dim(east)
## [1] 324 182

選取後我們用dim()函數看出東部資料具有324筆樣本 ,接著選取10個應變數以及一個自變數

data <- data.frame(county = east$COUNTY,
                   town = east$TOWN,
                  income = east$COLUMN136,
                   old = east$COLUMN10,
                   pair = east$COLUMN49,
                   career_pair = east$COLUMN106,
                   wage = east$COLUMN157,
                   wage_income = east$COLUMN147,
                   tax = east$COLUMN143,
                   profit = east$COLUMN145,
                   business = east$COLUMN146,
                   other = east$COLUMN154,
                   single = east$COLUMN107)
#data
str(data)
## 'data.frame':    324 obs. of  13 variables:
##  $ county     : chr  "臺東縣" "臺東縣" "臺東縣" "臺東縣" ...
##  $ town       : chr  "臺東市" "臺東市" "臺東市" "臺東市" ...
##  $ income     : chr  "136489" "108809" "439269" "477953" ...
##  $ old        : chr  "23.45" "21.82" "16.34" "18.43" ...
##  $ pair       : chr  "679" "422" "932" "1190" ...
##  $ career_pair: chr  "0" "0" "1" "0" ...
##  $ wage       : chr  "81247" "77463" "288561" "330096" ...
##  $ wage_income: chr  "110955" "101603" "365943" "422817" ...
##  $ tax        : chr  "222" "163" "536" "651" ...
##  $ profit     : chr  "1264" "768" "7874" "4515" ...
##  $ business   : chr  "2059" "130" "10862" "2407" ...
##  $ other      : chr  "582" "287" "1974" "1723" ...
##  $ single     : chr  "256" "133" "465" "376" ...

這是我們要分析的資料,還有資料結構

data$income <- as.numeric(data$income)
data$old <- as.numeric(data$old)
data$pair <- as.numeric(data$pair)
data$career_pair <- as.numeric(data$career_pair)
data$wage <- as.numeric(data$wage)
data$wage_income <- as.numeric(data$wage_income)
data$tax <- as.numeric(data$tax)
data$profit <- as.numeric(data$profit)
data$business <- as.numeric(data$business)
data$other <- as.numeric(data$other)
data$single <- as.numeric(data$single)

看一下分析變數的全距

matrix <- matrix(0,ncol = 3,nrow = 11)
for(i in 3:ncol(data)){
   matrix[i-2,1] <- names(data)[i]
   matrix[i-2,2] <- range(data[,i])[1]
   matrix[i-2,3] <- range(data[,i])[2]
}
matrix
##       [,1]          [,2]   [,3]     
##  [1,] "income"      "6390" "2055601"
##  [2,] "old"         "7.39" "70.69"  
##  [3,] "pair"        "16"   "3876"   
##  [4,] "career_pair" "0"    "3"      
##  [5,] "wage"        "3642" "1360835"
##  [6,] "wage_income" "4923" "1717913"
##  [7,] "tax"         "12"   "2492"   
##  [8,] "profit"      "0"    "20192"  
##  [9,] "business"    "0"    "47142"  
## [10,] "other"       "2"    "13116"  
## [11,] "single"      "14"   "1126"
range <- as.data.frame(matrix)
colnames(range) <- c("names","min","max")
range
##          names  min     max
## 1       income 6390 2055601
## 2          old 7.39   70.69
## 3         pair   16    3876
## 4  career_pair    0       3
## 5         wage 3642 1360835
## 6  wage_income 4923 1717913
## 7          tax   12    2492
## 8       profit    0   20192
## 9     business    0   47142
## 10       other    2   13116
## 11      single   14    1126

chapter 2. 變數資料視覺化

接著進行資料視覺化,首先先觀察應變數的資料視覺化

library(ggplot2)
p <- ggplot(data, aes(income))

應變數的機率密布圖,很顯然大部分所得收入落在0-500,000元之間,

所得為年所得

ggplot(data, aes(y = income)) +
  geom_boxplot() +     
  scale_x_discrete() + 
  ylab("年總所得") + 
  ggtitle("花東年所得盒鬚圖")

利用盒鬚圖進行應變樹資料視覺化也可看出總所得分布狀況大部分落在0-500,000

summary(data$income)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    6390   83145  136404  268755  271121 2055601

透過需要分析的資料以及變數繪製summary graph 進行分析(chapter1-6)

plot(data[3:ncol(data)])

值得注意的地方是其中自變數有些會出現相關性特別高的圖形

利用相關係數矩陣可以發現有些相關係數接近1可以懷疑這些變數中有些會出現共線性,以下文章會進行模型判斷是否出現共線性

round(cor(data[3:ncol(data)]),4)
##              income     old    pair career_pair    wage wage_income     tax
## income       1.0000 -0.3303  0.9699      0.1081  0.9968      0.9970  0.9905
## old         -0.3303  1.0000 -0.3030      0.0427 -0.3382     -0.3420 -0.3361
## pair         0.9699 -0.3030  1.0000      0.0765  0.9693      0.9737  0.9837
## career_pair  0.1081  0.0427  0.0765      1.0000  0.1099      0.1059  0.0870
## wage         0.9968 -0.3382  0.9693      0.1099  1.0000      0.9996  0.9862
## wage_income  0.9970 -0.3420  0.9737      0.1059  0.9996      1.0000  0.9900
## tax          0.9905 -0.3361  0.9837      0.0870  0.9862      0.9900  1.0000
## profit       0.8704 -0.2603  0.8409      0.1496  0.8633      0.8614  0.8540
## business     0.8787 -0.2313  0.8163      0.0343  0.8601      0.8579  0.8573
## other        0.9222 -0.2645  0.8986      0.1310  0.9138      0.9146  0.9196
## single       0.9125 -0.2463  0.9410      0.1107  0.9069      0.9123  0.9310
##              profit business   other  single
## income       0.8704   0.8787  0.9222  0.9125
## old         -0.2603  -0.2313 -0.2645 -0.2463
## pair         0.8409   0.8163  0.8986  0.9410
## career_pair  0.1496   0.0343  0.1310  0.1107
## wage         0.8633   0.8601  0.9138  0.9069
## wage_income  0.8614   0.8579  0.9146  0.9123
## tax          0.8540   0.8573  0.9196  0.9310
## profit       1.0000   0.8085  0.8193  0.7876
## business     0.8085   1.0000  0.8317  0.7930
## other        0.8193   0.8317  1.0000  0.8430
## single       0.7876   0.7930  0.8430  1.0000

chapter 3. 選取變數

變數 程式名稱 中文定義
Y “income” 綜合所得總額
X1 “old” 扶老比
X2 “pair” 15歲以上有偶人口數
X3 “career_pair” 共同事業戶數
X4 “wage” 薪資淨所得
X5 “wage_income” 各類所得金額薪資所得
X6 “tax” 綜合所得稅各類所得納稅單位
X7 “profit” 各類所得金額營利所得
X8 “business” 各類所得金額執行業務所得
X9 “other” 各類所得金額其他所得
X10 “single” 單獨生活戶數

但複迴歸模型是由簡單迴歸的方式增加變數的方式堆積而成

我們可以利用added - variable plot進行

added-variable plot(或稱marginal plots) 可以看到independent variable之間的相關性,可以從ols線看出變數間的相關性,若ols斜率為正(負)的,推測進行複迴歸模型參數估計為正(負)的

他可以視為做多次的簡單線性迴歸,也可看出變數之間的相關性

首先先看independent variable中的

  1. income總所得 vs. old扶養比(左上)

income與old有著同向相關性,因為OLS的線性迴歸線(藍色)斜率為正的 ,但彼此相關性不太高

  1. income總所得 vs. pair 15歲以上有偶人口數(右上)

income與pair有著同向相關性,因為OLS的線性迴歸線(藍色)斜率為正的 ,但彼此相關性不太高

  1. income總所得 vs. career_pair 共同事業戶數(左下)

從圖中可以看出 income與career_pair 的相關性不太高,因為OLS的線性迴歸線(藍色)呈現近似水平線 ,彼此相關性不太高

4.income總所得 vs. wage 薪資淨所得(右下)

在added-variable plot中可以看出income 與 wage具有蠻強的相關性, 彼此變數具有高度正相關,推測當薪資淨所得上升(下降)則總所得會跟著上升(下降) 透過OLS 線性迴歸線也能看出幾乎所有的點都剛好落在OLS線中

  1. income 總所得 vs. wage_income各類所得金額薪資所得(圖 左上)

從圖中可以看出income 與 各類所得金額薪資所得有著很強的相關性,且具有正相關(ols) 意即 總所得上升(下降)則 各類所得金額薪資所得上升(下降)

6.income總所得 vs. tax綜合所得稅各類所得納稅單位

總所得與綜合所得稅各類所得納稅單位有著正向關係,當綜合所得稅各類所得納稅單位上升(下降)則總所得上升(下降)

  1. income 總所得 vs.profit各類所得金額營利所得

總所得與各類所得金額營利所得具有正向相關,但相關性不高

  1. income 總所得 vs. business各類所得金額執行業務所得

總所得與各類所得金額執行業務所得具有正向相關性,但business大多數的點落在特定範圍,所以做ols精確性不高

  1. income 總所得 vs. other 各類所得金額其他所得

總所得與各類所得金額其他所得具有正向相關性,但other也有特定範圍

  1. income 總所得 vs. single單獨生活戶數

總所得與單獨生活戶數具有負向相關性

m3 <- lm(income ~ old + pair + career_pair + wage, data)
avPlots(m3, id=FALSE)

added-variable plot (income vs. pair vs. career_pair vs. wage)(上圖)

added-variable plot (income vs. wage_income vs. tax vs. profit vs. business vs. other vs. single)(下圖)

library(alr4)
m3 <- lm(income ~ wage_income + tax + profit + business + other + single, data)
avPlots(m3, id=FALSE)

chapter 4. 初步複迴歸分析模型

range[4] <- c("response variable",rep("predictor variables",times = 10))
colnames(range) <- c("names","min","max","variables")
range
##          names  min     max           variables
## 1       income 6390 2055601   response variable
## 2          old 7.39   70.69 predictor variables
## 3         pair   16    3876 predictor variables
## 4  career_pair    0       3 predictor variables
## 5         wage 3642 1360835 predictor variables
## 6  wage_income 4923 1717913 predictor variables
## 7          tax   12    2492 predictor variables
## 8       profit    0   20192 predictor variables
## 9     business    0   47142 predictor variables
## 10       other    2   13116 predictor variables
## 11      single   14    1126 predictor variables

從predictor variables中可以看出wage 跟 wage_income的資料全距非常大 ,初步模型中可以取logarithm transformations進行轉換,

再者,我認為wage(薪資淨所得)以及career_pair(共同事業戶數)兩者中應該有互相影響

共同事業戶數定義為:在同一處所同一主管人之下經營共同事業之工廠、商店、寺廟、機關、學校或其他公私場所。一人的薪資所得來源可能不是單一個

薪資淨所得以及共同事業戶數懷疑有交互作用,初步進行配飾 模型

lm_income <- lm(income ~ old + pair + career_pair + log(wage) + log(wage_income) + 
                  tax + profit + business + other + single + pair*career_pair,data = data)
summary(lm_income)
## 
## Call:
## lm(formula = income ~ old + pair + career_pair + log(wage) + 
##     log(wage_income) + tax + profit + business + other + single + 
##     pair * career_pair, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -161378  -13945    -554   11146  196027 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)       4.379e+05  6.783e+04   6.456 4.11e-10 ***
## old              -4.480e+02  2.792e+02  -1.605  0.10960    
## pair              2.123e+01  2.170e+01   0.978  0.32872    
## career_pair      -1.503e+04  1.205e+04  -1.247  0.21334    
## log(wage)         6.288e+05  7.104e+04   8.851  < 2e-16 ***
## log(wage_income) -6.523e+05  7.328e+04  -8.902  < 2e-16 ***
## tax               7.574e+02  3.500e+01  21.641  < 2e-16 ***
## profit            4.057e+00  1.294e+00   3.135  0.00188 ** 
## business          3.515e+00  5.904e-01   5.954 7.06e-09 ***
## other             1.863e+00  2.680e+00   0.695  0.48755    
## single           -9.675e+01  3.202e+01  -3.021  0.00273 ** 
## pair:career_pair  3.836e+01  1.295e+01   2.962  0.00329 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 35700 on 312 degrees of freedom
## Multiple R-squared:  0.9896, Adjusted R-squared:  0.9892 
## F-statistic:  2693 on 11 and 312 DF,  p-value: < 2.2e-16

此初步模型的係數

options(scipen = 999)
lm_income$coefficients
##      (Intercept)              old             pair      career_pair 
##    437898.513778      -448.004094        21.226471    -15029.386180 
##        log(wage) log(wage_income)              tax           profit 
##    628780.571592   -652289.959060       757.363325         4.056757 
##         business            other           single pair:career_pair 
##         3.514798         1.862886       -96.750318        38.361535

殘差分布情形

summary(lm_income$residuals)
##      Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
## -161377.5  -13945.5    -554.1       0.0   11146.5  196026.5
boxplot(lm_income$residuals,main = "boxplot of residual",xlab = "residual",horizontal = TRUE)

殘差範圍從-53137至143118分布範圍很廣

plot(lm_income$fitted.values,lm_income$residuals,main = "residual plot",
     xlab = "fitted value",ylab = "residual")
abline(h = 0,col = 2)

從residual plot ,x軸為fitted value,y軸為殘差的圖中可以看出殘差圖沒有null plot的形式,所以模型為error是non-constant variance

QQ-plot可以診斷殘差是否服從常態分配,當大多數的殘差點落在45度線上,則殘差服從常態分配

接著由QQ-plot中可以看出模型的殘差左下與右上的點沒有落在紅色45度的線上,所以模型的殘差沒有常態分布,不符合模型假設。

初步配飾結論

1.初步配飾tax與business還有wage在\(\alpha = 0.05\)的顯著水準下顯著意即參數估計不為0,career_pair與wage在顯著水準下不顯著,意即兩者沒有交互作用

2.從residual plot可以看出模型的誤差項為non-constant variance

3.從模型的殘差QQ-Plot中可以看出模型殘差不服從常態

4.初步模型配飾需進行模型診斷

chapter 5. 模型診斷

1. stepwise regression method

我先透過stepwise regression選取變數,利用變數選取方式建立新的模型中的predictor variables

此種方式選取標準為選\(AIC\)由小排至大,AIC各變數的相對大小來排

\(AIC = n *log({RSS}/{n}) + 2p\),\(p\)為變數多寡,也可當作對變數多寡做懲罰項

選取標準為\(AIC\)越小越好

我們透過forward selection以及both selection方法進行選取

(1). forward selection

newdata <- data[3:ncol(data)]



intercept_only <- lm(income ~ 1, data=newdata)

#define model with all predictors
all <- lm(income ~ ., data=newdata)

#perform forward stepwise regression
forward <- step(intercept_only, direction='forward', scope=formula(all), trace=0)
forward$anova
##            Step Df       Deviance Resid. Df     Resid. Dev      AIC
## 1               NA             NA       323 38148335035085 8261.330
## 2 + wage_income -1 37921595900779       322   226739134306 6602.688
## 3    + business -1    79145784509       321   147593349797 6465.583
## 4         + tax -1    14290925565       320   133302424232 6434.586
## 5        + wage -1    46721164318       319    86581259914 6296.768
## 6        + pair -1     2691267899       318    83889992015 6288.537
## 7 + career_pair -1      896587961       317    82993404054 6287.056
## 8      + profit -1      679421096       316    82313982957 6286.393

透過forward selection方法選取後變數為wage_income,business,tax,wage,pair,career_pair,profit,因為\(AIC\)為起初的predictor variables中最小,所以先以這7個變數進行配飾

(2). both selection

## both

#define intercept-only model
intercept_only <- lm(income ~ 1, data=newdata)

#define model with all predictors
all <- lm(income ~ ., data=newdata)

#perform backward stepwise regression
both <- step(intercept_only, direction='both', scope=formula(all), trace=0)

#view results of backward stepwise regression
both$anova
##            Step Df       Deviance Resid. Df     Resid. Dev      AIC
## 1               NA             NA       323 38148335035085 8261.330
## 2 + wage_income -1 37921595900779       322   226739134306 6602.688
## 3    + business -1    79145784509       321   147593349797 6465.583
## 4         + tax -1    14290925565       320   133302424232 6434.586
## 5        + wage -1    46721164318       319    86581259914 6296.768
## 6        + pair -1     2691267899       318    83889992015 6288.537
## 7 + career_pair -1      896587961       317    82993404054 6287.056
## 8      + profit -1      679421096       316    82313982957 6286.393

用both selection方法選取變數,\(AIC\)標準選取後一樣與forward selection選取變數一樣, 他篩選後的模型R-square和adjusted -r-square為最大

library(olsrr)
## Warning: package 'olsrr' was built under R version 4.1.3
## 
## Attaching package: 'olsrr'
## The following object is masked from 'package:datasets':
## 
##     rivers
ols_step_both_aic(all)
## 
## 
##                                            Stepwise Summary                                            
## -----------------------------------------------------------------------------------------------------
## Variable        Method       AIC             RSS                 Sum Sq           R-Sq      Adj. R-Sq 
## -----------------------------------------------------------------------------------------------------
## wage_income    addition    7524.161    226739134305.621    37921595900779.078    0.99406      0.99404 
## business       addition    7387.055    147593349796.685    38000741685288.016    0.99613      0.99611 
## tax            addition    7356.058    133302424231.549    38015032610853.156    0.99651      0.99647 
## wage           addition    7218.240     86581259913.550    38061753775171.156    0.99773      0.99770 
## pair           addition    7210.009     83889992014.722    38064445043069.984    0.99780      0.99777 
## career_pair    addition    7208.528     82993404053.560    38065341631031.141    0.99782      0.99778 
## profit         addition    7207.865     82313982957.168    38066021052127.539    0.99784      0.99779 
## -----------------------------------------------------------------------------------------------------

之後我們選的predictor variables為 wage_income,business,tax,wage,pair,career_pair,profit

both$coefficients
## (Intercept) wage_income    business         tax        wage        pair 
## 1453.910477   -2.603843    1.810282  527.030581    3.879911  -27.831459 
## career_pair      profit 
## 3885.351885    0.956838

這是利用both selection選取變數後做迴歸分析模型的參數估計

lm_income_mod <- lm(income~wage_income+business+tax+wage+pair+career_pair+profit,data = data)
summary(lm_income_mod)
## 
## Call:
## lm(formula = income ~ wage_income + business + tax + wage + pair + 
##     career_pair + profit, data = data)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -39836  -5612  -1444   2518 144550 
## 
## Coefficients:
##              Estimate Std. Error t value             Pr(>|t|)    
## (Intercept) 1453.9105  1778.4572   0.818              0.41425    
## wage_income   -2.6038     0.2955  -8.811 < 0.0000000000000002 ***
## business       1.8103     0.2790   6.488       0.000000000335 ***
## tax          527.0306    35.1171  15.008 < 0.0000000000000002 ***
## wage           3.8799     0.3218  12.058 < 0.0000000000000002 ***
## pair         -27.8315     8.5396  -3.259              0.00124 ** 
## career_pair 3885.3519  2403.0651   1.617              0.10691    
## profit         0.9568     0.5925   1.615              0.10731    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 16140 on 316 degrees of freedom
## Multiple R-squared:  0.9978, Adjusted R-squared:  0.9978 
## F-statistic: 2.088e+04 on 7 and 316 DF,  p-value: < 0.00000000000000022

之後配飾利用both selection方法,利用此方法選取變數後進行模型配飾

2. 殘差診斷

利用wage_income,business,tax,wage,pair,career_pair,profit

newdata <- data.frame(wage_income = data$wage_income,
                      business = data$business,
                      tax =  data$tax,
                      wage = data$wage,
                      pair = data$pair,
                      career_pair = data$career_pair,
                      profit = data$profit)

先觀察利用both selection選取變數之間的關係

plot(newdata,main = "summary graph")

再搭配correlation matrix

cor(newdata)
##             wage_income   business        tax      wage       pair career_pair
## wage_income   1.0000000 0.85788126 0.99003594 0.9995947 0.97371218  0.10592182
## business      0.8578813 1.00000000 0.85734586 0.8600760 0.81626408  0.03428154
## tax           0.9900359 0.85734586 1.00000000 0.9862474 0.98366689  0.08695252
## wage          0.9995947 0.86007595 0.98624737 1.0000000 0.96934012  0.10985998
## pair          0.9737122 0.81626408 0.98366689 0.9693401 1.00000000  0.07650446
## career_pair   0.1059218 0.03428154 0.08695252 0.1098600 0.07650446  1.00000000
## profit        0.8613937 0.80845919 0.85397808 0.8632931 0.84091631  0.14963490
##                profit
## wage_income 0.8613937
## business    0.8084592
## tax         0.8539781
## wage        0.8632931
## pair        0.8409163
## career_pair 0.1496349
## profit      1.0000000

wage_income vs.wage tax vs. wage_income 相關性蠻高的,推測兩者變數有一定共線性

這7個變數配飾模型來看看殘差分析

首先,進行residual plot

summary(lm_income_mod$residuals)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  -39836   -5612   -1444       0    2518  144550
boxplot(lm_income_mod$residuals,main = "boxplot of residual",xlab = "residual",horizontal = TRUE)

殘差分布狀態

summary(lm_income_mod$residuals)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  -39836   -5612   -1444       0    2518  144550
boxplot(lm_income_mod$residuals,main = "boxplot of residual",xlab = "residual",horizontal = TRUE)

plot(lm_income_mod$fitted.values,lm_income_mod$residuals,
     xlab = "fitted value",ylab = "residual",main = "residual plot")
abline(h = 0,col = 2)

從殘差圖中可以看出並非所謂的null plot所以可以推測利用both selection配飾的迴歸分析模型的誤差項並非constant variance

來看看殘差的QQ-Plot

qqnorm(lm_income_mod$residuals)
qqline(lm_income_mod$residuals,col = 2)

殘差分布並非全部落在45度線上,所以殘差並非服從常態分配

透過殘差圖以及QQ-plot圖判斷殘差並非服從常態分配也沒有constant variance,迴歸分析模型假設不符合

3. transformation

(1) response variable

因為殘差為非常態還有非constant variance,所以我利用box-cox transformation來進行response variable轉換,透過maximum likelihood method去選擇合適的\(\lambda\),

library(MASS)
## Warning: package 'MASS' was built under R version 4.1.3
## 
## Attaching package: 'MASS'
## The following object is masked from 'package:olsrr':
## 
##     cement
## The following object is masked from 'package:dplyr':
## 
##     select
bc <- boxcox(lm_income_mod)

lambda <- bc$x[which.max(bc$y)]
lambda
## [1] 0.989899

最後配飾結果選擇\(\lambda = 0.99\)選擇最近的整數,所以\(\lambda = 1\),不需進行response variable轉換

(2) predictor variable

利用added-variable plot來觀察變數間的關係

先來觀察這7個variable對response variable之間的關係, 並觀察是否predictor variable與response variable有線性關係,並針對此關係進行變數轉換

newdata <- data.frame(income = data$income,
                      wage_income = data$wage_income,
                      business = data$business,
                      tax =  data$tax,
                      wage = data$wage,
                      pair = data$pair,
                      career_pair = data$career_pair,
                      profit = data$profit)
  1. income vs. wage_income
library(alr4)
m1 <- lm(income ~ wage_income, data = newdata) 
avPlots(m1, id=FALSE)

此圖可以看出當ols方法來配飾這個資料,幾乎所有點都落在藍色ols線上,推測兩者的r-square很高,也可以看出兩者的線性關係很強,不需特意去做predictor variable的轉換。

  1. income vs. business
m2 <- lm(income~business , data = newdata)
avPlots(m2,id = FALSE)

此圖與income vs. wage_income,business 與 income有線性關係,不需做特意的變數轉換,但需要留意有outliers

  1. income vs. tax
m3 <- lm(income ~ tax, data = newdata) 
avPlots(m3, id=FALSE)

此圖可以看出幾乎所有點都落在ols線上,r-square推測相當大,tax也有著線性關係tax不須特意做變數轉換。

  1. income vs. wage
m4 <- lm(income ~ wage, data = newdata) 
avPlots(m4, id=FALSE)

此圖也能看出幾乎所有的點都落在ols藍色線上,推測r-sqaure偏大,而wage也沒有很顯著的二次式關係,所以不需要做線性轉換

5.income vs. pair

m5 <- lm(income ~ pair, data = newdata) 
avPlots(m5, id=FALSE)

此圖的added - variable plot可以看出,幾乎所有的點都落在藍色ols線上,也沒有出現明顯的二次式點,所以可以不需做特意的變數轉換

6.income vs. career_pair

m6 <- lm(income ~ career_pair, data = newdata) 
avPlots(m6, id=FALSE)

透過此圖可以看出career_pair有許多replications所以ols藍色線配適出來有一些問題,所以可以考慮用lack of fit test來進行診斷此變數模型是否合適

  1. income vs.profit
m7 <- lm(income ~ profit, data) 
avPlots(m7, id=FALSE)

此圖可以看出profit也沒有很明顯的二次式或其他非線性關係 所以不須特意做一些變數轉換,但還是有些點懷疑是outliers

4.weighted least square

經過上述狀態可以發現,用box-cox transformation告訴我們起初both selection篩選出來的變數不需做模型以及變數的轉換,也透過added- variable plot可以發現,predictor variable不需要特意做模型變數轉換,意即我們用both selection 的方法篩選後不需要做任何變數轉換,但殘差圖可以反應殘差並非constant variance,連QQ-Plot都沒有常態性。

若針對殘差的constant variance進行weighted least square(WLS)可以將各個觀測值得模型殘差進行加權,使其變成殘差相同變異

wt <- 1 / lm(abs(lm_income_mod$residuals) ~ lm_income_mod$fitted.values)$fitted.values^2


#perform weighted least squares regression
wls_model <- lm(income ~ wage_income + business + tax + wage            + pair + career_pair + profit, data = newdata,
                weights=wt)
#view summary of model
summary(wls_model)
## 
## Call:
## lm(formula = income ~ wage_income + business + tax + wage + pair + 
##     career_pair + profit, data = newdata, weights = wt)
## 
## Weighted Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.2195 -0.7363 -0.1695  0.4701 17.5758 
## 
## Coefficients:
##              Estimate Std. Error t value             Pr(>|t|)    
## (Intercept)  534.0329  1367.4202   0.391             0.696400    
## wage_income   -2.2618     0.3098  -7.302     0.00000000000232 ***
## business       2.0291     0.2959   6.858     0.00000000003679 ***
## tax          490.8045    41.4244  11.848 < 0.0000000000000002 ***
## wage           3.4883     0.3348  10.418 < 0.0000000000000002 ***
## pair         -25.5636     7.1114  -3.595             0.000377 ***
## career_pair 1409.9801  2326.1239   0.606             0.544850    
## profit         2.1690     0.6308   3.439             0.000663 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.766 on 316 degrees of freedom
## Multiple R-squared:  0.9937, Adjusted R-squared:  0.9936 
## F-statistic:  7140 on 7 and 316 DF,  p-value: < 0.00000000000000022

以上程式碼為利用weighted least square進行配飾 可以看出wage_income,business,tax,wage,pair,profit在\(\alpha = 0.05\)顯著水準下為顯著,

\(R^2 = \frac{SSReg}{SSTO}\) R-square = 0.9937,但複迴歸模型中若自變數增加則會增加r-square,所以我們觀察adjusted-r-square發現也達到0.9936,利用weighted least square配飾adjusted -r-square也相當不錯

library(ggfortify)
## Warning: package 'ggfortify' was built under R version 4.1.3
autoplot(wls_model)

auto plot具有四張圖,

左上為一般的residual plot,可以觀察殘差是否有同質變異性,當出現null plot代表模型的殘差具有同質變異性

右上為QQ- plot為殘差先標準化進行排序,當大部分殘差落在45度線上,則模型殘差為常態分配

左下為殘差進行標準化進行殘差圖分析,當出現null plot則代表具有殘差同質變異性

右下為槓桿值,偵測槓桿值,並分析那些觀測點為槓桿值

最後用auto plot可以將residual plot印出,左上角的residual plot可以看出模型似乎為null plot推測有可能是殘差同質性

但光看殘差圖比較主觀,需要一些模型檢定進行診斷

利用Non-constant Variance Score Test 進行殘差同質性檢定,

\(H_{0}\): constant variance

library(car)
ncvTest(wls_model)
## Non-constant Variance Score Test 
## Variance formula: ~ fitted.values 
## Chisquare = 2.141765, Df = 1, p = 0.14334

從檢定結果可以看出p-value = 0.309 大於\(\alpha = 0.05\) 所以不拒絕null hypothesis

代表殘差具有同質變異

接著利用常態檢定來觀察WLS殘差是否有常態性,

qqnorm(wls_model$residuals)
qqline(wls_model$residuals,col = 2,lwd = 2)

從QQ-Plot圖中可以發現殘差有些點並非落在45度線上,推測並非服從常態分布, 利用Shapiro-Wilk normality test結果也可以發現

shapiro.test(wls_model$residuals)
## 
##  Shapiro-Wilk normality test
## 
## data:  wls_model$residuals
## W = 0.66201, p-value < 0.00000000000000022

p-value < 0.05所以拒絕null hypothesis

\(H_{0}\):殘差服從常態假設

拒絕null hypothesis所以殘差不服從常態假設,但我們也做了box-cox transformation所以推測有可能樣本數太少(324筆樣本數),以至於殘差太少,所以不難發現常態檢定這假設沒過

5.outliers 診斷

因為我們利用weighted least square(以下簡稱WLS)進行模型配飾,但有些離群值可能影響模型最終配飾,所以針對這些模型進行離群值診斷,但並非所有的離群值都不好,但剔除離群值勢必會對模型有進一步影響,尤其是influential points 此點會影響模型最終配飾的參數估計以及standard error

library(olsrr)
ols_plot_cooksd_chart(wls_model)

ols_plot_cooksd_bar(wls_model)

cooksd <- cooks.distance(wls_model)

# Plot the Cook's Distance using the traditional 4/n criterion
sample_size <- nrow(newdata)
plot(cooksd, pch="*", cex=2, main="Influential Obs by Cooks distance")  # plot cook's distance
abline(h = 4/sample_size, col="red")  # add cutoff line
text(x=1:length(cooksd)+1, y=cooksd, labels=ifelse(cooksd>4/sample_size, names(cooksd),""), col="red")  # add labels

influential <- as.numeric(names(cooksd)[(cooksd > (4/sample_size))])

當cook’s distance 越大代表槓桿點越大,影響模型估計越明顯, 勢必要將這些點移除,避免影響迴歸分析模型估計結果

利用cook’s distance偵測影響點

資料當中可以看出共有15個樣本點為影響點

influential <- as.numeric(names(cooksd)[(cooksd > (4/sample_size))])
data[influential,]
##     county   town income   old pair career_pair   wage wage_income  tax profit
## 13  臺東縣 臺東市 444715 18.53  822           0 235905      297925  466   5672
## 32  臺東縣 臺東市 811646 12.17 1331           0 525625      653189  835   5426
## 51  臺東縣 成功鎮 291062 24.22  948           0 181281      235702  414  11647
## 98  臺東縣 東河鄉 390834 26.79  944           0 144249      190181  353   5126
## 154 花蓮縣 花蓮市 447071 21.36  894           0 220062      279419  510   2682
## 155 花蓮縣 花蓮市 928186 22.56 1776           0 530134      675085 1085   7175
## 157 花蓮縣 花蓮市 364676 31.45  783           3 233847      302965  504   6887
## 171 花蓮縣 花蓮市 450491 13.62  863           1 293908      371346  532   9932
## 172 花蓮縣 花蓮市 322344 15.38  436           1 154490      201392  319   6643
## 173 花蓮縣 花蓮市 180231 18.43  265           0  87179      112549  201   1952
## 179 花蓮縣 花蓮市 330943 19.68  496           0 215304      255266  300   6724
## 201 花蓮縣 鳳林鎮  87307 50.39  307           0  44877       58554   97    109
## 222 花蓮縣 新城鄉 614897 16.96 1013           1 303414      399440  690   2755
## 278 花蓮縣 豐濱鄉  94518 27.69  334           0  29950       43877   96    439
## 312 花蓮縣 秀林鄉 226858  9.69  587           0 132890      195422  407   1560
##     business other single
## 13     21318  2873    147
## 32     12460  3476    424
## 51      7455  1718    236
## 98      8664  1590    412
## 154    23802  1261    551
## 155    18060  5888    353
## 157     2892  1372    395
## 171    13608  1978    199
## 172     2791  1668    159
## 173     1048  2119    125
## 179    13008  1000    153
## 201    15379  3557    111
## 222     5574  1343    350
## 278      321   288    112
## 312      767  1604    165
nrow(data[influential,])
## [1] 15

將此15個樣本點移除後,做WLS進行模型配飾

new <- newdata[-influential, ]
model <- lm(income~wage_income + business + tax + wage + pair 
            + career_pair + profit,data = new)
wt <- 1 / lm(abs(model$residuals) ~ model$fitted.values)$fitted.values^2

#perform weighted least squares regression
wls_model1 <- lm(income ~ wage_income + business + tax + wage + 
                  pair + career_pair + profit, data = new, weights=wt)

#view summary of model
summary(wls_model1)
## 
## Call:
## lm(formula = income ~ wage_income + business + tax + wage + pair + 
##     career_pair + profit, data = new, weights = wt)
## 
## Weighted Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.7642 -0.7259 -0.0936  0.7206  5.8641 
## 
## Coefficients:
##              Estimate Std. Error t value             Pr(>|t|)    
## (Intercept) 1079.0704   709.4268   1.521                0.129    
## wage_income   -2.4538     0.1731 -14.173 < 0.0000000000000002 ***
## business       1.7709     0.1877   9.432 < 0.0000000000000002 ***
## tax          487.7791    23.5182  20.740 < 0.0000000000000002 ***
## wage           3.7439     0.1876  19.954 < 0.0000000000000002 ***
## pair         -25.0697     3.8780  -6.465       0.000000000409 ***
## career_pair -596.7711  1339.1956  -0.446                0.656    
## profit         1.5805     0.3834   4.123       0.000048457213 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.266 on 301 degrees of freedom
## Multiple R-squared:  0.998,  Adjusted R-squared:  0.9979 
## F-statistic: 2.118e+04 on 7 and 301 DF,  p-value: < 0.00000000000000022
library(ggfortify)
autoplot(wls_model1)

可以看出左上的residual plot似乎出現null plot的現象,右上的QQ-plot圖中觀察到資料有點傾向常態,但觀察圖形比較主觀,需用一些統計檢定進行輔助,首先先進行ncvTest,null hypothesis為殘差具有同質變異

library(car)
ncvTest(wls_model1)
## Non-constant Variance Score Test 
## Variance formula: ~ fitted.values 
## Chisquare = 1.661305, Df = 1, p = 0.19743

最後得到p-value = 0.19743 > \(\alpha = 0.05\)所以不拒絕null hypothesis 代表沒有足夠證據顯示模型殘差沒有同質變異,亦即殘差具有同質變異性。

接著利用shapiro wilks test檢定殘差是否有常態性

shapiro.test(wls_model1$residuals)
## 
##  Shapiro-Wilk normality test
## 
## data:  wls_model1$residuals
## W = 0.89814, p-value = 0.0000000000001488

進行常態檢定後發現不拒絕null hypothesis,所以有足夠證據顯示殘差為非常態分配,常態檢定未過 ,但起初有進行box-cox transformation,常態仍然沒過,或許因為樣本數不夠多,使得殘差常態檢定沒過。

6.共線性診斷並分析

共線性為自變數之間出現線性關係,進而影響模型最後結果,包括參數估計結果以及r-square,我們利用VIF方式來診斷模型自變數是否具有共線性, 某些解釋變數間存在某種近似的線性關係,我們選擇當VIF> 10則變數之間具有限性關係或有共線性。

library(car)

vif <- vif(wls_model1, digits = 3)
vif
## wage_income    business         tax        wage        pair career_pair 
## 2932.414136    3.132935  132.077717 2115.209881   10.034415    1.074382 
##      profit 
##    2.816435
barplot(vif,horiz = TRUE,las = 2)

最後發現wage_income,tax,wage,pair有共線性,但我們發現有共線性我們可以用ridge regression model來進行配飾,會有比較好的效果,刪除自變數或用逐步迴歸分析方法可能效果不會到太好,ridge regression 方法配飾會有好的效果,再此不特意做配飾維持原模型進行配飾。

chapter 6. 模型配飾與預測

最後我們利用chapter5.一系列的診斷模型方法進行配飾模型,包括殘差檢定(殘差圖來觀察是否殘差具有同質變異性,QQ-Plot觀察殘差是否服從常態分配) 還有一些統計檢定,WLS模型進行變異數加權模型配飾還有離群值診斷並剔除離群值進行進一步配飾還有BOX-COX transformation對response variable進行變數變換,最後得到以下模型配飾,此模型為最終模型配飾。

1.最終模型結果

wls_model1
## 
## Call:
## lm(formula = income ~ wage_income + business + tax + wage + pair + 
##     career_pair + profit, data = new, weights = wt)
## 
## Coefficients:
## (Intercept)  wage_income     business          tax         wage         pair  
##    1079.070       -2.454        1.771      487.779        3.744      -25.070  
## career_pair       profit  
##    -596.771        1.581
summary(wls_model1)
## 
## Call:
## lm(formula = income ~ wage_income + business + tax + wage + pair + 
##     career_pair + profit, data = new, weights = wt)
## 
## Weighted Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.7642 -0.7259 -0.0936  0.7206  5.8641 
## 
## Coefficients:
##              Estimate Std. Error t value             Pr(>|t|)    
## (Intercept) 1079.0704   709.4268   1.521                0.129    
## wage_income   -2.4538     0.1731 -14.173 < 0.0000000000000002 ***
## business       1.7709     0.1877   9.432 < 0.0000000000000002 ***
## tax          487.7791    23.5182  20.740 < 0.0000000000000002 ***
## wage           3.7439     0.1876  19.954 < 0.0000000000000002 ***
## pair         -25.0697     3.8780  -6.465       0.000000000409 ***
## career_pair -596.7711  1339.1956  -0.446                0.656    
## profit         1.5805     0.3834   4.123       0.000048457213 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.266 on 301 degrees of freedom
## Multiple R-squared:  0.998,  Adjusted R-squared:  0.9979 
## F-statistic: 2.118e+04 on 7 and 301 DF,  p-value: < 0.00000000000000022

當中截距項估計不顯著於0,還有pair也不顯著於0

所以最終配飾模型結果為

wls_model1$coefficients
## (Intercept) wage_income    business         tax        wage        pair 
## 1079.070371   -2.453809    1.770880  487.779130    3.743882  -25.069674 
## career_pair      profit 
## -596.771148    1.580545

\(Y_{i} = -2.4538X_{1} + 1.7709X_{2} + 487.7791X_{3} + 3.7439X_{4} -25.0697X_{5} + 1.5805X_{6} + \varepsilon_{i}\)

\(\varepsilon_{i}~iid N(0,\sigma^2)\)

顯著參數為

變數 程式名稱 中文定義
Y “income” 綜合所得總額
X1 “wage_income” 各類所得金額薪資所得
X2 “business” 各類所得金額執行業務所得
X3 “tax” 綜合所得稅各類所得納稅單位
X4 “wage” 薪資淨所得
X5 “pair” 15歲以上有偶人口數
X6 “profit” 各類所得金額營利所得

最終模型殘差分析結果以及敘述統計

summary(wls_model1$residuals)
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
## -33393.6  -3794.8   -355.5    126.3   3406.0  47033.4

2.利用bootstrap method推算信賴區間以及standard error

bootstrap可以針對非常態假設進行信賴區間,bootstrap test跟預測區間, 檢測道理很簡單,抽取樣本方式為取後放回,將想要估計的統計量記起來,比方說中位數,放回後進行多次實驗,最終算出95%的信賴區間估計。一般迭代越多次,越可以精準估計參數。

本次實驗為我們最終模型,意即剔除極端點還有影響點的WLS模型 bootstrap共做1000次實驗,讓R軟體進行計算

## boot strap

# Bootstrap 95% CI for regression coefficients
library(boot)
## Warning: package 'boot' was built under R version 4.1.3
## 
## Attaching package: 'boot'
## The following object is masked from 'package:car':
## 
##     logit
# function to obtain regression weights
bs <- function(formula, data, indices) {
  d <- data[indices,] # allows boot to select sample
  fit <- lm(formula, data=d)
  return(coef(fit))
}
# bootstrapping with 1000 replications
results <- boot(data=new, statistic=bs,
                R=1000, formula=wls_model1)

# view results
results
## 
## ORDINARY NONPARAMETRIC BOOTSTRAP
## 
## 
## Call:
## boot(data = new, statistic = bs, R = 1000, formula = wls_model1)
## 
## 
## Bootstrap Statistics :
##        original       bias     std. error
## t1* 1079.070371   37.1664147 1132.1548208
## t2*   -2.453809   -0.2404637    0.3420311
## t3*    1.770880   -0.2693134    0.3583199
## t4*  487.779130   40.9398961   41.9685791
## t5*    3.743882    0.2618205    0.3740050
## t6*  -25.069674   -4.9486512    6.1309128
## t7* -596.771148 2160.7147821 1931.4554332
## t8*    1.580545   -0.7861542    0.6701709

當中的bootstrap statistics那表格的original statistics為WLS配飾的參數估計,共有8個,

第二欄的bias為bootstrap估計出來參數與WLS估計出來的差異

第三欄為bootstrap估計出來的參數標準誤,但當中的標準誤會比WLS估計出來的還要來的大,因為透過Gauss Markov定理知道利用OLS估計出來的參數誤差會最小且不偏

透過參數估計以及參數估計標準誤可以求算95%信賴區間

type = “norm”為估計參數做信賴區間為接近常態方式估計

# get 95% confidence intervals
ci <- rbind(boot.ci(results, type="norm", index=1)$normal, # intercept
boot.ci(results, type="norm", index=2)$normal, # wage_income
boot.ci(results, type="norm", index=3)$normal,# business
boot.ci(results, type="norm", index=4)$normal, # tax
boot.ci(results, type="norm", index=5)$normal, # wage
boot.ci(results, type="norm", index=6)$normal, # pair
boot.ci(results, type="norm", index=7)$normal, # career_pair
boot.ci(results, type="norm", index=8)$normal) # profit

estimate <- rbind(boot.ci(results, type="norm", index=1)$t0,
                  boot.ci(results, type="norm", index=2)$t0,
                  boot.ci(results, type="norm", index=3)$t0,
                  boot.ci(results, type="norm", index=4)$t0,
                  boot.ci(results, type="norm", index=5)$t0,
                  boot.ci(results, type="norm", index=6)$t0,
                  boot.ci(results, type="norm", index=7)$t0,
                  boot.ci(results, type="norm", index=8)$t0)
ci <- cbind(ci,estimate)
colnames(ci) <- c("conf","lower bound","upper bound","estimate")
ci <- as.data.frame(ci)
ci
##             conf  lower bound upper bound    estimate
## (Intercept) 0.95 -1177.078717 3260.886631 1079.070371
## wage_income 0.95    -2.883714   -1.542977   -2.453809
## business    0.95     1.337899    2.742487    1.770880
## tax         0.95   364.582330  529.096137  487.779130
## wage        0.95     2.749025    4.215098    3.743882
## pair        0.95   -32.137391   -8.104654  -25.069674
## career_pair 0.95 -6543.069016 1028.097157 -596.771148
## profit      0.95     1.053189    3.680210    1.580545

最終利用bootstrap 方式得到個參數估計的95%信賴區間

lower bound為95% 信賴區間下界,upper bound為95%信賴區間上界

estimate為利用bootstrap方式所估計出來的參數,重複迭代1000次

3.利用delta method估計

delta method是利用一般泰勒展式,將非線性的變數計算變異數,標準誤還有信賴區間,例如如果我們針對估計出來的模型中的各類所得金額執行業務所得(business)跟薪資淨所得(wage)比例有興趣我們可以利用delta method進行估計

deltaMethod(wls_model1,"business/wage")
##               Estimate      SE   2.5 % 97.5 %
## business/wage  0.47301 0.06299 0.34955 0.5965

可以看出標準誤為0.06299,估計出來的參數比例為0.47301

4. 模型預測

首先我們先從各變數中位數來進行模型預測,利用最終wls_model1迴歸分析模型

median <- apply(new[2:ncol(new)],2,median)
median <- t(median)
median_data <- as.data.frame(median)
prediction <- predict(wls_model1,newdata = median_data)
prediction
##        1 
## 125791.5
data <- data.frame(real = median(new$income),prediction)
data
##     real prediction
## 1 131362   125791.5

real表示真實資料意即104年花東綜合所得總額中位數,但從預測出來的綜合所得總額中位數比真實資料少,代表綜合所得總額會受到其他因素影響。

5. 總結

summary(wls_model1)
## 
## Call:
## lm(formula = income ~ wage_income + business + tax + wage + pair + 
##     career_pair + profit, data = new, weights = wt)
## 
## Weighted Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.7642 -0.7259 -0.0936  0.7206  5.8641 
## 
## Coefficients:
##              Estimate Std. Error t value             Pr(>|t|)    
## (Intercept) 1079.0704   709.4268   1.521                0.129    
## wage_income   -2.4538     0.1731 -14.173 < 0.0000000000000002 ***
## business       1.7709     0.1877   9.432 < 0.0000000000000002 ***
## tax          487.7791    23.5182  20.740 < 0.0000000000000002 ***
## wage           3.7439     0.1876  19.954 < 0.0000000000000002 ***
## pair         -25.0697     3.8780  -6.465       0.000000000409 ***
## career_pair -596.7711  1339.1956  -0.446                0.656    
## profit         1.5805     0.3834   4.123       0.000048457213 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.266 on 301 degrees of freedom
## Multiple R-squared:  0.998,  Adjusted R-squared:  0.9979 
## F-statistic: 2.118e+04 on 7 and 301 DF,  p-value: < 0.00000000000000022

表格中出現3個*表示在\(\alpha = 0.05\)顯著水準下為顯著於0

程式名稱 中文定義 模型參數估計
“income” 綜合所得總額 Y
“pair” 15歲以上有偶人口數 -25.0697
“career_pair” 共同事業戶數 -596.7711
“wage” 薪資淨所得 3.7439
“wage_income” 各類所得金額薪資所得 -2.4538
“tax” 綜合所得稅各類所得納稅單位 487.7791
“profit” 各類所得金額營利所得 1.5805
“business” 各類所得金額執行業務所得 1.7709

綜合所得總額在花東地區會受到

15歲以上有偶人口數,負相關影響意及當有偶人口數多,綜合所得總額就比較小

共同事業戶數,負相關影響意即當共同事業戶數越多,綜合所得總額就越小

薪資淨所得,正相關影響意即當薪資淨所得多,綜合所得總額就越大

各類所得金額薪資所得,負相關影響意即當各類所得金額薪資所得越大則綜合所得總額就越小

綜合所得稅各類所得納稅單位,正相關影響意即當綜合所得稅各類所得納稅單位越大,則綜合所得總額就越大

各類所得金額營利所得,正相關影響意即當各類所得金額營利所得越大,則綜合所得總額就越大

各類所得金額執行業務所得,正相關影響意即當各類所得金額執行業務所得越大,則綜合所得總額就越大

當然模型估計出來並非百分之百精準,值得注意的是,花東地區為台灣發展比較慢的地區,對於綜合所得稅或許比西部開發城市例如新北市,台北市,桃園新竹台中等會偏少,但從花東地區分析其綜合所得總額可以看出15歲以上有偶人口數,共同事業戶數還有各類所得金額薪資所得 越多則綜合所得總額竟然會越少,這點出乎我的意料,政府必須更重視逃漏稅的可能性,照理說共同事業戶數越多,所得必須增加,因為共同事業可以課兩次稅收,但當每年5月納稅時,共同事業戶可能納稅時將財產申報至一方身上,而少了一人課稅。 15歲以上的有偶人口數也是如此,未來希望政府多關注15歲以上有偶人口數還有共同事業戶是否有依法規進行納稅。