Đọc dữ liệu

arr=read.csv("E:\\2. NCS hồ sơ- tiến trình học 2024\\8.1. Viết báo quốc tế\\45. Lớp học phân tích dữ liệu. Đại học Văn Lang. T12.2022\\Arrest data.csv")
summary(arr)
##        id             week           arrest         finance         
##  Min.   :  1.0   Min.   : 1.00   Min.   :0.0000   Length:432        
##  1st Qu.:108.8   1st Qu.:50.00   1st Qu.:0.0000   Class :character  
##  Median :216.5   Median :52.00   Median :0.0000   Mode  :character  
##  Mean   :216.5   Mean   :45.85   Mean   :0.2639                     
##  3rd Qu.:324.2   3rd Qu.:52.00   3rd Qu.:1.0000                     
##  Max.   :432.0   Max.   :52.00   Max.   :1.0000                     
##       age           race               work             married         
##  Min.   :17.0   Length:432         Length:432         Length:432        
##  1st Qu.:20.0   Class :character   Class :character   Class :character  
##  Median :23.0   Mode  :character   Mode  :character   Mode  :character  
##  Mean   :24.6                                                           
##  3rd Qu.:27.0                                                           
##  Max.   :44.0                                                           
##     parole              prior             educ      
##  Length:432         Min.   : 0.000   Min.   :2.000  
##  Class :character   1st Qu.: 1.000   1st Qu.:3.000  
##  Mode  :character   Median : 2.000   Median :3.000  
##                     Mean   : 2.984   Mean   :3.477  
##                     3rd Qu.: 4.000   3rd Qu.:4.000  
##                     Max.   :18.000   Max.   :6.000
head(arr)
##   id week arrest finance age  race work     married parole prior educ
## 1  1   20      1      no  27 black   no not married    yes     3    3
## 2  2   17      1      no  18 black   no not married    yes     8    4
## 3  3   25      1      no  19 other  yes not married    yes    13    3
## 4  4   52      0     yes  23 black  yes     married    yes     1    5
## 5  5   52      0      no  19 other  yes not married    yes     3    3
## 6  6   52      0      no  24 black  yes not married     no     2    4

Phân tích mô tả

library(table1)
## 
## Attaching package: 'table1'
## The following objects are masked from 'package:base':
## 
##     units, units<-
table1(~finance + factor(arrest) + age + work + married + parole, data = arr)
Overall
(N=432)
finance
no 216 (50.0%)
yes 216 (50.0%)
factor(arrest)
0 318 (73.6%)
1 114 (26.4%)
age
Mean (SD) 24.6 (6.11)
Median [Min, Max] 23.0 [17.0, 44.0]
work
no 185 (42.8%)
yes 247 (57.2%)
married
married 53 (12.3%)
not married 379 (87.7%)
parole
no 165 (38.2%)
yes 267 (61.8%)

Vẽ biểu đồ tuần bị bắt và hỗ trợ tài chính

library(ggplot2)
ggplot(data= arr, aes (x=finance, y = age, fill= finance)) + geom_boxplot()

Theo tình trạng hỗ trợ tài chính

table1(~ factor(arrest) + age + race + work + married + parole | finance, data = arr)
no
(N=216)
yes
(N=216)
Overall
(N=432)
factor(arrest)
0 150 (69.4%) 168 (77.8%) 318 (73.6%)
1 66 (30.6%) 48 (22.2%) 114 (26.4%)
age
Mean (SD) 24.2 (5.73) 25.0 (6.47) 24.6 (6.11)
Median [Min, Max] 23.0 [17.0, 44.0] 23.0 [17.0, 44.0] 23.0 [17.0, 44.0]
race
black 185 (85.6%) 194 (89.8%) 379 (87.7%)
other 31 (14.4%) 22 (10.2%) 53 (12.3%)
work
no 93 (43.1%) 92 (42.6%) 185 (42.8%)
yes 123 (56.9%) 124 (57.4%) 247 (57.2%)
married
married 29 (13.4%) 24 (11.1%) 53 (12.3%)
not married 187 (86.6%) 192 (88.9%) 379 (87.7%)
parole
no 81 (37.5%) 84 (38.9%) 165 (38.2%)
yes 135 (62.5%) 132 (61.1%) 267 (61.8%)

Vẽ biểu đồ tuần bị bắt và hỗ trợ tài chính

library(ggplot2)
ggplot(data = arr, aes(x=finance, y= age, fill = finance)) + geom_boxplot()