1 Tuần 4:

1.1 Các thao tác với biểu đồ trong gói ggplot2

1.1.1 vẽ biểu đồ Vẽ biểu đồ Scatter Plot trong R

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.2.3
library(AER)
## Warning: package 'AER' was built under R version 4.2.3
## Loading required package: car
## Warning: package 'car' was built under R version 4.2.3
## Loading required package: carData
## Warning: package 'carData' was built under R version 4.2.3
## Loading required package: lmtest
## Warning: package 'lmtest' was built under R version 4.2.3
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 4.2.3
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: sandwich
## Warning: package 'sandwich' was built under R version 4.2.3
## Loading required package: survival
data("CPS1985")

#### Chọn ra 3 biến lương, tuổi và nghề nghiệp để phân tích theo biến trình độ học vấn

CPS1985|> ggplot(map = aes(x =  education , y = wage)) +
  geom_point(color = 'red')

CPS1985|> ggplot(map = aes(x =  education , y = age)) +
  geom_point(color = 'black')

2 Tuần 3

2.1 Giới thiệu dữ liệu:

2.1.1 Bộ dữ liệu hoa Iris hoặc bộ dữ liệu Iris của Fisher là một bộ dữ liệu đa biến được giới thiệu bởi nhà thống kê và nhà sinh vật học người Anh Ronald Fisher trong bài báo năm 1936 của ông Việc sử dụng nhiều phép đo trong các vấn đề phân loại như một ví dụ về phân tích phân biệt tuyến tính.[1] Đôi khi nó được gọi là bộ dữ liệu Iris của Anderson vì Edgar Anderson đã thu thập dữ liệu để định lượng sự biến đổi hình thái của hoa Iris của ba loài có liên quan.[2] Hai trong số ba loài được thu thập ở Bán đảo Gaspé “tất cả từ cùng một đồng cỏ, được hái trong cùng một ngày và được đo lường cùng một lúc bởi cùng một người với cùng một thiết bị”.[3]Bộ dữ liệu bao gồm 50 mẫu từ ba loài Iris (Iris setosa, Iris virginica và Iris versicolor). Bốn đặc điểm được đo từ mỗi mẫu: chiều dài và chiều rộng của các lá đài và cánh hoa, tính bằng centimet. Dựa trên sự kết hợp của bốn đặc điểm này, Fisher đã phát triển một mô hình phân biệt tuyến tính để phân biệt các loài với nhau.

2.2 Xử lý dữ liệu

## Gọi các package trong thư viện ra

library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.2.3
## Warning: package 'tibble' was built under R version 4.2.3
## Warning: package 'tidyr' was built under R version 4.2.3
## Warning: package 'readr' was built under R version 4.2.3
## Warning: package 'purrr' was built under R version 4.2.3
## Warning: package 'dplyr' was built under R version 4.2.3
## Warning: package 'stringr' was built under R version 4.2.3
## Warning: package 'forcats' was built under R version 4.2.3
## Warning: package 'lubridate' was built under R version 4.2.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ lubridate 1.9.2     ✔ tibble    3.2.1
## ✔ purrr     1.0.1     ✔ tidyr     1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ✖ dplyr::recode() masks car::recode()
## ✖ purrr::some()   masks car::some()
## ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
library(dplyr)
data("iris") #gọi database iris ra

## pivot_longer giúp chúng ta có thể xoay dữ liệu biến  Sepal. Length từ rộng sang dài 
iris %>% pivot_longer(Sepal.Length)
## # A tibble: 150 × 6
##    Sepal.Width Petal.Length Petal.Width Species name         value
##          <dbl>        <dbl>       <dbl> <fct>   <chr>        <dbl>
##  1         3.5          1.4         0.2 setosa  Sepal.Length   5.1
##  2         3            1.4         0.2 setosa  Sepal.Length   4.9
##  3         3.2          1.3         0.2 setosa  Sepal.Length   4.7
##  4         3.1          1.5         0.2 setosa  Sepal.Length   4.6
##  5         3.6          1.4         0.2 setosa  Sepal.Length   5  
##  6         3.9          1.7         0.4 setosa  Sepal.Length   5.4
##  7         3.4          1.4         0.3 setosa  Sepal.Length   4.6
##  8         3.4          1.5         0.2 setosa  Sepal.Length   5  
##  9         2.9          1.4         0.2 setosa  Sepal.Length   4.4
## 10         3.1          1.5         0.1 setosa  Sepal.Length   4.9
## # ℹ 140 more rows
## Kết quả cho thấy biến Sepal.Width,Petal.Length,Petal.Width ngoài ra còn các cột mới tên name có tên Sepal.Length và value của cột Sepal.Length, 

## Hàm pivot_longer không thể nhận biết được dấu chấm, nên chúng ta dùng 'c()' để chọn biến

