’’’{r} > arr = read.csv(“C:/Users/admin/OneDrive/Desktop/Arrest
arr = read.csv ("C:/Users/admin/OneDrive/Desktop/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
library(table1)
##
## Attaching package: 'table1'
## The following objects are masked from 'package:base':
##
## units, units<-
table1(~ finance+ factor(arrest)+ age+ race+ 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] |
| race | |
| black | 379 (87.7%) |
| other | 53 (12.3%) |
| 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%) |
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%) |
library(ggplot2)
ggplot(data = arr, aes(x = finance, y = age, fill = finance))+ geom_boxplot()
data.csv”, header=T) > hist (arr\(week, color="blue") Warning messages: 1: In plot.window(xlim, ylim, "", ...) : "color" is not a graphical parameter 2: In title(main = main, sub = sub, xlab = xlab, ylab = ylab, ...) : "color" is not a graphical parameter 3: In axis(1, ...) : "color" is not a graphical parameter 4: In axis(2, at = yt, ...) : "color" is not a graphical parameter > table(arr\)arrest) Summary (arr) head (arr)
0 1 318 114 Warning messages: 1: In doTryCatch(return(expr), name, parentenv, handler) : “color” is not a graphical parameter 2: In doTryCatch(return(expr), name, parentenv, handler) : “color” is not a graphical parameter 3: In doTryCatch(return(expr), name, parentenv, handler) : “color” is not a graphical parameter 4: In doTryCatch(return(expr), name, parentenv, handler) : “color” is not a graphical parameter 5: In doTryCatch(return(expr), name, parentenv, handler) : “color” is not a graphical parameter 6: In doTryCatch(return(expr), name, parentenv, handler) : “color” is not a graphical parameter 7: In doTryCatch(return(expr), name, parentenv, handler) : “color” is not a graphical parameter 8: In doTryCatch(return(expr), name, parentenv, handler) : “color” is not a graphical parameter > table (arr\(finance, arr\)arrest)
0 1
no 150 66 yes 168 48 > 66/(150+66) [1] 0.3055556 > 48/(168+66) [1] 0.2051282
arr
hist (arr$week, color=“blue”)
table(~finance+ arrest+age+ race+ works, data=arr)
##vẽ biểu đồ
```
library (ggplot2)
ggplot(data=arr, eas(x=finance, y=week, fill=finance))+geom_boxplot)
> table (arr$finance, arr$arrest)
</div>
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the