iris %>% pivot_longer(c(Sepal.Length, Petal.Length))
## # A tibble: 300 × 5
##    Sepal.Width Petal.Width Species name         value
##          <dbl>       <dbl> <fct>   <chr>        <dbl>
##  1         3.5         0.2 setosa  Sepal.Length   5.1
##  2         3.5         0.2 setosa  Petal.Length   1.4
##  3         3           0.2 setosa  Sepal.Length   4.9
##  4         3           0.2 setosa  Petal.Length   1.4
##  5         3.2         0.2 setosa  Sepal.Length   4.7
##  6         3.2         0.2 setosa  Petal.Length   1.3
##  7         3.1         0.2 setosa  Sepal.Length   4.6
##  8         3.1         0.2 setosa  Petal.Length   1.5
##  9         3.6         0.2 setosa  Sepal.Length   5  
## 10         3.6         0.2 setosa  Petal.Length   1.4
## # ℹ 290 more rows
# Toán tử phủ nhận một lựa chọn
iris %>% select(!c(Sepal.Length, Petal.Length))
##     Sepal.Width Petal.Width    Species
## 1           3.5         0.2     setosa
## 2           3.0         0.2     setosa
## 3           3.2         0.2     setosa
## 4           3.1         0.2     setosa
## 5           3.6         0.2     setosa
## 6           3.9         0.4     setosa
## 7           3.4         0.3     setosa
## 8           3.4         0.2     setosa
## 9           2.9         0.2     setosa
## 10          3.1         0.1     setosa
## 11          3.7         0.2     setosa
## 12          3.4         0.2     setosa
## 13          3.0         0.1     setosa
## 14          3.0         0.1     setosa
## 15          4.0         0.2     setosa
## 16          4.4         0.4     setosa
## 17          3.9         0.4     setosa
## 18          3.5         0.3     setosa
## 19          3.8         0.3     setosa
## 20          3.8         0.3     setosa
## 21          3.4         0.2     setosa
## 22          3.7         0.4     setosa
## 23          3.6         0.2     setosa
## 24          3.3         0.5     setosa
## 25          3.4         0.2     setosa
## 26          3.0         0.2     setosa
## 27          3.4         0.4     setosa
## 28          3.5         0.2     setosa
## 29          3.4         0.2     setosa
## 30          3.2         0.2     setosa
## 31          3.1         0.2     setosa
## 32          3.4         0.4     setosa
## 33          4.1         0.1     setosa
## 34          4.2         0.2     setosa
## 35          3.1         0.2     setosa
## 36          3.2         0.2     setosa
## 37          3.5         0.2     setosa
## 38          3.6         0.1     setosa
## 39          3.0         0.2     setosa
## 40          3.4         0.2     setosa
## 41          3.5         0.3     setosa
## 42          2.3         0.3     setosa
## 43          3.2         0.2     setosa
## 44          3.5         0.6     setosa
## 45          3.8         0.4     setosa
## 46          3.0         0.3     setosa
## 47          3.8         0.2     setosa
## 48          3.2         0.2     setosa
## 49          3.7         0.2     setosa
## 50          3.3         0.2     setosa
## 51          3.2         1.4 versicolor
## 52          3.2         1.5 versicolor
## 53          3.1         1.5 versicolor
## 54          2.3         1.3 versicolor
## 55          2.8         1.5 versicolor
## 56          2.8         1.3 versicolor
## 57          3.3         1.6 versicolor
## 58          2.4         1.0 versicolor
## 59          2.9         1.3 versicolor
## 60          2.7         1.4 versicolor
## 61          2.0         1.0 versicolor
## 62          3.0         1.5 versicolor
## 63          2.2         1.0 versicolor
## 64          2.9         1.4 versicolor
## 65          2.9         1.3 versicolor
## 66          3.1         1.4 versicolor
## 67          3.0         1.5 versicolor
## 68          2.7         1.0 versicolor
## 69          2.2         1.5 versicolor
## 70          2.5         1.1 versicolor
## 71          3.2         1.8 versicolor
## 72          2.8         1.3 versicolor
## 73          2.5         1.5 versicolor
## 74          2.8         1.2 versicolor
## 75          2.9         1.3 versicolor
## 76          3.0         1.4 versicolor
## 77          2.8         1.4 versicolor
## 78          3.0         1.7 versicolor
## 79          2.9         1.5 versicolor
## 80          2.6         1.0 versicolor
## 81          2.4         1.1 versicolor
## 82          2.4         1.0 versicolor
## 83          2.7         1.2 versicolor
## 84          2.7         1.6 versicolor
## 85          3.0         1.5 versicolor
## 86          3.4         1.6 versicolor
## 87          3.1         1.5 versicolor
## 88          2.3         1.3 versicolor
## 89          3.0         1.3 versicolor
## 90          2.5         1.3 versicolor
## 91          2.6         1.2 versicolor
## 92          3.0         1.4 versicolor
## 93          2.6         1.2 versicolor
## 94          2.3         1.0 versicolor
## 95          2.7         1.3 versicolor
## 96          3.0         1.2 versicolor
## 97          2.9         1.3 versicolor
## 98          2.9         1.3 versicolor
## 99          2.5         1.1 versicolor
## 100         2.8         1.3 versicolor
## 101         3.3         2.5  virginica
## 102         2.7         1.9  virginica
## 103         3.0         2.1  virginica
## 104         2.9         1.8  virginica
## 105         3.0         2.2  virginica
## 106         3.0         2.1  virginica
## 107         2.5         1.7  virginica
## 108         2.9         1.8  virginica
## 109         2.5         1.8  virginica
## 110         3.6         2.5  virginica
## 111         3.2         2.0  virginica
## 112         2.7         1.9  virginica
## 113         3.0         2.1  virginica
## 114         2.5         2.0  virginica
## 115         2.8         2.4  virginica
## 116         3.2         2.3  virginica
## 117         3.0         1.8  virginica
## 118         3.8         2.2  virginica
## 119         2.6         2.3  virginica
## 120         2.2         1.5  virginica
## 121         3.2         2.3  virginica
## 122         2.8         2.0  virginica
## 123         2.8         2.0  virginica
## 124         2.7         1.8  virginica
## 125         3.3         2.1  virginica
## 126         3.2         1.8  virginica
## 127         2.8         1.8  virginica
## 128         3.0         1.8  virginica
## 129         2.8         2.1  virginica
## 130         3.0         1.6  virginica
## 131         2.8         1.9  virginica
## 132         3.8         2.0  virginica
## 133         2.8         2.2  virginica
## 134         2.8         1.5  virginica
## 135         2.6         1.4  virginica
## 136         3.0         2.3  virginica
## 137         3.4         2.4  virginica
## 138         3.1         1.8  virginica
## 139         3.0         1.8  virginica
## 140         3.1         2.1  virginica
## 141         3.1         2.4  virginica
## 142         3.1         2.3  virginica
## 143         2.7         1.9  virginica
## 144         3.2         2.3  virginica
## 145         3.3         2.5  virginica
## 146         3.0         2.3  virginica
## 147         2.5         1.9  virginica
## 148         3.0         2.0  virginica
## 149         3.4         2.3  virginica
## 150         3.0         1.8  virginica
##Kết quả cho thấy lệnh này lựa chọn ra các gía trị không phải 2 biến Sepal.Length, Petal.Length.
## Phép toán dùng để  phủ nhận một lựa chọn trong trường hợp này là phủ nhận biến có kí tự cuối cùng có tên là "width".
iris %>% select(!ends_with("Width"))
##     Sepal.Length Petal.Length    Species
## 1            5.1          1.4     setosa
## 2            4.9          1.4     setosa
## 3            4.7          1.3     setosa
## 4            4.6          1.5     setosa
## 5            5.0          1.4     setosa
## 6            5.4          1.7     setosa
## 7            4.6          1.4     setosa
## 8            5.0          1.5     setosa
## 9            4.4          1.4     setosa
## 10           4.9          1.5     setosa
## 11           5.4          1.5     setosa
## 12           4.8          1.6     setosa
## 13           4.8          1.4     setosa
## 14           4.3          1.1     setosa
## 15           5.8          1.2     setosa
## 16           5.7          1.5     setosa
## 17           5.4          1.3     setosa
## 18           5.1          1.4     setosa
## 19           5.7          1.7     setosa
## 20           5.1          1.5     setosa
## 21           5.4          1.7     setosa
## 22           5.1          1.5     setosa
## 23           4.6          1.0     setosa
## 24           5.1          1.7     setosa
## 25           4.8          1.9     setosa
## 26           5.0          1.6     setosa
## 27           5.0          1.6     setosa
## 28           5.2          1.5     setosa
## 29           5.2          1.4     setosa
## 30           4.7          1.6     setosa
## 31           4.8          1.6     setosa
## 32           5.4          1.5     setosa
## 33           5.2          1.5     setosa
## 34           5.5          1.4     setosa
## 35           4.9          1.5     setosa
## 36           5.0          1.2     setosa
## 37           5.5          1.3     setosa
## 38           4.9          1.4     setosa
## 39           4.4          1.3     setosa
## 40           5.1          1.5     setosa
## 41           5.0          1.3     setosa
## 42           4.5          1.3     setosa
## 43           4.4          1.3     setosa
## 44           5.0          1.6     setosa
## 45           5.1          1.9     setosa
## 46           4.8          1.4     setosa
## 47           5.1          1.6     setosa
## 48           4.6          1.4     setosa
## 49           5.3          1.5     setosa
## 50           5.0          1.4     setosa
## 51           7.0          4.7 versicolor
## 52           6.4          4.5 versicolor
## 53           6.9          4.9 versicolor
## 54           5.5          4.0 versicolor
## 55           6.5          4.6 versicolor
## 56           5.7          4.5 versicolor
## 57           6.3          4.7 versicolor
## 58           4.9          3.3 versicolor
## 59           6.6          4.6 versicolor
## 60           5.2          3.9 versicolor
## 61           5.0          3.5 versicolor
## 62           5.9          4.2 versicolor
## 63           6.0          4.0 versicolor
## 64           6.1          4.7 versicolor
## 65           5.6          3.6 versicolor
## 66           6.7          4.4 versicolor
## 67           5.6          4.5 versicolor
## 68           5.8          4.1 versicolor
## 69           6.2          4.5 versicolor
## 70           5.6          3.9 versicolor
## 71           5.9          4.8 versicolor
## 72           6.1          4.0 versicolor
## 73           6.3          4.9 versicolor
## 74           6.1          4.7 versicolor
## 75           6.4          4.3 versicolor
## 76           6.6          4.4 versicolor
## 77           6.8          4.8 versicolor
## 78           6.7          5.0 versicolor
## 79           6.0          4.5 versicolor
## 80           5.7          3.5 versicolor
## 81           5.5          3.8 versicolor
## 82           5.5          3.7 versicolor
## 83           5.8          3.9 versicolor
## 84           6.0          5.1 versicolor
## 85           5.4          4.5 versicolor
## 86           6.0          4.5 versicolor
## 87           6.7          4.7 versicolor
## 88           6.3          4.4 versicolor
## 89           5.6          4.1 versicolor
## 90           5.5          4.0 versicolor
## 91           5.5          4.4 versicolor
## 92           6.1          4.6 versicolor
## 93           5.8          4.0 versicolor
## 94           5.0          3.3 versicolor
## 95           5.6          4.2 versicolor
## 96           5.7          4.2 versicolor
## 97           5.7          4.2 versicolor
## 98           6.2          4.3 versicolor
## 99           5.1          3.0 versicolor
## 100          5.7          4.1 versicolor
## 101          6.3          6.0  virginica
## 102          5.8          5.1  virginica
## 103          7.1          5.9  virginica
## 104          6.3          5.6  virginica
## 105          6.5          5.8  virginica
## 106          7.6          6.6  virginica
## 107          4.9          4.5  virginica
## 108          7.3          6.3  virginica
## 109          6.7          5.8  virginica
## 110          7.2          6.1  virginica
## 111          6.5          5.1  virginica
## 112          6.4          5.3  virginica
## 113          6.8          5.5  virginica
## 114          5.7          5.0  virginica
## 115          5.8          5.1  virginica
## 116          6.4          5.3  virginica
## 117          6.5          5.5  virginica
## 118          7.7          6.7  virginica
## 119          7.7          6.9  virginica
## 120          6.0          5.0  virginica
## 121          6.9          5.7  virginica
## 122          5.6          4.9  virginica
## 123          7.7          6.7  virginica
## 124          6.3          4.9  virginica
## 125          6.7          5.7  virginica
## 126          7.2          6.0  virginica
## 127          6.2          4.8  virginica
## 128          6.1          4.9  virginica
## 129          6.4          5.6  virginica
## 130          7.2          5.8  virginica
## 131          7.4          6.1  virginica
## 132          7.9          6.4  virginica
## 133          6.4          5.6  virginica
## 134          6.3          5.1  virginica
## 135          6.1          5.6  virginica
## 136          7.7          6.1  virginica
## 137          6.3          5.6  virginica
## 138          6.4          5.5  virginica
## 139          6.0          4.8  virginica
## 140          6.9          5.4  virginica
## 141          6.7          5.6  virginica
## 142          6.9          5.1  virginica
## 143          5.8          5.1  virginica
## 144          6.8          5.9  virginica
## 145          6.7          5.7  virginica
## 146          6.7          5.2  virginica
## 147          6.3          5.0  virginica
## 148          6.5          5.2  virginica
## 149          6.2          5.4  virginica
## 150          5.9          5.1  virginica
## Sử dụng  "&" và  "|" để tìm điểm hợp và giao của 2 lựa chọn 
iris %>% select(starts_with("Petal") & ends_with("Width"))
##     Petal.Width
## 1           0.2
## 2           0.2
## 3           0.2
## 4           0.2
## 5           0.2
## 6           0.4
## 7           0.3
## 8           0.2
## 9           0.2
## 10          0.1
## 11          0.2
## 12          0.2
## 13          0.1
## 14          0.1
## 15          0.2
## 16          0.4
## 17          0.4
## 18          0.3
## 19          0.3
## 20          0.3
## 21          0.2
## 22          0.4
## 23          0.2
## 24          0.5
## 25          0.2
## 26          0.2
## 27          0.4
## 28          0.2
## 29          0.2
## 30          0.2
## 31          0.2
## 32          0.4
## 33          0.1
## 34          0.2
## 35          0.2
## 36          0.2
## 37          0.2
## 38          0.1
## 39          0.2
## 40          0.2
## 41          0.3
## 42          0.3
## 43          0.2
## 44          0.6
## 45          0.4
## 46          0.3
## 47          0.2
## 48          0.2
## 49          0.2
## 50          0.2
## 51          1.4
## 52          1.5
## 53          1.5
## 54          1.3
## 55          1.5
## 56          1.3
## 57          1.6
## 58          1.0
## 59          1.3
## 60          1.4
## 61          1.0
## 62          1.5
## 63          1.0
## 64          1.4
## 65          1.3
## 66          1.4
## 67          1.5
## 68          1.0
## 69          1.5
## 70          1.1
## 71          1.8
## 72          1.3
## 73          1.5
## 74          1.2
## 75          1.3
## 76          1.4
## 77          1.4
## 78          1.7
## 79          1.5
## 80          1.0
## 81          1.1
## 82          1.0
## 83          1.2
## 84          1.6
## 85          1.5
## 86          1.6
## 87          1.5
## 88          1.3
## 89          1.3
## 90          1.3
## 91          1.2
## 92          1.4
## 93          1.2
## 94          1.0
## 95          1.3
## 96          1.2
## 97          1.3
## 98          1.3
## 99          1.1
## 100         1.3
## 101         2.5
## 102         1.9
## 103         2.1
## 104         1.8
## 105         2.2
## 106         2.1
## 107         1.7
## 108         1.8
## 109         1.8
## 110         2.5
## 111         2.0
## 112         1.9
## 113         2.1
## 114         2.0
## 115         2.4
## 116         2.3
## 117         1.8
## 118         2.2
## 119         2.3
## 120         1.5
## 121         2.3
## 122         2.0
## 123         2.0
## 124         1.8
## 125         2.1
## 126         1.8
## 127         1.8
## 128         1.8
## 129         2.1
## 130         1.6
## 131         1.9
## 132         2.0
## 133         2.2
## 134         1.5
## 135         1.4
## 136         2.3
## 137         2.4
## 138         1.8
## 139         1.8
## 140         2.1
## 141         2.4
## 142         2.3
## 143         1.9
## 144         2.3
## 145         2.5
## 146         2.3
## 147         1.9
## 148         2.0
## 149         2.3
## 150         1.8
iris %>% select(starts_with("Petal") | ends_with("Width"))
##     Petal.Length Petal.Width Sepal.Width
## 1            1.4         0.2         3.5
## 2            1.4         0.2         3.0
## 3            1.3         0.2         3.2
## 4            1.5         0.2         3.1
## 5            1.4         0.2         3.6
## 6            1.7         0.4         3.9
## 7            1.4         0.3         3.4
## 8            1.5         0.2         3.4
## 9            1.4         0.2         2.9
## 10           1.5         0.1         3.1
## 11           1.5         0.2         3.7
## 12           1.6         0.2         3.4
## 13           1.4         0.1         3.0
## 14           1.1         0.1         3.0
## 15           1.2         0.2         4.0
## 16           1.5         0.4         4.4
## 17           1.3         0.4         3.9
## 18           1.4         0.3         3.5
## 19           1.7         0.3         3.8
## 20           1.5         0.3         3.8
## 21           1.7         0.2         3.4
## 22           1.5         0.4         3.7
## 23           1.0         0.2         3.6
## 24           1.7         0.5         3.3
## 25           1.9         0.2         3.4
## 26           1.6         0.2         3.0
## 27           1.6         0.4         3.4
## 28           1.5         0.2         3.5
## 29           1.4         0.2         3.4
## 30           1.6         0.2         3.2
## 31           1.6         0.2         3.1
## 32           1.5         0.4         3.4
## 33           1.5         0.1         4.1
## 34           1.4         0.2         4.2
## 35           1.5         0.2         3.1
## 36           1.2         0.2         3.2
## 37           1.3         0.2         3.5
## 38           1.4         0.1         3.6
## 39           1.3         0.2         3.0
## 40           1.5         0.2         3.4
## 41           1.3         0.3         3.5
## 42           1.3         0.3         2.3
## 43           1.3         0.2         3.2
## 44           1.6         0.6         3.5
## 45           1.9         0.4         3.8
## 46           1.4         0.3         3.0
## 47           1.6         0.2         3.8
## 48           1.4         0.2         3.2
## 49           1.5         0.2         3.7
## 50           1.4         0.2         3.3
## 51           4.7         1.4         3.2
## 52           4.5         1.5         3.2
## 53           4.9         1.5         3.1
## 54           4.0         1.3         2.3
## 55           4.6         1.5         2.8
## 56           4.5         1.3         2.8
## 57           4.7         1.6         3.3
## 58           3.3         1.0         2.4
## 59           4.6         1.3         2.9
## 60           3.9         1.4         2.7
## 61           3.5         1.0         2.0
## 62           4.2         1.5         3.0
## 63           4.0         1.0         2.2
## 64           4.7         1.4         2.9
## 65           3.6         1.3         2.9
## 66           4.4         1.4         3.1
## 67           4.5         1.5         3.0
## 68           4.1         1.0         2.7
## 69           4.5         1.5         2.2
## 70           3.9         1.1         2.5
## 71           4.8         1.8         3.2
## 72           4.0         1.3         2.8
## 73           4.9         1.5         2.5
## 74           4.7         1.2         2.8
## 75           4.3         1.3         2.9
## 76           4.4         1.4         3.0
## 77           4.8         1.4         2.8
## 78           5.0         1.7         3.0
## 79           4.5         1.5         2.9
## 80           3.5         1.0         2.6
## 81           3.8         1.1         2.4
## 82           3.7         1.0         2.4
## 83           3.9         1.2         2.7
## 84           5.1         1.6         2.7
## 85           4.5         1.5         3.0
## 86           4.5         1.6         3.4
## 87           4.7         1.5         3.1
## 88           4.4         1.3         2.3
## 89           4.1         1.3         3.0
## 90           4.0         1.3         2.5
## 91           4.4         1.2         2.6
## 92           4.6         1.4         3.0
## 93           4.0         1.2         2.6
## 94           3.3         1.0         2.3
## 95           4.2         1.3         2.7
## 96           4.2         1.2         3.0
## 97           4.2         1.3         2.9
## 98           4.3         1.3         2.9
## 99           3.0         1.1         2.5
## 100          4.1         1.3         2.8
## 101          6.0         2.5         3.3
## 102          5.1         1.9         2.7
## 103          5.9         2.1         3.0
## 104          5.6         1.8         2.9
## 105          5.8         2.2         3.0
## 106          6.6         2.1         3.0
## 107          4.5         1.7         2.5
## 108          6.3         1.8         2.9
## 109          5.8         1.8         2.5
## 110          6.1         2.5         3.6
## 111          5.1         2.0         3.2
## 112          5.3         1.9         2.7
## 113          5.5         2.1         3.0
## 114          5.0         2.0         2.5
## 115          5.1         2.4         2.8
## 116          5.3         2.3         3.2
## 117          5.5         1.8         3.0
## 118          6.7         2.2         3.8
## 119          6.9         2.3         2.6
## 120          5.0         1.5         2.2
## 121          5.7         2.3         3.2
## 122          4.9         2.0         2.8
## 123          6.7         2.0         2.8
## 124          4.9         1.8         2.7
## 125          5.7         2.1         3.3
## 126          6.0         1.8         3.2
## 127          4.8         1.8         2.8
## 128          4.9         1.8         3.0
## 129          5.6         2.1         2.8
## 130          5.8         1.6         3.0
## 131          6.1         1.9         2.8
## 132          6.4         2.0         3.8
## 133          5.6         2.2         2.8
## 134          5.1         1.5         2.8
## 135          5.6         1.4         2.6
## 136          6.1         2.3         3.0
## 137          5.6         2.4         3.4
## 138          5.5         1.8         3.1
## 139          4.8         1.8         3.0
## 140          5.4         2.1         3.1
## 141          5.6         2.4         3.1
## 142          5.1         2.3         3.1
## 143          5.1         1.9         2.7
## 144          5.9         2.3         3.2
## 145          5.7         2.5         3.3
## 146          5.2         2.3         3.0
## 147          5.0         1.9         2.5
## 148          5.2         2.0         3.0
## 149          5.4         2.3         3.4
## 150          5.1         1.8         3.0
iris %>% select(starts_with("Petal") & !ends_with("Width"))
##     Petal.Length
## 1            1.4
## 2            1.4
## 3            1.3
## 4            1.5
## 5            1.4
## 6            1.7
## 7            1.4
## 8            1.5
## 9            1.4
## 10           1.5
## 11           1.5
## 12           1.6
## 13           1.4
## 14           1.1
## 15           1.2
## 16           1.5
## 17           1.3
## 18           1.4
## 19           1.7
## 20           1.5
## 21           1.7
## 22           1.5
## 23           1.0
## 24           1.7
## 25           1.9
## 26           1.6
## 27           1.6
## 28           1.5
## 29           1.4
## 30           1.6
## 31           1.6
## 32           1.5
## 33           1.5
## 34           1.4
## 35           1.5
## 36           1.2
## 37           1.3
## 38           1.4
## 39           1.3
## 40           1.5
## 41           1.3
## 42           1.3
## 43           1.3
## 44           1.6
## 45           1.9
## 46           1.4
## 47           1.6
## 48           1.4
## 49           1.5
## 50           1.4
## 51           4.7
## 52           4.5
## 53           4.9
## 54           4.0
## 55           4.6
## 56           4.5
## 57           4.7
## 58           3.3
## 59           4.6
## 60           3.9
## 61           3.5
## 62           4.2
## 63           4.0
## 64           4.7
## 65           3.6
## 66           4.4
## 67           4.5
## 68           4.1
## 69           4.5
## 70           3.9
## 71           4.8
## 72           4.0
## 73           4.9
## 74           4.7
## 75           4.3
## 76           4.4
## 77           4.8
## 78           5.0
## 79           4.5
## 80           3.5
## 81           3.8
## 82           3.7
## 83           3.9
## 84           5.1
## 85           4.5
## 86           4.5
## 87           4.7
## 88           4.4
## 89           4.1
## 90           4.0
## 91           4.4
## 92           4.6
## 93           4.0
## 94           3.3
## 95           4.2
## 96           4.2
## 97           4.2
## 98           4.3
## 99           3.0
## 100          4.1
## 101          6.0
## 102          5.1
## 103          5.9
## 104          5.6
## 105          5.8
## 106          6.6
## 107          4.5
## 108          6.3
## 109          5.8
## 110          6.1
## 111          5.1
## 112          5.3
## 113          5.5
## 114          5.0
## 115          5.1
## 116          5.3
## 117          5.5
## 118          6.7
## 119          6.9
## 120          5.0
## 121          5.7
## 122          4.9
## 123          6.7
## 124          4.9
## 125          5.7
## 126          6.0
## 127          4.8
## 128          4.9
## 129          5.6
## 130          5.8
## 131          6.1
## 132          6.4
## 133          5.6
## 134          5.1
## 135          5.6
## 136          6.1
## 137          5.6
## 138          5.5
## 139          4.8
## 140          5.4
## 141          5.6
## 142          5.1
## 143          5.1
## 144          5.9
## 145          5.7
## 146          5.2
## 147          5.0
## 148          5.2
## 149          5.4
## 150          5.1
#kết quả: cho thấy lấy cái kết quả lớn nhất
## 1.2 Vẽ biểu đồ:
s <- subset(iris, Species=="setosa")
head(s)
##   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1          5.1         3.5          1.4         0.2  setosa
## 2          4.9         3.0          1.4         0.2  setosa
## 3          4.7         3.2          1.3         0.2  setosa
## 4          4.6         3.1          1.5         0.2  setosa
## 5          5.0         3.6          1.4         0.2  setosa
## 6          5.4         3.9          1.7         0.4  setosa
#Nhận xét: Có tất cả 6 giá trị phù hợp với đề bài yêu cầu

# Nối dữ liệu: 

df1 <- data.frame(Sepal.Length = c(1:6), Product = c(rep("setosa", 3), rep("versicolor", 3)))
head(df1)
##   Sepal.Length    Product
## 1            1     setosa
## 2            2     setosa
## 3            3     setosa
## 4            4 versicolor
## 5            5 versicolor
## 6            6 versicolor
df2 <- data.frame(Sepal.Length = c(1,3,5), Product = c(rep("setosa", 2), rep("versicolor", 1)))
df2
##   Sepal.Length    Product
## 1            1     setosa
## 2            3     setosa
## 3            5 versicolor
## Gộp các biến thành dữ liệu mới:

d2 <- iris$Petal.Length + iris$Petal.Width #gán biến d2 bằng giá trị của cánh hoa cộng với chiều rộng cánh hoa

d3 <- iris$Petal.Width + 0.5 #gán biến d3 bằng giá trị chiều rộng của cánh hoa cộng thêm một giá trị nào đó bất kì trong trường hợp này tôi đặt đại  0.5 
d4 <- data.frame(iris$Petal.Length,iris$Petal.Width ,d2) #nối tất cả các dữ liệu 
d5 <- data.frame(d4, d3) 
head(d5,4) #in cấu trúc dữ liệu ra
##   iris.Petal.Length iris.Petal.Width  d2  d3
## 1               1.4              0.2 1.6 0.7
## 2               1.4              0.2 1.6 0.7
## 3               1.3              0.2 1.5 0.7
## 4               1.5              0.2 1.7 0.7
## chia chiều dài cánh hoa thành 3 khoảng từ đó suy ra "dài", " ngắn" và "vừa"
iris$daicut[iris$Petal.Length>=8] <- "dài"
iris$daicut[iris$Petal.Length <8 & iris$Petal.Length >=7 ] <- "vừa"
iris$daicut[iris$Petal.Length <7] <- "ngắn"
head(iris,4)
##   Sepal.Length Sepal.Width Petal.Length Petal.Width Species daicut
## 1          5.1         3.5          1.4         0.2  setosa   ngắn
## 2          4.9         3.0          1.4         0.2  setosa   ngắn
## 3          4.7         3.2          1.3         0.2  setosa   ngắn
## 4          4.6         3.1          1.5         0.2  setosa   ngắn
# Tuần 2

Giống như tuần 1 thì chúng ta sử dụng lại dataset(CPS1985)

Lấy dữ liệu trong thư viện

```r
library(AER)

# Lấy dữ liệu dataset CPS1985 từ package AER để tiến hành phân tích

data("CPS1985")

# Gán dữ liệu CPS1985 cho h

h <- CPS1985

# Xem cấu trúc dữ liệu gốc

str(h)
## 'data.frame':    534 obs. of  11 variables:
##  $ wage      : num  5.1 4.95 6.67 4 7.5 ...
##  $ education : num  8 9 12 12 12 13 10 12 16 12 ...
##  $ experience: num  21 42 1 4 17 9 27 9 11 9 ...
##  $ age       : num  35 57 19 22 35 28 43 27 33 27 ...
##  $ ethnicity : Factor w/ 3 levels "cauc","hispanic",..: 2 1 1 1 1 1 1 1 1 1 ...
##  $ region    : Factor w/ 2 levels "south","other": 2 2 2 2 2 2 1 2 2 2 ...
##  $ gender    : Factor w/ 2 levels "male","female": 2 2 1 1 1 1 1 1 1 1 ...
##  $ occupation: Factor w/ 6 levels "worker","technical",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ sector    : Factor w/ 3 levels "manufacturing",..: 1 1 1 3 3 3 3 3 1 3 ...
##  $ union     : Factor w/ 2 levels "no","yes": 1 1 1 1 1 2 1 1 1 1 ...
##  $ married   : Factor w/ 2 levels "no","yes": 2 2 1 1 2 1 1 1 2 1 ...
# Xuất hiện 6 dòng đầu của cấu trúc

head(h)
##       wage education experience age ethnicity region gender occupation
## 1     5.10         8         21  35  hispanic  other female     worker
## 1100  4.95         9         42  57      cauc  other female     worker
## 2     6.67        12          1  19      cauc  other   male     worker
## 3     4.00        12          4  22      cauc  other   male     worker
## 4     7.50        12         17  35      cauc  other   male     worker
## 5    13.07        13          9  28      cauc  other   male     worker
##             sector union married
## 1    manufacturing    no     yes
## 1100 manufacturing    no     yes
## 2    manufacturing    no      no
## 3            other    no      no
## 4            other    no     yes
## 5            other   yes      no
# Xuất hiện 6 dòng cuối của cấu trúc

tail(h)
##      wage education experience age ethnicity region gender occupation
## 528 11.79        16          6  28      cauc  other female  technical
## 529 11.36        18          5  29      cauc  other   male  technical
## 530  6.10        12         33  51     other  other female  technical
## 531 23.25        17         25  48     other  other female  technical
## 532 19.88        12         13  31      cauc  south   male  technical
## 533 15.38        16         33  55      cauc  other   male  technical
##            sector union married
## 528         other   yes      no
## 529         other    no      no
## 530         other    no     yes
## 531         other   yes     yes
## 532         other   yes     yes
## 533 manufacturing    no     yes
# Các đại lượng đo lường trong thống kê:

# Biến lương

luong <- h$wage
luong
##   [1]  5.10  4.95  6.67  4.00  7.50 13.07  4.45 19.47 13.28  8.75 11.35 11.50
##  [13]  6.50  6.25 19.98  7.30  8.00 22.20  3.65 20.55  5.71  7.00  3.75  4.50
##  [25]  9.56  5.75  9.36  6.50  3.35  4.75  8.90  4.00  4.70  5.00  9.25 10.67
##  [37]  7.61 10.00  7.50 12.20  3.35 11.00 12.00  4.85  4.30  6.00 15.00  4.85
##  [49]  9.00  6.36  9.15 11.00  4.50  4.80  4.00  5.50  8.40  6.75 10.00  5.00
##  [61]  6.50 10.75  7.00 11.43  4.00  9.00 13.00 12.22  6.28  6.75  3.35 16.00
##  [73]  5.25  3.50  4.22  3.00  4.00 10.00  5.00 16.00 13.98 13.26  6.10  3.75
##  [85]  9.00  9.45  5.50  8.93  6.25  9.75  6.73  7.78  2.85  3.35 19.98  8.50
##  [97]  9.75 15.00  8.00 11.25 14.00 10.00  6.50  9.83 18.50 12.50 26.00 14.00
## [109] 10.50 11.00 12.47 12.50 15.00  6.00  9.50  5.00  3.75 12.57  6.88  5.50
## [121]  7.00  4.50  6.50 12.00  5.00  6.50  6.80  8.75  3.75  4.50  6.00  5.50
## [133] 13.00  5.65  4.80  7.00  5.25  3.35  8.50  6.00  6.75  8.89 14.21 10.78
## [145]  8.90  7.50  4.50 11.25 13.45  6.00  4.62 10.58  5.00  8.20  6.25  8.50
## [157] 24.98 16.65  6.25  4.55 11.25 21.25 12.65  7.50 10.25  3.35 13.45  4.84
## [169] 26.29  6.58 44.50 15.00 11.25  7.00 10.00 14.53 20.00 22.50  3.64 10.62
## [181] 24.98  6.00 19.00 13.20 22.50 15.00  6.88 11.84 16.14 13.95 13.16  5.30
## [193]  4.50 10.00 10.00 10.00  9.37  5.80 17.86  1.00  8.80  9.00 18.16  7.81
## [205] 10.62  4.50 17.25 10.50  9.22 15.00 22.50  4.55  9.00 13.33 15.00  7.50
## [217]  4.25 12.50  5.13  3.35 11.11  3.84  6.40  5.56 10.00  5.65 11.50  3.50
## [229]  3.35  4.75 19.98  3.50  4.00  7.00  6.25  4.50 14.29  5.00 13.75 13.71
## [241]  7.50  3.80  5.00  9.42  5.50  3.75  3.50  5.80 12.00  5.00  8.75 10.00
## [253]  8.50  8.63  9.00  5.50 11.11 10.00  5.20  8.00  3.56  5.20 11.67 11.32
## [265]  7.50  5.50  5.00  7.75  5.25  9.00  9.65  5.21  7.00 12.16  5.25 10.32
## [277]  3.35  7.70  9.17  8.43  4.00  4.13  3.00  4.25  7.53 10.53  5.00 15.03
## [289] 11.25  6.25  3.50  6.85 12.50 12.00  6.00  9.50  4.10 10.43  5.00  7.69
## [301]  5.50  6.40 12.50  6.25  8.00  9.60  9.10  7.50  5.00  7.00  3.55  8.50
## [313]  4.50  7.88  5.25  5.00  9.33 10.50  7.50  9.50  9.60  5.87 11.02  5.00
## [325]  5.62 12.50 10.81  5.40  7.00  4.59  6.00 11.71  5.62  5.50  4.85  6.75
## [337]  4.25  5.75  3.50  3.35 10.62  8.00  4.75  8.50  8.85  8.00  6.00  7.14
## [349]  3.40  6.00  3.75  8.89  4.35 13.10  4.35  3.50  3.80  5.26  3.35 16.26
## [361]  4.25  4.50  8.00  4.00  7.96  4.00  4.15  5.95  3.60  8.75  3.40  4.28
## [373]  5.35  5.00  7.65  6.94  7.50  3.60  1.75  3.45  9.63  8.49  8.99  3.65
## [385]  3.50  3.43  5.50  6.93  3.51  3.75  4.17  9.57 14.67 12.50  5.50  5.15
## [397]  8.00  5.83  3.35  7.00 10.00  8.00  6.88  5.55  7.50  8.93  9.00  3.50
## [409]  5.77 25.00  6.85  6.50  3.75  3.50  4.50  2.01  4.17 13.00  3.98  7.50
## [421] 13.12  4.00  3.95 13.00  9.00  4.55  9.50  4.50  8.75 10.00 18.00 24.98
## [433] 12.05 22.00  8.75 22.20 17.25  6.00  8.06  9.24 12.00 10.61  5.71 10.00
## [445] 17.50 15.00  7.78  7.80 10.00 24.98 10.28 15.00 12.00 10.58  5.85 11.22
## [457]  8.56 13.89  5.71 15.79  7.50 11.25  6.15 13.45  6.25  6.50 12.00  8.50
## [469]  8.00  5.75 15.73  9.86 13.51  5.40  6.25  5.50  5.00  6.25  5.75 20.50
## [481]  5.00  7.00 18.00 12.00 20.40 22.20 16.42  8.63 19.38 14.00 10.00 15.95
## [493] 20.00 10.00 24.98 11.25 22.83 10.20 10.00 14.00 12.50  5.79 24.98  4.35
## [505] 11.25  6.67  8.00 18.16 12.00  8.89  9.50 13.65 12.00 15.00 12.67  7.38
## [517] 15.56  7.45  6.25  6.25  9.37 22.50  7.50  7.00  5.75  7.67 12.50 16.00
## [529] 11.79 11.36  6.10 23.25 19.88 15.38
mean(luong)
## [1] 9.024064
# Nhận xét lương trung bình của một người là 9.024064 (đv)

# Tính lương trung bình theo giới tính:

aggregate(h$wage, list(h$gender), FUN = "mean")
##   Group.1        x
## 1    male 9.994913
## 2  female 7.878857
# Nhận xét: ta có sự chênh lệch số lương nam nhiều hơn nữ là 2.120273 đơn vị, số lương trung bình của nam là 9.994913 đơn vị và lương trung bình của nữ là 7.878857 đơn vị

#Độ lệch chuẩn

sd(h$wage)
## [1] 5.139097
# Phương sai

var(h$wage)
## [1] 26.41032
# Cắt dữ liệu trong bộ dữ liệu

quantile(h$wage,0.5)
##  50% 
## 7.78
# Nhận xét: ta có phần tử trung vị bằng 7.78 đv

hist(h$wage)

# Biến tuổi:

tuoi <- h$age
tuoi
##   [1] 35 57 19 22 35 28 43 27 33 27 35 37 41 45 44 55 57 44 33 51 34 55 27 31 41
##  [26] 57 26 46 26 26 33 64 33 24 37 54 38 53 21 30 18 34 32 31 27 28 34 29 47 27
##  [51] 25 35 25 34 19 29 36 29 40 46 34 42 64 21 24 43 37 37 56 57 20 40 31 22 53
##  [76] 55 42 29 30 53 34 34 60 35 27 31 35 36 24 54 20 41 19 28 41 26 30 51 37 33
## [101] 30 28 26 41 33 27 41 55 22 56 29 29 58 26 46 25 28 30 36 30 25 33 46 38 24
## [126] 23 45 37 24 34 19 21 26 22 31 25 20 56 53 27 30 36 32 45 43 56 21 59 34 26
## [151] 45 45 23 37 19 31 40 41 22 22 48 51 36 35 46 31 30 22 55 42 21 60 25 50 42
## [176] 40 43 33 60 52 53 30 37 32 44 32 38 44 36 38 56 32 25 37 36 29 48 36 55 42
## [201] 61 29 37 19 28 21 52 33 33 48 38 52 34 34 42 22 47 61 23 36 46 42 63 25 38
## [226] 28 38 50 21 28 64 26 33 23 23 34 52 32 41 61 45 22 20 50 38 25 52 24 36 37
## [251] 29 29 43 36 49 24 32 44 37 35 30 42 61 31 34 41 26 42 63 38 56 34 33 50 24
## [276] 47 25 27 62 30 26 22 46 19 21 32 57 42 55 26 43 26 35 23 50 43 33 35 18 37
## [301] 39 24 32 49 26 48 35 38 25 28 20 20 19 39 26 22 33 47 41 57 32 29 32 44 52
## [326] 27 58 36 29 54 37 64 21 51 32 40 38 33 53 25 63 27 20 26 39 32 64 37 43 47
## [351] 24 43 37 54 51 63 34 52 20 32 20 43 34 42 32 25 21 28 61 35 63 56 31 32 38
## [376] 25 27 24 23 20 42 42 33 25 34 20 38 44 53 59 45 23 36 39 28 20 61 22 18 44
## [401] 41 33 30 62 20 61 28 49 25 24 54 56 35 62 19 19 44 43 26 28 51 30 27 35 28
## [426] 59 61 27 53 53 39 54 28 35 48 32 29 26 36 27 30 54 27 18 35 36 28 30 36 28
## [451] 31 35 47 31 36 43 34 39 31 31 44 46 38 38 29 29 29 34 57 39 26 34 38 32 38
## [476] 51 22 51 21 36 20 57 60 42 26 64 39 24 33 38 42 36 50 32 27 26 61 49 26 55
## [501] 36 60 41 21 33 32 39 31 36 44 37 33 47 57 37 35 32 43 32 29 30 39 32 25 49
## [526] 32 31 30 28 29 51 48 31 55
mean(tuoi)
## [1] 36.83333
# Nhận xét: Sau khi tính trung bình của 534 phần tử thì chúng ta thấy số tuổi trung bình của mọi người là 36.83333
median(tuoi)
## [1] 35
# Nhận xét: phần tử trung vị là 35 tuổi nghĩa là đây là giá trị nằm giữa của phần nhỏ hơn và lớn hơn

# Lập bảng tần số và vẽ đồ thị lương và tuổi 

tuoi1 <- cut(tuoi, breaks = c(0, 20, 40,60), labels = c("0-20", "20-40", "40-60"), right = TRUE)
table(tuoi1)
## tuoi1
##  0-20 20-40 40-60 
##    28   325   158
# Nhận xét: Tuổi trong khoảng từ 20-40 chiếm tỷ lệ rất lớn 63,6%, trong độ tuổi 40-60 chiếm tỷ lệ vừa phải 30,92% và độ tuổi từ 0-20 chiếm tỷ lệ thấp 5,48%

luong1 <- cut(luong, breaks =c(3, 5, 7,10), labels = c("thấp", "trung bình", "cao"), right = TRUE)
luong1
##   [1] trung bình thấp       trung bình thấp       cao        <NA>      
##   [7] thấp       <NA>       <NA>       cao        <NA>       <NA>      
##  [13] trung bình trung bình <NA>       cao        cao        <NA>      
##  [19] thấp       <NA>       trung bình trung bình thấp       thấp      
##  [25] cao        trung bình cao        trung bình thấp       thấp      
##  [31] cao        thấp       thấp       thấp       cao        <NA>      
##  [37] cao        cao        cao        <NA>       thấp       <NA>      
##  [43] <NA>       thấp       thấp       trung bình <NA>       thấp      
##  [49] cao        trung bình cao        <NA>       thấp       thấp      
##  [55] thấp       trung bình cao        trung bình cao        thấp      
##  [61] trung bình <NA>       trung bình <NA>       thấp       cao       
##  [67] <NA>       <NA>       trung bình trung bình thấp       <NA>      
##  [73] trung bình thấp       thấp       <NA>       thấp       cao       
##  [79] thấp       <NA>       <NA>       <NA>       trung bình thấp      
##  [85] cao        cao        trung bình cao        trung bình cao       
##  [91] trung bình cao        <NA>       thấp       <NA>       cao       
##  [97] cao        <NA>       cao        <NA>       <NA>       cao       
## [103] trung bình cao        <NA>       <NA>       <NA>       <NA>      
## [109] <NA>       <NA>       <NA>       <NA>       <NA>       trung bình
## [115] cao        thấp       thấp       <NA>       trung bình trung bình
## [121] trung bình thấp       trung bình <NA>       thấp       trung bình
## [127] trung bình cao        thấp       thấp       trung bình trung bình
## [133] <NA>       trung bình thấp       trung bình trung bình thấp      
## [139] cao        trung bình trung bình cao        <NA>       <NA>      
## [145] cao        cao        thấp       <NA>       <NA>       trung bình
## [151] thấp       <NA>       thấp       cao        trung bình cao       
## [157] <NA>       <NA>       trung bình thấp       <NA>       <NA>      
## [163] <NA>       cao        <NA>       thấp       <NA>       thấp      
## [169] <NA>       trung bình <NA>       <NA>       <NA>       trung bình
## [175] cao        <NA>       <NA>       <NA>       thấp       <NA>      
## [181] <NA>       trung bình <NA>       <NA>       <NA>       <NA>      
## [187] trung bình <NA>       <NA>       <NA>       <NA>       trung bình
## [193] thấp       cao        cao        cao        cao        trung bình
## [199] <NA>       <NA>       cao        cao        <NA>       cao       
## [205] <NA>       thấp       <NA>       <NA>       cao        <NA>      
## [211] <NA>       thấp       cao        <NA>       <NA>       cao       
## [217] thấp       <NA>       trung bình thấp       <NA>       thấp      
## [223] trung bình trung bình cao        trung bình <NA>       thấp      
## [229] thấp       thấp       <NA>       thấp       thấp       trung bình
## [235] trung bình thấp       <NA>       thấp       <NA>       <NA>      
## [241] cao        thấp       thấp       cao        trung bình thấp      
## [247] thấp       trung bình <NA>       thấp       cao        cao       
## [253] cao        cao        cao        trung bình <NA>       cao       
## [259] trung bình cao        thấp       trung bình <NA>       <NA>      
## [265] cao        trung bình thấp       cao        trung bình cao       
## [271] cao        trung bình trung bình <NA>       trung bình <NA>      
## [277] thấp       cao        cao        cao        thấp       thấp      
## [283] <NA>       thấp       cao        <NA>       thấp       <NA>      
## [289] <NA>       trung bình thấp       trung bình <NA>       <NA>      
## [295] trung bình cao        thấp       <NA>       thấp       cao       
## [301] trung bình trung bình <NA>       trung bình cao        cao       
## [307] cao        cao        thấp       trung bình thấp       cao       
## [313] thấp       cao        trung bình thấp       cao        <NA>      
## [319] cao        cao        cao        trung bình <NA>       thấp      
## [325] trung bình <NA>       <NA>       trung bình trung bình thấp      
## [331] trung bình <NA>       trung bình trung bình thấp       trung bình
## [337] thấp       trung bình thấp       thấp       <NA>       cao       
## [343] thấp       cao        cao        cao        trung bình cao       
## [349] thấp       trung bình thấp       cao        thấp       <NA>      
## [355] thấp       thấp       thấp       trung bình thấp       <NA>      
## [361] thấp       thấp       cao        thấp       cao        thấp      
## [367] thấp       trung bình thấp       cao        thấp       thấp      
## [373] trung bình thấp       cao        trung bình cao        thấp      
## [379] <NA>       thấp       cao        cao        cao        thấp      
## [385] thấp       thấp       trung bình trung bình thấp       thấp      
## [391] thấp       cao        <NA>       <NA>       trung bình trung bình
## [397] cao        trung bình thấp       trung bình cao        cao       
## [403] trung bình trung bình cao        cao        cao        thấp      
## [409] trung bình <NA>       trung bình trung bình thấp       thấp      
## [415] thấp       <NA>       thấp       <NA>       thấp       cao       
## [421] <NA>       thấp       thấp       <NA>       cao        thấp      
## [427] cao        thấp       cao        cao        <NA>       <NA>      
## [433] <NA>       <NA>       cao        <NA>       <NA>       trung bình
## [439] cao        cao        <NA>       <NA>       trung bình cao       
## [445] <NA>       <NA>       cao        cao        cao        <NA>      
## [451] <NA>       <NA>       <NA>       <NA>       trung bình <NA>      
## [457] cao        <NA>       trung bình <NA>       cao        <NA>      
## [463] trung bình <NA>       trung bình trung bình <NA>       cao       
## [469] cao        trung bình <NA>       cao        <NA>       trung bình
## [475] trung bình trung bình thấp       trung bình trung bình <NA>      
## [481] thấp       trung bình <NA>       <NA>       <NA>       <NA>      
## [487] <NA>       cao        <NA>       <NA>       cao        <NA>      
## [493] <NA>       cao        <NA>       <NA>       <NA>       <NA>      
## [499] cao        <NA>       <NA>       trung bình <NA>       thấp      
## [505] <NA>       trung bình cao        <NA>       <NA>       cao       
## [511] cao        <NA>       <NA>       <NA>       <NA>       cao       
## [517] <NA>       cao        trung bình trung bình cao        <NA>      
## [523] cao        trung bình trung bình cao        <NA>       <NA>      
## [529] <NA>       <NA>       trung bình <NA>       <NA>       <NA>      
## Levels: thấp trung bình cao
barplot(tuoi, xlab = " ", ylab = "Tuổi", main = "Biểu đồ thể hiện dữ liệu của biến tuổi ", col =  c("red", "green", "blue", "pink", "white"))

barplot(luong, xlab = " ", ylab = "Lương", main = "Biểu đồ thể hiện dữ liệu của biến lương ", col =  c("red", "green", "blue", "pink", "white"))

# Kết họp lại giữa tuổi và lương:

f = table(tuoi,luong1)
f
##     luong1
## tuoi thấp trung bình cao
##   18    3          0   1
##   19    4          3   1
##   20    9          3   2
##   21    5          3   2
##   22    8          3   1
##   23    1          4   1
##   24    6          5   1
##   25    9          6   1
##   26    6          7   5
##   27    4          3   6
##   28    3          5   5
##   29    1          7   5
##   30    3          4   4
##   31    4          3   2
##   32    3          4   6
##   33    5          2   5
##   34    5          3   6
##   35    2          2   6
##   36    1          4   7
##   37    2          2   8
##   38    1          5   5
##   39    0          2   3
##   40    0          1   1
##   41    0          2   5
##   42    3          2   5
##   43    4          0   6
##   44    2          2   3
##   45    2          2   1
##   46    1          2   1
##   47    1          1   1
##   48    0          0   3
##   49    1          2   1
##   50    1          2   1
##   51    1          4   0
##   52    2          2   0
##   53    3          0   4
##   54    1          1   1
##   55    0          1   1
##   56    2          2   2
##   57    2          3   3
##   58    0          0   0
##   59    2          0   0
##   60    1          2   0
##   61    1          0   4
##   62    1          1   1
##   63    2          2   0
##   64    1          2   0

#Kiểm định Chi Bình Phương giữa 2 biến

#chúng ta có thể sử dụng kiểm định H0 và H1 với alpha bằng 0.5 để kiểm ra giá trị p- value xem nó có thể thỏa mãn đươc đề bài không

chisq.test(luong, tuoi, correct=FALSE)

#Với alpha bằng 5%, p-value =0.729> alpha bằng 5%. Ta có thể kết luận là 2 biến này độc lập với nhau

#Lương theo giới tính f1 = table(luong,gioitinh) f1

#Sử dụng Chi bình phương để xác định sự phụ thuộc của 2 biến

chisq.test(luong, gioitinh, correct=FALSE)

data: luong and gioitinh X-squared = 270.1, df = 237, p-value = 0.06876

#Nhận xét: với p-value=0.06876> alpha =5% bác bỏ H0, Kết luận lương ảnh hưởng đến giới tính.




# Tuần 1

# Giải thích dữ liệu

Dữ liệu chéo bắt nguồn từ Khảo sát dân số hiện tại tháng 5 năm 1985 của cục Điều tra dân số Hoa Kỳ  (mẫu ngẫu nhiên rút ra cho Berndt 1991).

Wage: Lương (tính bằng đô la mỗi giờ)

Education: Trình độ học vấn

Experience: Số năm kinh nghiệm làm việc

Age: tuổi tính bằng năm

ethnicity: Yếu tố dân tộc với các cấp độ "cauc", "hispanic", "other".


Region Factor (khu vực sinh sống):  có sống ở Miền Nam hay không?

gender: yếu tố chỉ giới tính


Occupation factor: Yếu tố nghề nghiệp với các mức độ "công nhân" (thợ hoặc công nhân dây chuyền lắp ráp), "kỹ thuật" , (nhân viên phục vụ), văn phòng và nhân viên văn thư,(nhân viên bán hàng), (quản lý và điều hành).

Sector :  Yếu tố với các cấp độ "chế tạo" (chế tạo hoặc khai khoáng), "xây dựng", "khác".

union Factor: Cá nhân có làm công việc đoàn thể không?

married Factor: Cá nhân đã kết hôn chưa?

#Phân tích dữ liệu SPS1985 từ package "AER" để có dữ liệu chúng ta vào library() để tìm dữ liệu của package AER sau đó thì tìm dataset (CPS1985) 

```r
#Lấy dữ liệu trong thư viện
library(AER)
#Lấy dữ liệu dataset CPS1985 từ package AER để tiến hành phân tích 
data("CPS1985")
#Gán dữ liệu CPS1985 cho h
h <- CPS1985
#xem cấu trúc dữ liệu gốc
str(h)
## 'data.frame':    534 obs. of  11 variables:
##  $ wage      : num  5.1 4.95 6.67 4 7.5 ...
##  $ education : num  8 9 12 12 12 13 10 12 16 12 ...
##  $ experience: num  21 42 1 4 17 9 27 9 11 9 ...
##  $ age       : num  35 57 19 22 35 28 43 27 33 27 ...
##  $ ethnicity : Factor w/ 3 levels "cauc","hispanic",..: 2 1 1 1 1 1 1 1 1 1 ...
##  $ region    : Factor w/ 2 levels "south","other": 2 2 2 2 2 2 1 2 2 2 ...
##  $ gender    : Factor w/ 2 levels "male","female": 2 2 1 1 1 1 1 1 1 1 ...
##  $ occupation: Factor w/ 6 levels "worker","technical",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ sector    : Factor w/ 3 levels "manufacturing",..: 1 1 1 3 3 3 3 3 1 3 ...
##  $ union     : Factor w/ 2 levels "no","yes": 1 1 1 1 1 2 1 1 1 1 ...
##  $ married   : Factor w/ 2 levels "no","yes": 2 2 1 1 2 1 1 1 2 1 ...
#Xuất hiện 6 dòng đầu của cấu trúc
head(h) 
##       wage education experience age ethnicity region gender occupation
## 1     5.10         8         21  35  hispanic  other female     worker
## 1100  4.95         9         42  57      cauc  other female     worker
## 2     6.67        12          1  19      cauc  other   male     worker
## 3     4.00        12          4  22      cauc  other   male     worker
## 4     7.50        12         17  35      cauc  other   male     worker
## 5    13.07        13          9  28      cauc  other   male     worker
##             sector union married
## 1    manufacturing    no     yes
## 1100 manufacturing    no     yes
## 2    manufacturing    no      no
## 3            other    no      no
## 4            other    no     yes
## 5            other   yes      no
#Xuất hiện 6 dòng cuối của cáy trúc
tail(h)
##      wage education experience age ethnicity region gender occupation
## 528 11.79        16          6  28      cauc  other female  technical
## 529 11.36        18          5  29      cauc  other   male  technical
## 530  6.10        12         33  51     other  other female  technical
## 531 23.25        17         25  48     other  other female  technical
## 532 19.88        12         13  31      cauc  south   male  technical
## 533 15.38        16         33  55      cauc  other   male  technical
##            sector union married
## 528         other   yes      no
## 529         other    no      no
## 530         other    no     yes
## 531         other   yes     yes
## 532         other   yes     yes
## 533 manufacturing    no     yes
## Chọn 3 dữ liệu để phân tích: Tuổi(Age), Trình độ học vấn (Education) và giới tính (gender)
# Gán biến age thành Tuoi, education thành hocvan và gender là gioitinh
Tuoi <-h$age
hocvan<- h$education
gioitinh <- h$gender
#Lọc dữ liệu có điều kiện:
th <- h[gioitinh =="male" & hocvan == "12",]
th
##      wage education experience age ethnicity region gender occupation
## 2    6.67        12          1  19      cauc  other   male     worker
## 3    4.00        12          4  22      cauc  other   male     worker
## 4    7.50        12         17  35      cauc  other   male     worker
## 7   19.47        12          9  27      cauc  other   male     worker
## 9    8.75        12          9  27      cauc  other   male     worker
## 10  11.35        12         17  35      cauc  other   male     worker
## 11  11.50        12         19  37      cauc  other   male     worker
## 15   7.30        12         37  55      cauc  other   male     worker
## 17  22.20        12         26  44      cauc  other   male     worker
## 19  20.55        12         33  51      cauc  other   male     worker
## 22   3.75        12          9  27      cauc  other   male     worker
## 24   9.56        12         23  41      cauc  other   male     worker
## 26   9.36        12          8  26      cauc  other   male     worker
## 29   4.75        12          8  26      cauc  other   male     worker
## 34   9.25        12         19  37      cauc  other   male     worker
## 35  10.67        12         36  54     other  other   male     worker
## 36   7.61        12         20  38     other  south   male     worker
## 37  10.00        12         35  53     other  other   male     worker
## 38   7.50        12          3  21      cauc  other   male     worker
## 40   3.35        12          0  18      cauc  other   male     worker
## 42  12.00        12         14  32      cauc  other   male     worker
## 49   6.36        12          9  27      cauc  other   male     worker
## 50   9.15        12          7  25      cauc  other   male     worker
## 58  10.00        12         22  40     other  other   male     worker
## 61  10.75        12         24  42      cauc  other   male     worker
## 63  11.43        12          3  21      cauc  south   male     worker
## 64   4.00        12          6  24     other  other   male     worker
## 66  13.00        12         19  37     other  south   male     worker
## 67  12.22        12         19  37      cauc  other   male     worker
## 77  10.00        12         11  29      cauc  other   male     worker
## 78   5.00        12         12  30     other  other   male     worker
## 79  16.00        12         35  53      cauc  south   male     worker
## 81  13.26        12         16  34      cauc  other   male     worker
## 85   9.45        12         13  31      cauc  other   male     worker
## 90   6.73        12          2  20      cauc  south   male     worker
## 91   7.78        12         23  41      cauc  other   male     worker
## 92   2.85        12          1  19      cauc  other   male     worker
## 94  19.98        12         23  41      cauc  other   male     worker
## 95   8.50        12          8  26     other  other   male     worker
## 97  15.00        12         33  51      cauc  other   male     worker
## 102  6.50        12          8  26      cauc  other   male     worker
## 103  9.83        12         23  41      cauc  other   male     worker
## 105 12.50        12          9  27      cauc  south   male     worker
## 108 10.50        12          4  22      cauc  other   male     worker
## 111 12.50        12         11  29      cauc  other   male     worker
## 112 15.00        12         40  58      cauc  other   male     worker
## 113  6.00        12          8  26      cauc  other   male     worker
## 117 12.57        12         12  30      cauc  other   male     worker
## 119  5.50        12         12  30      cauc  other   male     worker
## 120  7.00        12          7  25      cauc  other   male     worker
## 122  6.50        12         28  46      cauc  other   male     worker
## 123 12.00        12         20  38      cauc  south   male     worker
## 124  5.00        12          6  24      cauc  south   male     worker
## 125  6.50        12          5  23      cauc  south   male     worker
## 129  4.50        12         16  34  hispanic  south   male     worker
## 130  6.00        12          1  19  hispanic  south   male     worker
## 131  5.50        12          3  21      cauc  other   male     worker
## 132 13.00        12          8  26      cauc  other   male     worker
## 136  5.25        12          2  20      cauc  other   male     worker
## 139  6.00        12          9  27      cauc  other   male     worker
## 140  6.75        12         12  30      cauc  south   male     worker
## 141  8.89        12         18  36      cauc  other   male     worker
## 145  7.50        12         38  56      cauc  south   male     worker
## 147 11.25        12         41  59      cauc  other   male     worker
## 148 13.45        12         16  34      cauc  south   male     worker
## 152  5.00        12          5  23      cauc  south   male     worker
## 154  6.25        12          1  19      cauc  south   male     worker
## 155  8.50        12         13  31      cauc  other   male     worker
## 163  7.50        12         17  35      cauc  other   male management
## 171 15.00        12         42  60      cauc  other   male management
## 179 10.62        12         34  52      cauc  south   male management
## 187 11.84        12         26  44      cauc  other   male management
## 191  5.30        12         14  32     other  south   male management
## 199  1.00        12         24  42      cauc  other   male management
## 212  9.00        12         16  34      cauc  other   male      sales
## 217 12.50        12         43  61      cauc  other   male      sales
## 220 11.11        12         28  46      cauc  south   male      sales
## 224 10.00        12         20  38      cauc  south   male      sales
## 233  7.00        12          5  23      cauc  other   male      sales
## 239 13.71        12         43  61      cauc  other   male      sales
## 243  9.42        12         32  50      cauc  south   male      sales
## 244  5.50        12         20  38      cauc  other   male      sales
## 246  3.50        12         34  52      cauc  other   male      sales
## 269  9.00        12         20  38      cauc  other   male     office
## 279  8.43        12         12  30      cauc  south   male     office
## 280  4.00        12          8  26     other  south   male     office
## 291  6.85        12          8  26     other  other   male     office
## 293 12.00        12          5  23      cauc  south   male     office
## 299  7.69        12         19  37      cauc  other   male     office
## 311  8.50        12          2  20     other  south   male     office
## 315  5.00        12          4  22      cauc  south   male     office
## 335  6.75        12         22  40      cauc  other   male     office
## 338  3.50        12         35  53      cauc  other   male     office
## 359 16.26        12         14  32     other  other   male   services
## 365  4.00        12          7  25  hispanic  south   male   services
## 374  7.65        12         20  38      cauc  other   male   services
## 385  3.43        12          2  20     other  south   male   services
## 386  5.50        12         20  38      cauc  south   male   services
## 387  6.93        12         26  44      cauc  other   male   services
## 394  5.50        12         10  28      cauc  other   male   services
## 417 13.00        12         25  43     other  other   male   services
## 421  4.00        12         12  30      cauc  other   male   services
## 424  9.00        12         10  28      cauc  other   male   services
## 434  8.75        12         30  48      cauc  other   male  technical
## 476  5.00        12          4  22  hispanic  other   male  technical
## 478  5.75        12          3  21      cauc  other   male  technical
## 513 15.00        12         39  57      cauc  other   male  technical
## 527 16.00        12         12  30      cauc  south   male  technical
## 532 19.88        12         13  31      cauc  south   male  technical
##            sector union married
## 2   manufacturing    no      no
## 3           other    no      no
## 4           other    no     yes
## 7           other    no      no
## 9           other    no      no
## 10          other   yes     yes
## 11  manufacturing   yes      no
## 15   construction    no     yes
## 17  manufacturing   yes     yes
## 19          other    no     yes
## 22          other    no      no
## 24          other    no     yes
## 26  manufacturing    no     yes
## 29          other    no     yes
## 34  manufacturing    no      no
## 35          other    no      no
## 36   construction    no     yes
## 37   construction   yes     yes
## 38          other    no      no
## 40          other    no      no
## 42  manufacturing    no     yes
## 49  manufacturing    no     yes
## 50          other    no     yes
## 58  manufacturing   yes      no
## 61   construction   yes     yes
## 63   construction    no      no
## 64  manufacturing   yes      no
## 66  manufacturing   yes     yes
## 67   construction   yes     yes
## 77          other   yes     yes
## 78          other    no     yes
## 79  manufacturing   yes     yes
## 81          other   yes     yes
## 85  manufacturing    no      no
## 90  manufacturing    no     yes
## 91  manufacturing    no     yes
## 92          other    no      no
## 94  manufacturing    no     yes
## 95          other   yes     yes
## 97   construction   yes     yes
## 102         other    no      no
## 103 manufacturing    no     yes
## 105         other    no     yes
## 108         other   yes     yes
## 111  construction    no      no
## 112  construction   yes     yes
## 113  construction    no      no
## 117         other   yes     yes
## 119         other    no     yes
## 120         other   yes     yes
## 122         other    no     yes
## 123 manufacturing   yes     yes
## 124  construction    no      no
## 125 manufacturing    no      no
## 129         other    no      no
## 130         other   yes      no
## 131 manufacturing    no      no
## 132         other    no     yes
## 136         other    no      no
## 139         other    no     yes
## 140         other    no     yes
## 141 manufacturing    no     yes
## 145         other    no     yes
## 147         other   yes     yes
## 148         other   yes     yes
## 152         other    no     yes
## 154         other    no      no
## 155 manufacturing    no     yes
## 163         other    no      no
## 171 manufacturing    no     yes
## 179         other    no     yes
## 187         other    no     yes
## 191         other    no     yes
## 199         other    no     yes
## 212         other    no     yes
## 217 manufacturing    no     yes
## 220         other    no     yes
## 224 manufacturing    no     yes
## 233         other    no     yes
## 239         other   yes     yes
## 243         other    no     yes
## 244         other    no     yes
## 246         other    no     yes
## 269         other   yes     yes
## 279         other    no     yes
## 280         other    no     yes
## 291         other    no      no
## 293         other    no      no
## 299         other    no     yes
## 311         other    no      no
## 315         other    no      no
## 335         other    no      no
## 338         other    no     yes
## 359         other   yes      no
## 365         other    no      no
## 374         other    no      no
## 385         other    no      no
## 386         other    no     yes
## 387         other   yes     yes
## 394         other    no     yes
## 417         other   yes     yes
## 421         other    no      no
## 424         other    no     yes
## 434         other    no     yes
## 476         other    no      no
## 478         other    no     yes
## 513         other   yes     yes
## 527         other    no     yes
## 532         other   yes     yes
#Nhận xét: Sau khi lọc dữ liệu thì tìm thấy có 109 người có giới tính nam và thỏa điều kiện học lớp 12 chiếm 20,41%
#Lập bảng tần số của biến trình độ học vấn theo độ tuổi 

#Sử dụng dữ liệu trong package "ggplot2" cho biến giới tuổi và trình độ học vấn

library(ggplot2)
barplot(hocvan, xlab = " ", ylab = "học vấn", main = "Biểu đồ thể hiện dữ liệu của biến học vấn ", col =  c("red", "green", "blue", "pink", "white"))

barplot(Tuoi, xlab = "", ylab = "Tuổi",  main = "Biểu đồ thể hiện dữ liệu của biến Tuổi", col = c("red", "green", "blue", "pink", "white"))

#Xử lý dữ liệu
#Lọc dữ liệu:
hocvan10_12 <- hocvan[hocvan>10 & hocvan<12]
hocvan10_12
##  [1] 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11
## [26] 11 11
#Sắp xếp dữ liệu theo trình độ chuyên môn tăng dần
trinhdotang = h[order(h$occupation),]
trinhdotang
##       wage education experience age ethnicity region gender occupation
## 1     5.10         8         21  35  hispanic  other female     worker
## 1100  4.95         9         42  57      cauc  other female     worker
## 2     6.67        12          1  19      cauc  other   male     worker
## 3     4.00        12          4  22      cauc  other   male     worker
## 4     7.50        12         17  35      cauc  other   male     worker
## 5    13.07        13          9  28      cauc  other   male     worker
## 6     4.45        10         27  43      cauc  south   male     worker
## 7    19.47        12          9  27      cauc  other   male     worker
## 8    13.28        16         11  33      cauc  other   male     worker
## 9     8.75        12          9  27      cauc  other   male     worker
## 10   11.35        12         17  35      cauc  other   male     worker
## 11   11.50        12         19  37      cauc  other   male     worker
## 12    6.50         8         27  41      cauc  south   male     worker
## 13    6.25         9         30  45      cauc  south   male     worker
## 14   19.98         9         29  44      cauc  south   male     worker
## 15    7.30        12         37  55      cauc  other   male     worker
## 16    8.00         7         44  57      cauc  south   male     worker
## 17   22.20        12         26  44      cauc  other   male     worker
## 18    3.65        11         16  33      cauc  other   male     worker
## 19   20.55        12         33  51      cauc  other   male     worker
## 20    5.71        12         16  34      cauc  other female     worker
## 21    7.00         7         42  55     other  other   male     worker
## 22    3.75        12          9  27      cauc  other   male     worker
## 23    4.50        11         14  31     other  south   male     worker
## 24    9.56        12         23  41      cauc  other   male     worker
## 25    5.75         6         45  57      cauc  south   male     worker
## 26    9.36        12          8  26      cauc  other   male     worker
## 27    6.50        10         30  46      cauc  other   male     worker
## 28    3.35        12          8  26      cauc  other female     worker
## 29    4.75        12          8  26      cauc  other   male     worker
## 30    8.90        14         13  33      cauc  other   male     worker
## 31    4.00        12         46  64      cauc  south female     worker
## 32    4.70         8         19  33      cauc  other   male     worker
## 33    5.00        17          1  24      cauc  south female     worker
## 34    9.25        12         19  37      cauc  other   male     worker
## 35   10.67        12         36  54     other  other   male     worker
## 36    7.61        12         20  38     other  south   male     worker
## 37   10.00        12         35  53     other  other   male     worker
## 38    7.50        12          3  21      cauc  other   male     worker
## 39   12.20        14         10  30      cauc  south   male     worker
## 40    3.35        12          0  18      cauc  other   male     worker
## 41   11.00        14         14  34      cauc  south   male     worker
## 42   12.00        12         14  32      cauc  other   male     worker
## 43    4.85         9         16  31      cauc  other female     worker
## 44    4.30        13          8  27      cauc  south   male     worker
## 45    6.00         7         15  28      cauc  south female     worker
## 46   15.00        16         12  34      cauc  other   male     worker
## 47    4.85        10         13  29      cauc  south   male     worker
## 48    9.00         8         33  47      cauc  other   male     worker
## 49    6.36        12          9  27      cauc  other   male     worker
## 50    9.15        12          7  25      cauc  other   male     worker
## 51   11.00        16         13  35      cauc  other   male     worker
## 52    4.50        12          7  25      cauc  other female     worker
## 53    4.80        12         16  34      cauc  other female     worker
## 54    4.00        13          0  19      cauc  other   male     worker
## 55    5.50        12         11  29      cauc  other female     worker
## 56    8.40        13         17  36      cauc  other   male     worker
## 57    6.75        10         13  29      cauc  other   male     worker
## 58   10.00        12         22  40     other  other   male     worker
## 59    5.00        12         28  46      cauc  other female     worker
## 60    6.50        11         17  34      cauc  other   male     worker
## 61   10.75        12         24  42      cauc  other   male     worker
## 62    7.00         3         55  64  hispanic  south   male     worker
## 63   11.43        12          3  21      cauc  south   male     worker
## 64    4.00        12          6  24     other  other   male     worker
## 65    9.00        10         27  43      cauc  other   male     worker
## 66   13.00        12         19  37     other  south   male     worker
## 67   12.22        12         19  37      cauc  other   male     worker
## 68    6.28        12         38  56      cauc  other female     worker
## 69    6.75        10         41  57     other  south   male     worker
## 70    3.35        11          3  20     other  south   male     worker
## 71   16.00        14         20  40      cauc  other   male     worker
## 72    5.25        10         15  31      cauc  other   male     worker
## 73    3.50         8          8  22  hispanic  south   male     worker
## 74    4.22         8         39  53      cauc  south female     worker
## 75    3.00         6         43  55  hispanic  other female     worker
## 76    4.00        11         25  42      cauc  south female     worker
## 77   10.00        12         11  29      cauc  other   male     worker
## 78    5.00        12         12  30     other  other   male     worker
## 79   16.00        12         35  53      cauc  south   male     worker
## 80   13.98        14         14  34      cauc  other   male     worker
## 81   13.26        12         16  34      cauc  other   male     worker
## 82    6.10        10         44  60      cauc  other female     worker
## 83    3.75        16         13  35      cauc  south female     worker
## 84    9.00        13          8  27     other  other   male     worker
## 85    9.45        12         13  31      cauc  other   male     worker
## 86    5.50        11         18  35      cauc  other   male     worker
## 87    8.93        12         18  36      cauc  other female     worker
## 88    6.25        12          6  24      cauc  south female     worker
## 89    9.75        11         37  54      cauc  south   male     worker
## 90    6.73        12          2  20      cauc  south   male     worker
## 91    7.78        12         23  41      cauc  other   male     worker
## 92    2.85        12          1  19      cauc  other   male     worker
## 93    3.35        12         10  28     other  south female     worker
## 94   19.98        12         23  41      cauc  other   male     worker
## 95    8.50        12          8  26     other  other   male     worker
## 96    9.75        15          9  30      cauc  other female     worker
## 97   15.00        12         33  51      cauc  other   male     worker
## 98    8.00        12         19  37      cauc  other female     worker
## 99   11.25        13         14  33      cauc  other   male     worker
## 100  14.00        11         13  30      cauc  other   male     worker
## 101  10.00        10         12  28      cauc  other   male     worker
## 102   6.50        12          8  26      cauc  other   male     worker
## 103   9.83        12         23  41      cauc  other   male     worker
## 104  18.50        14         13  33      cauc  other female     worker
## 105  12.50        12          9  27      cauc  south   male     worker
## 106  26.00        14         21  41      cauc  other   male     worker
## 107  14.00         5         44  55      cauc  south   male     worker
## 108  10.50        12          4  22      cauc  other   male     worker
## 109  11.00         8         42  56      cauc  other   male     worker
## 110  12.47        13         10  29      cauc  other   male     worker
## 111  12.50        12         11  29      cauc  other   male     worker
## 112  15.00        12         40  58      cauc  other   male     worker
## 113   6.00        12          8  26      cauc  other   male     worker
## 114   9.50        11         29  46      cauc  south   male     worker
## 115   5.00        16          3  25      cauc  other   male     worker
## 116   3.75        11         11  28      cauc  other   male     worker
## 117  12.57        12         12  30      cauc  other   male     worker
## 118   6.88         8         22  36  hispanic  other female     worker
## 119   5.50        12         12  30      cauc  other   male     worker
## 120   7.00        12          7  25      cauc  other   male     worker
## 121   4.50        12         15  33      cauc  other female     worker
## 122   6.50        12         28  46      cauc  other   male     worker
## 123  12.00        12         20  38      cauc  south   male     worker
## 124   5.00        12          6  24      cauc  south   male     worker
## 125   6.50        12          5  23      cauc  south   male     worker
## 126   6.80         9         30  45      cauc  south female     worker
## 127   8.75        13         18  37      cauc  other   male     worker
## 128   3.75        12          6  24     other  south female     worker
## 129   4.50        12         16  34  hispanic  south   male     worker
## 130   6.00        12          1  19  hispanic  south   male     worker
## 131   5.50        12          3  21      cauc  other   male     worker
## 132  13.00        12          8  26      cauc  other   male     worker
## 133   5.65        14          2  22      cauc  other   male     worker
## 134   4.80         9         16  31     other  other   male     worker
## 135   7.00        10          9  25      cauc  south   male     worker
## 136   5.25        12          2  20      cauc  other   male     worker
## 137   3.35         7         43  56      cauc  south   male     worker
## 138   8.50         9         38  53      cauc  other   male     worker
## 139   6.00        12          9  27      cauc  other   male     worker
## 140   6.75        12         12  30      cauc  south   male     worker
## 141   8.89        12         18  36      cauc  other   male     worker
## 142  14.21        11         15  32      cauc  other   male     worker
## 143  10.78        11         28  45     other  south   male     worker
## 144   8.90        10         27  43      cauc  south   male     worker
## 145   7.50        12         38  56      cauc  south   male     worker
## 146   4.50        12          3  21      cauc  other female     worker
## 147  11.25        12         41  59      cauc  other   male     worker
## 148  13.45        12         16  34      cauc  south   male     worker
## 149   6.00        13          7  26      cauc  south   male     worker
## 150   4.62         6         33  45     other  south female     worker
## 151  10.58        14         25  45      cauc  other   male     worker
## 152   5.00        12          5  23      cauc  south   male     worker
## 153   8.20        14         17  37     other  south   male     worker
## 154   6.25        12          1  19      cauc  south   male     worker
## 155   8.50        12         13  31      cauc  other   male     worker
## 429  10.00        13         34  53      cauc  other   male  technical
## 430  18.00        18         15  39      cauc  other   male  technical
## 431  24.98        17         31  54      cauc  other   male  technical
## 432  12.05        16          6  28      cauc  other female  technical
## 433  22.00        14         15  35      cauc  south   male  technical
## 434   8.75        12         30  48      cauc  other   male  technical
## 435  22.20        18          8  32      cauc  other   male  technical
## 436  17.25        18          5  29      cauc  other   male  technical
## 437   6.00        17          3  26      cauc  other female  technical
## 438   8.06        13         17  36      cauc  south   male  technical
## 439   9.24        16          5  27     other  other   male  technical
## 440  12.00        14         10  30      cauc  other female  technical
## 441  10.61        15         33  54      cauc  other female  technical
## 442   5.71        18          3  27      cauc  other   male  technical
## 443  10.00        16          0  18      cauc  other female  technical
## 444  17.50        16         13  35     other  south   male  technical
## 445  15.00        18         12  36      cauc  other   male  technical
## 446   7.78        16          6  28      cauc  other female  technical
## 447   7.80        17          7  30      cauc  other   male  technical
## 448  10.00        16         14  36      cauc  south   male  technical
## 449  24.98        17          5  28      cauc  other female  technical
## 450  10.28        15         10  31      cauc  south female  technical
## 451  15.00        18         11  35      cauc  other female  technical
## 452  12.00        17         24  47      cauc  other female  technical
## 453  10.58        16          9  31      cauc  other   male  technical
## 454   5.85        18         12  36      cauc  south   male  technical
## 455  11.22        18         19  43      cauc  other   male  technical
## 456   8.56        14         14  34      cauc  other female  technical
## 457  13.89        16         17  39      cauc  other female  technical
## 458   5.71        18          7  31      cauc  south   male  technical
## 459  15.79        18          7  31      cauc  other   male  technical
## 460   7.50        16         22  44      cauc  other female  technical
## 461  11.25        12         28  46      cauc  other female  technical
## 462   6.15        16         16  38      cauc  other female  technical
## 463  13.45        16         16  38     other  south   male  technical
## 464   6.25        16          7  29      cauc  other female  technical
## 465   6.50        12         11  29      cauc  other female  technical
## 466  12.00        12         11  29      cauc  other female  technical
## 467   8.50        12         16  34      cauc  other female  technical
## 468   8.00        18         33  57      cauc  other   male  technical
## 469   5.75        12         21  39      cauc  south female  technical
## 470  15.73        16          4  26      cauc  other   male  technical
## 471   9.86        15         13  34      cauc  other   male  technical
## 472  13.51        18         14  38      cauc  other   male  technical
## 473   5.40        16         10  32      cauc  other female  technical
## 474   6.25        18         14  38      cauc  south   male  technical
## 475   5.50        16         29  51      cauc  south   male  technical
## 476   5.00        12          4  22  hispanic  other   male  technical
## 477   6.25        18         27  51     other  other   male  technical
## 478   5.75        12          3  21      cauc  other   male  technical
## 479  20.50        16         14  36      cauc  south   male  technical
## 480   5.00        14          0  20      cauc  other   male  technical
## 481   7.00        18         33  57      cauc  other   male  technical
## 482  18.00        16         38  60      cauc  south   male  technical
## 483  12.00        18         18  42      cauc  other female  technical
## 484  20.40        17          3  26      cauc  other   male  technical
## 485  22.20        18         40  64      cauc  other female  technical
## 486  16.42        14         19  39      cauc  other   male  technical
## 487   8.63        14          4  24      cauc  other female  technical
## 488  19.38        16         11  33      cauc  other female  technical
## 489  14.00        16         16  38      cauc  other female  technical
## 490  10.00        14         22  42      cauc  other   male  technical
## 491  15.95        17         13  36      cauc  other female  technical
## 492  20.00        16         28  50      cauc  south female  technical
## 493  10.00        16         10  32      cauc  other female  technical
## 494  24.98        16          5  27      cauc  south female  technical
## 495  11.25        15          5  26      cauc  other   male  technical
## 496  22.83        18         37  61      cauc  other female  technical
## 497  10.20        17         26  49      cauc  other female  technical
## 498  10.00        16          4  26      cauc  south female  technical
## 499  14.00        18         31  55      cauc  other female  technical
## 500  12.50        17         13  36      cauc  other female  technical
## 501   5.79        12         42  60      cauc  other female  technical
## 502  24.98        17         18  41  hispanic  other   male  technical
## 503   4.35        12          3  21      cauc  other female  technical
## 504  11.25        17         10  33      cauc  other female  technical
## 505   6.67        16         10  32      cauc  other female  technical
## 506   8.00        16         17  39  hispanic  other female  technical
## 507  18.16        18          7  31      cauc  other   male  technical
## 508  12.00        16         14  36      cauc  other female  technical
## 509   8.89        16         22  44      cauc  other female  technical
## 510   9.50        17         14  37      cauc  other female  technical
## 511  13.65        16         11  33      cauc  other   male  technical
## 512  12.00        18         23  47      cauc  other   male  technical
## 513  15.00        12         39  57      cauc  other   male  technical
## 514  12.67        16         15  37      cauc  other   male  technical
## 515   7.38        14         15  35  hispanic  other female  technical
## 516  15.56        16         10  32      cauc  other   male  technical
## 517   7.45        12         25  43      cauc  south female  technical
## 518   6.25        14         12  32      cauc  other female  technical
## 519   6.25        16          7  29  hispanic  south female  technical
## 520   9.37        17          7  30      cauc  other   male  technical
## 521  22.50        16         17  39      cauc  other   male  technical
## 522   7.50        16         10  32      cauc  other   male  technical
## 523   7.00        17          2  25      cauc  south   male  technical
## 524   5.75         9         34  49     other  south female  technical
## 525   7.67        15         11  32      cauc  other female  technical
## 526  12.50        15         10  31      cauc  other   male  technical
## 527  16.00        12         12  30      cauc  south   male  technical
## 528  11.79        16          6  28      cauc  other female  technical
## 529  11.36        18          5  29      cauc  other   male  technical
## 530   6.10        12         33  51     other  other female  technical
## 531  23.25        17         25  48     other  other female  technical
## 532  19.88        12         13  31      cauc  south   male  technical
## 533  15.38        16         33  55      cauc  other   male  technical
## 346   6.00         4         54  64      cauc  other   male   services
## 347   7.14        14         17  37      cauc  other   male   services
## 348   3.40         8         29  43     other  other female   services
## 349   6.00        15         26  47      cauc  south female   services
## 350   3.75         2         16  24  hispanic  other   male   services
## 351   8.89         8         29  43     other  other female   services
## 352   4.35        11         20  37      cauc  other female   services
## 353  13.10        10         38  54     other  south female   services
## 354   4.35         8         37  51     other  south female   services
## 355   3.50         9         48  63      cauc  other   male   services
## 356   3.80        12         16  34      cauc  other female   services
## 357   5.26         8         38  52      cauc  other female   services
## 358   3.35        14          0  20     other  other   male   services
## 359  16.26        12         14  32     other  other   male   services
## 360   4.25        12          2  20      cauc  other female   services
## 361   4.50        16         21  43      cauc  other   male   services
## 362   8.00        13         15  34      cauc  other female   services
## 363   4.00        16         20  42      cauc  other female   services
## 364   7.96        14         12  32      cauc  other female   services
## 365   4.00        12          7  25  hispanic  south   male   services
## 366   4.15        11          4  21      cauc  other   male   services
## 367   5.95        13          9  28      cauc  south   male   services
## 368   3.60        12         43  61  hispanic  south female   services
## 369   8.75        10         19  35      cauc  south   male   services
## 370   3.40         8         49  63      cauc  other female   services
## 371   4.28        12         38  56      cauc  other female   services
## 372   5.35        12         13  31      cauc  other female   services
## 373   5.00        12         14  32      cauc  other female   services
## 374   7.65        12         20  38      cauc  other   male   services
## 375   6.94        12          7  25      cauc  other female   services
## 376   7.50        12          9  27      cauc  other female   services
## 377   3.60        12          6  24      cauc  other female   services
## 378   1.75        12          5  23      cauc  south female   services
## 379   3.45        13          1  20     other  south female   services
## 380   9.63        14         22  42      cauc  other   male   services
## 381   8.49        12         24  42      cauc  other female   services
## 382   8.99        12         15  33      cauc  other female   services
## 383   3.65        11          8  25      cauc  south female   services
## 384   3.50        11         17  34      cauc  south female   services
## 385   3.43        12          2  20     other  south   male   services
## 386   5.50        12         20  38      cauc  south   male   services
## 387   6.93        12         26  44      cauc  other   male   services
## 388   3.51        10         37  53     other  south female   services
## 389   3.75        12         41  59      cauc  other female   services
## 390   4.17        12         27  45      cauc  other female   services
## 391   9.57        12          5  23      cauc  other female   services
## 392  14.67        14         16  36     other  other   male   services
## 393  12.50        14         19  39      cauc  other female   services
## 394   5.50        12         10  28      cauc  other   male   services
## 395   5.15        13          1  20      cauc  south   male   services
## 396   8.00        12         43  61     other  other female   services
## 397   5.83        13          3  22     other  other   male   services
## 398   3.35        12          0  18      cauc  other female   services
## 399   7.00        12         26  44      cauc  south female   services
## 400  10.00        10         25  41      cauc  other female   services
## 401   8.00        12         15  33      cauc  other female   services
## 402   6.88        14         10  30      cauc  south female   services
## 403   5.55        11         45  62      cauc  other female   services
## 404   7.50        11          3  20     other  other   male   services
## 405   8.93         8         47  61  hispanic  other   male   services
## 406   9.00        16          6  28     other  other female   services
## 407   3.50        10         33  49      cauc  south female   services
## 408   5.77        16          3  25      cauc  other   male   services
## 409  25.00        14          4  24  hispanic  other   male   services
## 410   6.85        14         34  54     other  other   male   services
## 411   6.50        11         39  56      cauc  south   male   services
## 412   3.75        12         17  35      cauc  south female   services
## 413   3.50         9         47  62      cauc  other   male   services
## 414   4.50        11          2  19      cauc  other   male   services
## 415   2.01        13          0  19      cauc  south   male   services
## 416   4.17        14         24  44      cauc  other female   services
## 417  13.00        12         25  43     other  other   male   services
## 418   3.98        14          6  26      cauc  other female   services
## 419   7.50        12         10  28      cauc  other female   services
## 420  13.12        12         33  51     other  other female   services
## 421   4.00        12         12  30      cauc  other   male   services
## 422   3.95        12          9  27      cauc  south female   services
## 423  13.00        11         18  35      cauc  south   male   services
## 424   9.00        12         10  28      cauc  other   male   services
## 425   4.55         8         45  59      cauc  south female   services
## 426   9.50         9         46  61      cauc  other female   services
## 427   4.50         7         14  27  hispanic  south   male   services
## 428   8.75        11         36  53      cauc  other female   services
## 249   5.00        14         17  37  hispanic  other female     office
## 250   8.75        13         10  29      cauc  south female     office
## 251  10.00        16          7  29      cauc  other female     office
## 252   8.50        12         25  43      cauc  other female     office
## 253   8.63        12         18  36     other  other female     office
## 254   9.00        16         27  49      cauc  other female     office
## 255   5.50        16          2  24      cauc  other female     office
## 256  11.11        13         13  32      cauc  other   male     office
## 257  10.00        14         24  44      cauc  other female     office
## 258   5.20        18         13  37  hispanic  south female     office
## 259   8.00        14         15  35      cauc  other female     office
## 260   3.56        12         12  30  hispanic  south female     office
## 261   5.20        12         24  42      cauc  other female     office
## 262  11.67        12         43  61      cauc  other female     office
## 263  11.32        12         13  31      cauc  other female     office
## 264   7.50        12         16  34      cauc  south female     office
## 265   5.50        11         24  41      cauc  other female     office
## 266   5.00        16          4  26      cauc  south female     office
## 267   7.75        12         24  42      cauc  other female     office
## 268   5.25        12         45  63      cauc  other female     office
## 269   9.00        12         20  38      cauc  other   male     office
## 270   9.65        12         38  56      cauc  other female     office
## 271   5.21        18         10  34      cauc  south   male     office
## 272   7.00        11         16  33     other  other female     office
## 273  12.16        12         32  50     other  south female     office
## 274   5.25        16          2  24      cauc  south female     office
## 275  10.32        13         28  47      cauc  south female     office
## 276   3.35        16          3  25     other  other   male     office
## 277   7.70        13          8  27      cauc  other female     office
## 278   9.17        12         44  62      cauc  other female     office
## 279   8.43        12         12  30      cauc  south   male     office
## 280   4.00        12          8  26     other  south   male     office
## 281   4.13        12          4  22      cauc  other female     office
## 282   3.00        12         28  46      cauc  south female     office
## 283   4.25        13          0  19      cauc  south female     office
## 284   7.53        14          1  21      cauc  south   male     office
## 285  10.53        14         12  32      cauc  other female     office
## 286   5.00        12         39  57      cauc  other female     office
## 287  15.03        12         24  42      cauc  other female     office
## 288  11.25        17         32  55     other  other female     office
## 289   6.25        16          4  26     other  other   male     office
## 290   3.50        12         25  43     other  other female     office
## 291   6.85        12          8  26     other  other   male     office
## 292  12.50        13         16  35      cauc  other female     office
## 293  12.00        12          5  23      cauc  south   male     office
## 294   6.00        13         31  50      cauc  other   male     office
## 295   9.50        12         25  43      cauc  other female     office
## 296   4.10        12         15  33      cauc  other female     office
## 297  10.43        14         15  35      cauc  south female     office
## 298   5.00        12          0  18      cauc  other female     office
## 299   7.69        12         19  37      cauc  other   male     office
## 300   5.50        12         21  39     other  other female     office
## 301   6.40        12          6  24      cauc  other female     office
## 302  12.50        12         14  32      cauc  other female     office
## 303   6.25        13         30  49      cauc  other female     office
## 304   8.00        12          8  26      cauc  other female     office
## 305   9.60         9         33  48      cauc  other   male     office
## 306   9.10        13         16  35  hispanic  other   male     office
## 307   7.50        12         20  38      cauc  south female     office
## 308   5.00        13          6  25      cauc  south female     office
## 309   7.00        12         10  28      cauc  other female     office
## 310   3.55        13          1  20      cauc  south female     office
## 311   8.50        12          2  20     other  south   male     office
## 312   4.50        13          0  19      cauc  south female     office
## 313   7.88        16         17  39     other  other   male     office
## 314   5.25        12          8  26      cauc  other female     office
## 315   5.00        12          4  22      cauc  south   male     office
## 316   9.33        12         15  33      cauc  other female     office
## 317  10.50        12         29  47      cauc  other female     office
## 318   7.50        12         23  41     other  south female     office
## 319   9.50        12         39  57      cauc  south female     office
## 320   9.60        12         14  32      cauc  south female     office
## 321   5.87        17          6  29     other  south female     office
## 322  11.02        14         12  32      cauc  south   male     office
## 323   5.00        12         26  44      cauc  south female     office
## 324   5.62        14         32  52      cauc  other female     office
## 325  12.50        15          6  27      cauc  other female     office
## 326  10.81        12         40  58      cauc  other female     office
## 327   5.40        12         18  36      cauc  other female     office
## 328   7.00        11         12  29      cauc  other female     office
## 329   4.59        12         36  54      cauc  south female     office
## 330   6.00        12         19  37      cauc  other female     office
## 331  11.71        16         42  64      cauc  other female     office
## 332   5.62        13          2  21  hispanic  other female     office
## 333   5.50        12         33  51      cauc  other female     office
## 334   4.85        12         14  32      cauc  south female     office
## 335   6.75        12         22  40      cauc  other   male     office
## 336   4.25        12         20  38      cauc  other female     office
## 337   5.75        12         15  33      cauc  other female     office
## 338   3.50        12         35  53      cauc  other   male     office
## 339   3.35        12          7  25      cauc  other female     office
## 340  10.62        12         45  63      cauc  other female     office
## 341   8.00        12          9  27      cauc  other female     office
## 342   4.75        12          2  20      cauc  south female     office
## 343   8.50        17          3  26      cauc  south   male     office
## 344   8.85        14         19  39     other  other female     office
## 345   8.00        12         14  32      cauc  south female     office
## 211   4.55        13         33  52      cauc  other female      sales
## 212   9.00        12         16  34      cauc  other   male      sales
## 213  13.33        18         10  34      cauc  other   male      sales
## 214  15.00        14         22  42      cauc  other   male      sales
## 215   7.50        14          2  22      cauc  other   male      sales
## 216   4.25        12         29  47      cauc  south female      sales
## 217  12.50        12         43  61      cauc  other   male      sales
## 218   5.13        12          5  23      cauc  other female      sales
## 219   3.35        16         14  36     other  south female      sales
## 220  11.11        12         28  46      cauc  south   male      sales
## 221   3.84        11         25  42     other  south female      sales
## 222   6.40        12         45  63      cauc  other female      sales
## 223   5.56        14          5  25      cauc  south   male      sales
## 224  10.00        12         20  38      cauc  south   male      sales
## 225   5.65        16          6  28      cauc  other female      sales
## 226  11.50        16         16  38      cauc  other   male      sales
## 227   3.50        11         33  50      cauc  other female      sales
## 228   3.35        13          2  21      cauc  south female      sales
## 229   4.75        12         10  28      cauc  south female      sales
## 230  19.98        14         44  64      cauc  south   male      sales
## 231   3.50        14          6  26      cauc  south female      sales
## 232   4.00        12         15  33      cauc  other female      sales
## 233   7.00        12          5  23      cauc  other   male      sales
## 234   6.25        13          4  23      cauc  other female      sales
## 235   4.50        14         14  34      cauc  other   male      sales
## 236  14.29        14         32  52      cauc  other female      sales
## 237   5.00        12         14  32      cauc  other female      sales
## 238  13.75        14         21  41      cauc  other   male      sales
## 239  13.71        12         43  61      cauc  other   male      sales
## 240   7.50        12         27  45     other  south female      sales
## 241   3.80        12          4  22      cauc  other female      sales
## 242   5.00        14          0  20  hispanic  other   male      sales
## 243   9.42        12         32  50      cauc  south   male      sales
## 244   5.50        12         20  38      cauc  other   male      sales
## 245   3.75        15          4  25      cauc  south   male      sales
## 246   3.50        12         34  52      cauc  other   male      sales
## 247   5.80        13          5  24      cauc  other   male      sales
## 248  12.00        17         13  36      cauc  other   male      sales
## 156  24.98        16         18  40      cauc  other   male management
## 157  16.65        14         21  41      cauc  south   male management
## 158   6.25        14          2  22      cauc  other   male management
## 159   4.55        12          4  22  hispanic  south female management
## 160  11.25        12         30  48  hispanic  south female management
## 161  21.25        13         32  51      cauc  other   male management
## 162  12.65        17         13  36      cauc  other female management
## 163   7.50        12         17  35      cauc  other   male management
## 164  10.25        14         26  46      cauc  other female management
## 165   3.35        16          9  31      cauc  other   male management
## 166  13.45        16          8  30     other  other   male management
## 167   4.84        15          1  22      cauc  other   male management
## 168  26.29        17         32  55      cauc  south   male management
## 169   6.58        12         24  42      cauc  other female management
## 170  44.50        14          1  21      cauc  other female management
## 171  15.00        12         42  60      cauc  other   male management
## 172  11.25        16          3  25     other  other female management
## 173   7.00        12         32  50      cauc  other female management
## 174  10.00        14         22  42     other  other   male management
## 175  14.53        16         18  40      cauc  other   male management
## 176  20.00        18         19  43      cauc  other female management
## 177  22.50        15         12  33      cauc  other   male management
## 178   3.64        12         42  60      cauc  other female management
## 179  10.62        12         34  52      cauc  south   male management
## 180  24.98        18         29  53      cauc  other   male management
## 181   6.00        16          8  30      cauc  south   male management
## 182  19.00        18         13  37      cauc  other   male management
## 183  13.20        16         10  32      cauc  other   male management
## 184  22.50        16         22  44      cauc  other   male management
## 185  15.00        16         10  32      cauc  south   male management
## 186   6.88        17         15  38      cauc  other female management
## 187  11.84        12         26  44      cauc  other   male management
## 188  16.14        14         16  36      cauc  other   male management
## 189  13.95        18         14  38      cauc  other female management
## 190  13.16        12         38  56      cauc  other female management
## 191   5.30        12         14  32     other  south   male management
## 192   4.50        12          7  25      cauc  other female management
## 193  10.00        18         13  37      cauc  south female management
## 194  10.00        10         20  36      cauc  other   male management
## 195  10.00        16          7  29  hispanic  other   male management
## 196   9.37        16         26  48      cauc  other female management
## 197   5.80        16         14  36      cauc  other   male management
## 198  17.86        13         36  55      cauc  other   male management
## 199   1.00        12         24  42      cauc  other   male management
## 200   8.80        14         41  61      cauc  south   male management
## 201   9.00        16          7  29     other  other   male management
## 202  18.16        17         14  37      cauc  south   male management
## 203   7.81        12          1  19      cauc  south female management
## 204  10.62        16          6  28      cauc  other female management
## 205   4.50        12          3  21      cauc  other female management
## 206  17.25        15         31  52      cauc  other   male management
## 207  10.50        13         14  33      cauc  other female management
## 208   9.22        14         13  33      cauc  other female management
## 209  15.00        16         26  48     other  other   male management
## 210  22.50        18         14  38      cauc  other   male management
##             sector union married
## 1    manufacturing    no     yes
## 1100 manufacturing    no     yes
## 2    manufacturing    no      no
## 3            other    no      no
## 4            other    no     yes
## 5            other   yes      no
## 6            other    no      no
## 7            other    no      no
## 8    manufacturing    no     yes
## 9            other    no      no
## 10           other   yes     yes
## 11   manufacturing   yes      no
## 12           other    no     yes
## 13           other   yes      no
## 14           other    no     yes
## 15    construction    no     yes
## 16           other    no     yes
## 17   manufacturing   yes     yes
## 18           other    no      no
## 19           other    no     yes
## 20   manufacturing   yes     yes
## 21   manufacturing   yes     yes
## 22           other    no      no
## 23           other    no     yes
## 24           other    no     yes
## 25   manufacturing    no     yes
## 26   manufacturing    no     yes
## 27           other    no     yes
## 28   manufacturing    no     yes
## 29           other    no     yes
## 30           other    no      no
## 31           other    no      no
## 32           other    no     yes
## 33           other    no      no
## 34   manufacturing    no      no
## 35           other    no      no
## 36    construction    no     yes
## 37    construction   yes     yes
## 38           other    no      no
## 39   manufacturing    no     yes
## 40           other    no      no
## 41   manufacturing   yes     yes
## 42   manufacturing    no     yes
## 43   manufacturing    no     yes
## 44    construction    no      no
## 45   manufacturing    no     yes
## 46   manufacturing    no     yes
## 47           other    no      no
## 48           other   yes     yes
## 49   manufacturing    no     yes
## 50           other    no     yes
## 51   manufacturing   yes     yes
## 52   manufacturing    no     yes
## 53   manufacturing    no     yes
## 54           other    no      no
## 55   manufacturing    no      no
## 56   manufacturing    no      no
## 57   manufacturing    no     yes
## 58   manufacturing   yes      no
## 59   manufacturing    no     yes
## 60           other    no      no
## 61    construction   yes     yes
## 62   manufacturing    no     yes
## 63    construction    no      no
## 64   manufacturing   yes      no
## 65    construction    no     yes
## 66   manufacturing   yes     yes
## 67    construction   yes     yes
## 68   manufacturing    no     yes
## 69   manufacturing   yes     yes
## 70   manufacturing    no      no
## 71           other   yes     yes
## 72           other    no     yes
## 73   manufacturing    no     yes
## 74   manufacturing    no     yes
## 75   manufacturing   yes     yes
## 76   manufacturing   yes     yes
## 77           other   yes     yes
## 78           other    no     yes
## 79   manufacturing   yes     yes
## 80           other    no      no
## 81           other   yes     yes
## 82   manufacturing   yes      no
## 83           other    no      no
## 84   manufacturing   yes      no
## 85   manufacturing    no      no
## 86           other   yes     yes
## 87           other    no     yes
## 88           other    no      no
## 89   manufacturing   yes     yes
## 90   manufacturing    no     yes
## 91   manufacturing    no     yes
## 92           other    no      no
## 93   manufacturing    no     yes
## 94   manufacturing    no     yes
## 95           other   yes     yes
## 96   manufacturing    no     yes
## 97    construction   yes     yes
## 98   manufacturing    no     yes
## 99           other    no     yes
## 100          other   yes     yes
## 101   construction    no     yes
## 102          other    no      no
## 103  manufacturing    no     yes
## 104  manufacturing    no      no
## 105          other    no     yes
## 106          other   yes     yes
## 107   construction    no     yes
## 108          other   yes     yes
## 109  manufacturing    no     yes
## 110          other   yes     yes
## 111   construction    no      no
## 112   construction   yes     yes
## 113   construction    no      no
## 114   construction    no     yes
## 115          other   yes      no
## 116   construction    no      no
## 117          other   yes     yes
## 118          other    no     yes
## 119          other    no     yes
## 120          other   yes     yes
## 121  manufacturing    no      no
## 122          other    no     yes
## 123  manufacturing   yes     yes
## 124   construction    no      no
## 125  manufacturing    no      no
## 126  manufacturing    no     yes
## 127          other    no     yes
## 128  manufacturing    no     yes
## 129          other    no      no
## 130          other   yes      no
## 131  manufacturing    no      no
## 132          other    no     yes
## 133  manufacturing    no      no
## 134  manufacturing    no      no
## 135   construction    no     yes
## 136          other    no      no
## 137  manufacturing    no     yes
## 138  manufacturing    no     yes
## 139          other    no     yes
## 140          other    no     yes
## 141  manufacturing    no     yes
## 142  manufacturing   yes      no
## 143   construction   yes     yes
## 144   construction   yes     yes
## 145          other    no     yes
## 146  manufacturing    no      no
## 147          other   yes     yes
## 148          other   yes     yes
## 149  manufacturing    no     yes
## 150  manufacturing    no      no
## 151  manufacturing    no     yes
## 152          other    no     yes
## 153          other    no      no
## 154          other    no      no
## 155  manufacturing    no     yes
## 429   construction   yes     yes
## 430          other    no     yes
## 431  manufacturing    no     yes
## 432  manufacturing    no      no
## 433          other    no     yes
## 434          other    no     yes
## 435          other    no     yes
## 436  manufacturing    no     yes
## 437          other   yes      no
## 438          other    no     yes
## 439  manufacturing   yes     yes
## 440          other    no     yes
## 441          other    no      no
## 442          other    no     yes
## 443          other    no      no
## 444          other    no     yes
## 445          other    no     yes
## 446          other    no     yes
## 447          other    no     yes
## 448          other   yes     yes
## 449          other    no      no
## 450          other    no     yes
## 451          other    no     yes
## 452          other    no     yes
## 453  manufacturing    no      no
## 454          other    no     yes
## 455          other    no     yes
## 456          other    no     yes
## 457  manufacturing    no      no
## 458          other    no      no
## 459          other    no     yes
## 460          other    no     yes
## 461          other    no     yes
## 462          other    no      no
## 463          other    no      no
## 464          other    no     yes
## 465          other    no      no
## 466          other    no     yes
## 467          other    no      no
## 468          other   yes      no
## 469          other    no     yes
## 470  manufacturing    no     yes
## 471          other    no     yes
## 472          other   yes     yes
## 473          other    no     yes
## 474          other    no     yes
## 475          other    no     yes
## 476          other    no      no
## 477          other    no     yes
## 478          other    no     yes
## 479          other   yes     yes
## 480   construction    no     yes
## 481          other    no     yes
## 482          other    no     yes
## 483          other   yes     yes
## 484  manufacturing    no      no
## 485          other    no      no
## 486  manufacturing    no      no
## 487          other    no      no
## 488          other    no     yes
## 489          other    no     yes
## 490          other    no     yes
## 491          other   yes      no
## 492          other   yes     yes
## 493          other    no     yes
## 494          other    no      no
## 495          other    no      no
## 496  manufacturing    no      no
## 497          other   yes     yes
## 498          other    no     yes
## 499          other   yes      no
## 500          other   yes     yes
## 501          other    no     yes
## 502          other    no     yes
## 503          other    no     yes
## 504          other    no      no
## 505          other   yes      no
## 506          other    no     yes
## 507          other    no     yes
## 508          other    no     yes
## 509          other   yes     yes
## 510          other    no     yes
## 511          other    no     yes
## 512          other   yes     yes
## 513          other   yes     yes
## 514          other    no     yes
## 515          other    no      no
## 516          other    no      no
## 517          other    no      no
## 518          other    no     yes
## 519          other    no     yes
## 520          other   yes     yes
## 521  manufacturing    no     yes
## 522          other   yes     yes
## 523          other    no     yes
## 524          other   yes     yes
## 525          other    no     yes
## 526          other    no      no
## 527          other    no     yes
## 528          other   yes      no
## 529          other    no      no
## 530          other    no     yes
## 531          other   yes     yes
## 532          other   yes     yes
## 533  manufacturing    no     yes
## 346          other    no     yes
## 347          other    no     yes
## 348          other    no     yes
## 349          other    no      no
## 350          other    no      no
## 351          other    no      no
## 352          other    no     yes
## 353          other    no     yes
## 354          other    no     yes
## 355          other    no      no
## 356          other    no      no
## 357          other    no     yes
## 358          other    no      no
## 359          other   yes      no
## 360          other    no     yes
## 361          other    no     yes
## 362          other    no     yes
## 363          other    no      no
## 364          other    no     yes
## 365          other    no      no
## 366          other    no     yes
## 367          other    no     yes
## 368          other    no     yes
## 369          other    no      no
## 370          other    no      no
## 371          other    no     yes
## 372          other    no     yes
## 373          other    no     yes
## 374          other    no      no
## 375          other    no      no
## 376  manufacturing   yes     yes
## 377          other    no      no
## 378          other    no     yes
## 379          other    no      no
## 380          other   yes     yes
## 381          other    no     yes
## 382          other   yes      no
## 383          other    no     yes
## 384          other    no     yes
## 385          other    no      no
## 386          other    no     yes
## 387          other   yes     yes
## 388          other    no     yes
## 389          other    no      no
## 390          other    no     yes
## 391          other   yes     yes
## 392          other    no     yes
## 393          other    no     yes
## 394          other    no     yes
## 395          other   yes      no
## 396          other   yes     yes
## 397          other    no      no
## 398          other    no      no
## 399          other    no     yes
## 400          other   yes     yes
## 401          other    no     yes
## 402          other    no      no
## 403          other   yes      no
## 404          other    no      no
## 405          other   yes     yes
## 406          other    no     yes
## 407          other    no      no
## 408  manufacturing    no      no
## 409          other   yes      no
## 410          other   yes     yes
## 411          other    no     yes
## 412          other    no     yes
## 413          other   yes     yes
## 414          other    no      no
## 415          other    no      no
## 416          other    no      no
## 417          other   yes     yes
## 418          other    no      no
## 419          other    no      no
## 420          other    no     yes
## 421          other    no      no
## 422          other    no     yes
## 423          other   yes     yes
## 424          other    no     yes
## 425          other    no      no
## 426          other   yes     yes
## 427          other    no     yes
## 428          other    no      no
## 249          other    no     yes
## 250          other    no     yes
## 251          other    no     yes
## 252          other    no      no
## 253          other    no     yes
## 254  manufacturing    no     yes
## 255          other    no      no
## 256          other    no     yes
## 257          other    no      no
## 258          other    no     yes
## 259          other   yes      no
## 260          other    no      no
## 261          other    no     yes
## 262   construction    no     yes
## 263  manufacturing    no     yes
## 264          other    no     yes
## 265          other    no     yes
## 266          other    no     yes
## 267          other    no     yes
## 268          other    no     yes
## 269          other   yes     yes
## 270          other    no     yes
## 271          other    no     yes
## 272          other    no     yes
## 273          other    no     yes
## 274          other    no      no
## 275          other    no      no
## 276          other    no      no
## 277          other   yes      no
## 278  manufacturing    no     yes
## 279          other    no     yes
## 280          other    no     yes
## 281          other    no     yes
## 282          other    no     yes
## 283          other    no      no
## 284          other    no      no
## 285  manufacturing    no     yes
## 286          other    no     yes
## 287          other    no     yes
## 288          other    no     yes
## 289          other    no      no
## 290          other    no      no
## 291          other    no      no
## 292          other    no     yes
## 293          other    no      no
## 294          other    no      no
## 295          other    no      no
## 296          other    no     yes
## 297          other    no     yes
## 298          other    no      no
## 299          other    no     yes
## 300          other    no      no
## 301          other    no      no
## 302          other   yes     yes
## 303          other    no     yes
## 304          other    no      no
## 305          other   yes      no
## 306          other    no      no
## 307          other    no      no
## 308          other    no     yes
## 309          other   yes     yes
## 310          other    no      no
## 311          other    no      no
## 312          other    no      no
## 313          other    no     yes
## 314          other    no      no
## 315          other    no      no
## 316          other    no      no
## 317          other    no     yes
## 318          other    no     yes
## 319          other    no     yes
## 320          other    no     yes
## 321          other    no      no
## 322          other   yes     yes
## 323          other    no      no
## 324          other    no     yes
## 325          other    no     yes
## 326          other    no     yes
## 327  manufacturing    no     yes
## 328          other    no      no
## 329   construction    no     yes
## 330          other    no     yes
## 331  manufacturing    no      no
## 332          other    no     yes
## 333          other    no     yes
## 334          other    no     yes
## 335          other    no      no
## 336          other    no     yes
## 337          other    no     yes
## 338          other    no     yes
## 339          other    no     yes
## 340  manufacturing    no      no
## 341          other    no      no
## 342          other    no     yes
## 343          other    no      no
## 344          other   yes     yes
## 345          other    no     yes
## 211          other    no     yes
## 212          other    no     yes
## 213          other    no     yes
## 214          other    no      no
## 215          other    no      no
## 216          other    no     yes
## 217  manufacturing    no     yes
## 218          other    no     yes
## 219          other    no     yes
## 220          other    no     yes
## 221          other    no     yes
## 222          other    no     yes
## 223          other    no      no
## 224  manufacturing    no     yes
## 225          other    no     yes
## 226          other    no     yes
## 227          other    no     yes
## 228          other    no     yes
## 229          other    no      no
## 230          other    no     yes
## 231          other    no     yes
## 232          other    no      no
## 233          other    no     yes
## 234  manufacturing    no     yes
## 235          other    no     yes
## 236          other    no     yes
## 237          other    no     yes
## 238          other    no     yes
## 239          other   yes     yes
## 240          other    no     yes
## 241          other    no      no
## 242          other    no      no
## 243          other    no     yes
## 244          other    no     yes
## 245          other    no      no
## 246          other    no     yes
## 247          other    no      no
## 248  manufacturing    no     yes
## 156          other    no     yes
## 157          other    no     yes
## 158          other    no      no
## 159          other    no      no
## 160          other    no     yes
## 161          other    no      no
## 162          other    no     yes
## 163          other    no      no
## 164          other    no     yes
## 165          other    no      no
## 166          other    no      no
## 167          other   yes     yes
## 168          other    no     yes
## 169          other    no     yes
## 170          other    no      no
## 171  manufacturing    no     yes
## 172  manufacturing    no      no
## 173          other    no     yes
## 174          other    no      no
## 175          other    no     yes
## 176          other    no     yes
## 177          other    no     yes
## 178          other    no     yes
## 179          other    no     yes
## 180          other    no     yes
## 181          other    no      no
## 182  manufacturing    no      no
## 183          other    no      no
## 184          other    no     yes
## 185          other    no     yes
## 186          other    no     yes
## 187          other    no     yes
## 188          other    no      no
## 189          other    no     yes
## 190          other    no     yes
## 191          other    no     yes
## 192          other    no     yes
## 193          other    no      no
## 194          other    no     yes
## 195          other   yes     yes
## 196          other    no     yes
## 197          other    no     yes
## 198          other    no      no
## 199          other    no     yes
## 200          other    no     yes
## 201          other    no     yes
## 202          other    no      no
## 203          other    no      no
## 204  manufacturing    no     yes
## 205          other    no     yes
## 206          other    no     yes
## 207  manufacturing    no     yes
## 208          other    no     yes
## 209  manufacturing   yes     yes
## 210          other    no     yes
#Lập bảng tần số
sec <- h$sector
table(sec)
## sec
## manufacturing  construction         other 
##            99            24           411
#Nhận xét:ngành dựa vào yếu tố cấp độ cho thấy có 441 người làm ngành khác chiếm tỷ lệ cao nhất 76,97%, ngành chế tạo và khai khoáng là 99 người chiếm tỷ lệ vừa phải 18,54%, ngành xây dựng 24 người chiếm tỷ lệ rất thấp 4,49% 
#Lập bảng tần số cho biến "experience"
exp <- h$experience
table(cut(exp,6))
## 
## (-0.055,9.17]   (9.17,18.3]   (18.3,27.5]   (27.5,36.7]   (36.7,45.8] 
##           156           169            89            61            51 
##   (45.8,55.1] 
##             8
#Nhận xét: Số năm kinh nghiệm làm việc ở trong khoảng (-0.055,9.17] và (9.17,18.3] chiếm tỉ lệ cao lần lượt là 156 người (chiếm 29,21%) và 169 người (chiếm 31,65%), trong khoảng (18.3,27.5], (27.5,36.7], (36.7,45.8] chiếm tỷ lệ vừa phải lần lượt là 89 nguời (16,67%), 61 người (chiếm 11,42%) và 51 người (chiếm 9,55%) và khoảng (45.8,55.1] chiếm tỷ lệ rất thấp 1,98%