ALY6015: SEC-13
Statistical Analysis of New York Police
Department Stop-and-Frisk Policy
Report
Submitted to:
Prof. Roy Wada
By:
Akshay Kirit Kalavadia
Liching Hwang
Jyothi Chandrakanth
Date: 23rd May, 2021
1|Page
Content
Introduction…………………………………………………………………………… 3
Data Analysis…………………………………………………………………………. 4
Sub-Group Analysis……………………………………………………………. 5
Creating New Variable…………………………………………..……...….. 9
Analytical Methods………………………………………………………….… 10
Linear Regression…………………………………………………..…………. 10
Chi-Square.……………………………………………………………….………. 11
One-Way Anova………………………………………………………….….…. 12
Summary…………………………………………………………….….………………. 13
Reference………………………………………………………….…….………….…. 14
Appendix.…………………………………………………….………….………….…. 15
2|Page
Introduction
Before 2003, NYPD officers were not required to report the reasons for Stop-And-Frisk
perform during the duty. In 2003, the police dept came up with form that were required to
be filled by each officer for each stop along with the reason and action taken. In NYPD Dept
Stop-And-Frisk dataset, we have 31 variables with 12012 observations. The dataset contains
information on stops related to the stop-and-frisk program in New York City as recorded by
police officers from 2003 to 2015. Fields included in the dataset include the race and sex of
the suspect, as well as the specific actions (frisking, searching, and/or arresting the suspect)
conducted by the police officer and the reasons reported by the officer for doing so. We
would provide some statistic tables and graphs to show the dataset and use ANOVA test,
Chi-Square test, and linear regression to analyse our data. The below are the sample of the
forms which are required by the officers to be filled and from which the data have been
collected:
3|Page
Data Analysis
We created two subsets, one is about the sex(male and female) with year, stopped,
arrested, searched, frisked. Another is race(Asian, Black, American Indian, White Hispanic,
Black Hispanic, White) with year, stopped, arrested, searched, frisked.
Figure 1: Correlation Matrix
The correlation graphs shows that the blue represent positive, on the other hand, red
represent negative. We can see each variable is blue circle, so it is positive relationship.
4|Page
Subgroup Analysis
Table 1: Gender statistic table
N
Mean
Sd
Min
Max
stopped
4793337
440.81
1312.54
1
22972
arrested
292852
35.14
76.23
1
926
searched
410547
49.24
119.1
1
1828
frisked
2512580
252.42
784.58
1
13593
stopped
4451476
767.63
1727.07
1
22972
arrested
264955
53.29
93.88
1
926
searched
387355
75.57
145.61
1
1828
frisked
2420251
426.63
1004.11
1
13593
stopped
341861
67.36
147.46
1
2261
arrested
27897
8.3
12.7
1
108
searched
23192
7.22
10.69
1
103
frisked
92329
21.57
42.51
1
507
Sex
Male
Female
This is statistic table by gender. We break down to the male and female. The total number of
the stopped variable is 4.7 million people. However, 90% of men stopped. And in the
arrested, searched, and frisked the number of males are all more than female. In the mean
column, we can see the numbers in male are more than the total. In the max column, the
maximum is all come from the male.
In addition, we can infer that from total number of people 92.87% , 90.47%, 94.35% and
96.33% of the individuals were male, who were stopped, arrested, searched and frisked
respectively. Hence, we can observe from the statistics that more male were stopped,
arrested, searched and frisked then female.
5|Page
Figure 2: Comparison between Male and Female
In the graphs above, there are four graphs in the Figure 2, comparing male and female about
stopped, arrested, searched, and frisked from year 2003 to 2015. The blue color represent
the male and the red one represent female. We see that the number of females in each graph
are lower than male. Sometimes the ratio is too different, and the number of women seems
to be close to zero. Between 2008 and 2012, the number of males was relatively large in these
four variables, but females did not seem to have any special distribution. The numbers for
stop, arrested, searched and frisked have significantly decreased in 2016.
6|Page
N
Race
stopped
arrested
frisked
searched
Asian
stopped
arrested
frisked
searched
Black
stopped
arrested
frisked
searched
Indian
stopped
arrested
frisked
searched
Table 2: Race statistic table
Percentage
Mean
Sd
Min
Max
4793337
292852
2512580
410547
100%
100%
100%
100%
440.81 1312.54
35.14
76.23
49.24 119.10
252.42 784.58
1
1
1
1
22972
926
1828
13593
154316
9640
65313
12581
3.2%
3.3%
2.6%
3.1%
87.43
8.73
43.11
10.89
233.46
19.04
118.82
25.64
1
1
1
1
2870
222
1686
280
2598217
154072
1410179
216351
54.2%
52.6%
56.1%
52.7%
1315.55 2583.65
82.04 129.62
722.79 1471.04
116.94 202.24
1
1
1
1
22972
926
13593
1828
19584
947
8481
0.4%
0.32%
0.3%
0.35%
14.78
2.21
8.93
2.95
27.75
2.19
14.84
1
1
1
273
18
138
4.30
1
46
6.3%
7.1%
7.1%
6.8%
160.58
14.11
100.47
19.65
321.13
22.05
211.33
32.05
1
1
1
1
3639
191
1841
269
25.4%
25.9%
26.0%
27.1%
620.50 1139.55
42.31
65.89
340.11 744.88
61.97 115.23
1
1
1
1
12437
481
9213
1178
10.4%
10.8%
7.9%
10.0%
256.29
19.06
106.19
25.42
1
1
1
1
5931
229
2848
348
1433
White Hispanic
stopped
306232
arrested
20767
frisked
175518
searched
28215
Black Hispanic
stopped
1218049
arrested
75857
frisked
655048
searched
110684
White
stopped
496939
arrested
31569
frisked
198041
searched
41283
488.18
29.53
219.75
42.92
In this table, the number of Black people in each variable is the most, over 50%. However,
according to the United States Census Bureau website, the percentage of Black people only
24% in New York City. The major gender is White people about 42% in New York City.
Therefore, the number of the Black Hispanic are the second highest in the race. The
interesting thing is the number of Indian people no matter in stopped, arrested, frisked and
searched variables have lowest number. Some columns are less than ten.
7|Page
Figure 3: Stopped by NYPD each year
The above graph depicts the number of people that were stopped based on the race. The
races include six different races as shown in the above graph for the year 2003 to 2015. We
can say that the number of people that are black were stopped mostly for all the years. In the
year 2009 the number of Blacks that were stopped are more than 25000. The numbers have
significantly dropped after 2012. The second highest number of people that were stopped
next after Blacks were Black Hispanics. The graph does show that there could be a relationship
with the number of people stopped and ethnicity, which can be determined by further
analysis.
8|Page
Creating new variable
We have observed that individuals are stopped but are not always arrested or summoned in
court. Therefore, they are innocent individuals. We have created a new variable called
“innocent” which includes number of individuals who are stopped but are not arrested or
summoned.
nypd$innocent <-nypd$stopped + nypd$searched + nypd$frisked - nypd$arrested nypd$summoned
Figure 4: Innocent people stopped by Race
The above graph displays the number of people innocent people stopped based on ethnicity.
We can infer that the highest number of people that were tuned out to be innocents were
Blacks following with black Hispanics. The least number of people that were found out to be
innocent were American Indians. Unfortunately, darker skins are easily labelled even though
they are innocent.
9|Page
Analytical methods
(i)
Linear Regression:
Perform Linear Regression for Weapons found with the number of incidents where the
suspect was frisked due to suspicion of weapon possession and Number of incidents where
the suspect was stopped due to observed actions resembling engagement in a violent crime.
ŷ = 1.474 + 0.044x1 + 0.066x2
=========================================================================
Dependent variable:
----------------------------Weapon Found
-----------------------------------------------------------------------------------------------------------------Suspect was frisked due to suspicion of weapon possession
0.044***
(0.001)
Suspect was stopped due to observed actions
resembling engagement in a violent crime
Constant
0.066***
(0.001)
1.474***
(0.086)
-----------------------------------------------------------------------------------------------------------------Observations
12,012
R2
0.634
Adjusted R2
0.633
Residual Std. Error
9.074 (df = 12009)
F Statistic
10,380.900*** (df = 2; 12009)
===========================================================================
Note:
*p<0.1; **p<0.05; ***p<0.01
===========================================================================
Observation: From the above result, R-Square = 0.63. Hence 63% of the variability in
dependent variable Weapons found is accounted by independent variables frisked due to
suspicion of weapon possession and stopped due to observed actions resembling
engagement in a violent crime. We also infer that both independent variables have significant
influence on the outcome variable.
10 | P a g e
(ii) Chi-Square Independence Test
Are stopped numbers related to ethnicity? From 2003 to 2015 the number of stops for twelve
years. At the 0.05 level of significance, can it be concluded that stopped numbers by year
were dependent upon ethnicity?
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
Total
Asian and
Pacific
Islander
115
135
139
147
145
151
149
152
152
151
143
109
77
1765
Table 3: Ethnicity Contingency Table
American
Indian/Alaskan
White
Black
Native
Hispanic
152
72
142
152
91
149
152
110
152
152
111
152
152
114
151
152
122
152
152
119
151
152
134
151
152
130
151
152
132
152
154
102
150
153
56
134
148
32
120
1975
1325
1907
BlackHispanic
151
152
152
152
152
152
152
152
152
152
154
146
144
1963
White
152
152
152
152
152
152
152
152
152
152
152
133
134
1939
Step 1. State the hypotheses and identify the claim.
Claim - Does the number of stopped by year depend on the ethnicity
Null Hypothesis (H0): Stopped is independent of ethnicity
Alternate Hypothesis (H1): Stopped is dependent of ethnicity
Step 2. Find the critical value.
The critical value is = 11.0705
Step 3. Compute the test value
Table 4: Chi-Square
X-squared
df
p-value
110.27
60
8.283e-05
11 | P a g e
Step 4. Summarize the results
The critical value (11.0705) < the x-squared value (110.27) and p-value (8.283e-05) is less than
the significance value (0.05).
Hence we have enough evidence to reject the Null Hypothesis and conclude that the number
of stops are dependent on the ethnicity.
(iii) One-Way ANOVA
Conduct a one-way ANOVA for Independent variables, Stopped with a dependent variable as
sex (male & female) at ⍺ = 0.05 and summarize the conclusion.
Null Hypothesis (H0): μ1 = μ2
Alternate Hypothesis (H1): μ1 ≠ μ2
Table 6: One-Way ANOVA test Result
Df
Sum Sq
Mean Sq
1
1406000000
1406000000
sex
Residuals
F value
Pr(>F)
963.5 <0.0000000000000002***
12010 17530000000 1459000
Observation: As we can see, the p-value is less than 0.05, we have enough evidence to reject
the null hypothesis that the mean number of stops for male are equal to mean number of
stops for female.
12 | P a g e
Summary
In this assignment, we focus on the sex and the race in the dataset. In addition, a new variable
innocent was created to check how many of innocent people were stopped although they
were innocent. The three analytical methods, chi-square, one-way ANOVA, and linear
regression, were used. Graphs were generated to compare and analyse visually. The results
were inferred based on the results. After the tests we can conclude that ethnicity is
dependent on the number of people that were stopped.
We confirmed the disparity in stops by ethnicity by comparing the population distribution of
the population in New York. There are 44% white population and 25.5% black population. But
when we observe the number of stops of white and black ethnicity people, only 10.4% of all
the stops were white people and 54.2% were black.
13 | P a g e
Reference
Downloadable data. (n.d.). Retrieved April 27, 2021, from
https://dasil.sites.grinnell.edu/downloadable-data/
Bluman, A. G. (2018). Elementary statistics: a step-by-step approach. McGraw-Hill
Education.
Kabacoff, R. I. (2015). R in action: data analysis and graphics with R. Manning Publications
Alboukadel Kassambara. (2019, November 29). ANOVA in R: The Ultimate Guide. Datanovia.
https://www.datanovia.com/en/lessons/anova-in-r/.
One-Way ANOVA test in R. (n.d.). Retrieved May 10, 2021, from
http://www.sthda.com/english/wiki/one-way-anova-test-in-r
Wikimedia Foundation. (2021, May 3). Demographic history of New York City. Wikipedia.
https://en.wikipedia.org/wiki/Demographic_history_of_New_York_City.
Ridgeway, G. (2007). Analysis of Racial Disparities in the New York Police Department’s Stop,
Question, and Frisk Practices. Published 2007 by the RAND Corporation. Retrieved 22 May
2021, from
https://www.rand.org/content/dam/rand/pubs/technical_reports/2007/RAND_TR534.pdf
14 | P a g e
Appendix / R-code
nypd<-read.csv("NYPD_SQF.csv")
stopped<- nypd[which(nypd$stopped>0),]
arrested<-nypd[nypd$arrested>0,]
frisked<-nypd[nypd$frisked>0,]
searched<-nypd[nypd$searched>0,]
sum(stopped$stopped)
sum(arrested$arrested)
sum(searched$searched)
sum(frisked$frisked)
mean(stopped$stopped)
mean(arrested$arrested)
mean(searched$searched)
mean(frisked$frisked)
sd(stopped$stopped)
sd(arrested$arrested)
sd(searched$searched)
sd(frisked$frisked)
max(stopped$stopped)
max(arrested$arrested)
max(searched$searched)
max(frisked$frisked)
stopped_male<-nypd[which(nypd$sex=="M" & nypd$stopped >0),]
arrested_male<-nypd[which(nypd$sex=="M" & nypd$arrested >0),]
searched_male<-nypd[which(nypd$sex=="M" & nypd$searched >0),]
frisked_male<- nypd[which(nypd$sex=="M" & nypd$frisked >0),]
sum(stopped_male$stopped)
sum(arrested_male$arrested)
sum(searched_male$searched)
sum(frisked_male$frisked)
stopped_female<-nypd[which(nypd$sex=="F" & nypd$stopped >0),]
arrested_female<-nypd[which(nypd$sex=="F" & nypd$arrested >0),]
searched_female<-nypd[which(nypd$sex=="F" & nypd$searched >0),]
frisked_female<- nypd[which(nypd$sex=="F" & nypd$frisked >0),]
mean(stopped_male$stopped)
mean(arrested_male$arrested)
mean(searched_male$searched)
mean(frisked_male$frisked)
15 | P a g e
sd(stopped_male$stopped)
sd(arrested_male$arrested)
sd(searched_male$searched)
sd(frisked_male$frisked)
max(stopped_male$stopped)
max(arrested_male$arrested)
max(searched_male$searched)
max(frisked_male$frisked)
mean(stopped_female$stopped)
mean(arrested_female$arrested)
mean(searched_female$searched)
mean(frisked_female$frisked)
sd(stopped_female$stopped)
sd(arrested_female$arrested)
sd(searched_female$searched)
sd(frisked_female$frisked)
max(stopped_female$stopped)
max(arrested_female$arrested)
max(searched_female$searched)
max(frisked_female$frisked)
stopped_asian<-nypd[which(nypd$race == "A" & nypd$stopped >0),]
arrested_asian<-nypd[which(nypd$race=="A" & nypd$arrested >0),]
searched_asian<-nypd[which(nypd$race=="A" & nypd$searched >0),]
frisked_asian<- nypd[which(nypd$race=="A" & nypd$frisked >0),]
stopped_black<-nypd[which(nypd$race == "B" & nypd$stopped >0),]
arrested_black<-nypd[which(nypd$race=="B" & nypd$arrested >0),]
searched_black<-nypd[which(nypd$race=="B" & nypd$searched >0),]
frisked_black<- nypd[which(nypd$race=="B" & nypd$frisked >0),]
stopped_indian<-nypd[which(nypd$race == "I" & nypd$stopped >0),]
arrested_indian<-nypd[which(nypd$race=="I" & nypd$arrested >0),]
searched_indian<-nypd[which(nypd$race=="I" & nypd$searched >0),]
frisked_indian<- nypd[which(nypd$race=="I" & nypd$frisked >0),]
stopped_white_hispanic<-nypd[which(nypd$race == "P" & nypd$stopped >0),]
arrested_white_hispanic<-nypd[which(nypd$race=="P" & nypd$arrested >0),]
searched_white_hispanic<-nypd[which(nypd$race=="P" & nypd$searched >0),]
frisked_white_hispanic<- nypd[which(nypd$race=="P" & nypd$frisked >0),]
stopped_black_hispanic<-nypd[which(nypd$race == "Q" & nypd$stopped >0),]
16 | P a g e
arrested_black_hispanic<-nypd[which(nypd$race=="Q" & nypd$arrested >0),]
searched_black_hispanic<-nypd[which(nypd$race=="Q" & nypd$searched >0),]
frisked_black_hispanic<- nypd[which(nypd$race=="Q" & nypd$frisked >0),]
stopped_white<-nypd[which(nypd$race == "W" & nypd$stopped >0),]
arrested_white<-nypd[which(nypd$race=="W" & nypd$arrested >0),]
searched_white<-nypd[which(nypd$race=="W" & nypd$searched >0),]
frisked_white<- nypd[which(nypd$race=="W" & nypd$frisked >0),]
mean(stopped_asian$stopped)
mean(arrested_asian$arrested)
mean(searched_asian$searched)
mean(frisked_asian$frisked)
sd(stopped_asian$stopped)
sd(arrested_asian$arrested)
sd(searched_asian$searched)
sd(frisked_asian$frisked)
max(stopped_asian$stopped)
max(arrested_asian$arrested)
max(searched_asian$searched)
max(frisked_asian$frisked)
mean(stopped_black$stopped)
mean(arrested_black$arrested)
mean(searched_black$searched)
mean(frisked_black$frisked)
sd(stopped_black$stopped)
sd(arrested_black$arrested)
sd(searched_black$searched)
sd(frisked_black$frisked)
max(stopped_black$stopped)
max(arrested_black$arrested)
max(searched_black$searched)
max(frisked_black$frisked)
mean(stopped_indian$stopped)
mean(arrested_indian$arrested)
mean(searched_indian$searched)
mean(frisked_indian$frisked)
sd(stopped_indian$stopped)
sd(arrested_indian$arrested)
sd(searched_indian$searched)
17 | P a g e
sd(frisked_indian$frisked)
max(stopped_indian$stopped)
max(arrested_indian$arrested)
max(searched_indian$searched)
max(frisked_indian$frisked)
mean(stopped_white_hispanic$stopped)
mean(arrested_white_hispanic$arrested)
mean(frisked_white_hispanic$frisked)
mean(searched_white_hispanic$searched)
sd(stopped_white_hispanic$stopped)
sd(arrested_white_hispanic$arrested)
sd(frisked_white_hispanic$frisked)
sd(searched_white_hispanic$searched)
mean(stopped_black_hispanic$stopped)
mean(arrested_black_hispanic$arrested)
mean(frisked_black_hispanic$frisked)
mean(searched_black_hispanic$searched)
sd(stopped_black_hispanic$stopped)
sd(arrested_black_hispanic$arrested)
sd(frisked_black_hispanic$frisked)
sd(searched_black_hispanic$searched)
mean(stopped_white$stopped)
mean(arrested_white$arrested)
mean(frisked_white$frisked)
mean(searched_white$searched)
sd(stopped_white$stopped)
sd(arrested_white$arrested)
sd(frisked_white$frisked)
sd(searched_white$searched)
nypd$innocent <-nypd$stopped + nypd$searched + nypd$frisked - nypd$arrested nypd$summoned
#Perform Linear Regression for Weapons found with the number of incidents where the
suspect was
#frisked due to suspicion of weapon possession and Number of incidents where the suspect
was stopped
#due to observed actions resembling engagement in a violent crime.
18 | P a g e
#summary of the model
options(scipen =999)
model_regression<-lm(formula = nypd$weapnfnd ~ nypd$rf_othsw + nypd$cs_vcrim)
summary(model_regression)
model_regression$coefficients
table_regression<-data.frame(model_regression$coefficients)
rownames(table_regression)<- c("Intercept","Suspision of weapon","Voilent crime")
colnames(table_regression)<- c("Coefficients")
write.csv(table_regression,"regressiontable.csv")
library(ggplot2)
#New codes for graph
library(gridExtra)
grid.arrange(stopped_graph,arrested_graph,searched_graph,frisked_graph,ncol=2,nrow=2)
stopped_graph <- ggplot(data=stopped, aes(x=sex, y=stopped)) +
labs(title = " Stopped in each Year") + xlab("Year") + ylab("Number of people stopped") +
theme(text = element_text(size = 15),plot.title = element_text(hjust = 0.5)) +
geom_bar(stat="identity", position=position_dodge())+ scale_fill_discrete (name =
"Gender", labels = c( "Female", "Male"))
arrested_graph<-ggplot(data=arrested, aes(x=year, y=arrested, fill=sex)) +
labs(title = " Arrested in each Year") + xlab("Year") + ylab("Number of people arrested") +
theme(text = element_text(size = 15),plot.title = element_text(hjust = 0.5)) +
geom_bar(stat="identity", position=position_dodge())+ scale_fill_discrete (name =
"Gender", labels = c( "Female", "Male"))
searched_graph<-ggplot(data=nypd, aes(x=year, y=searched, fill=sex)) +
labs(title = " Searched in each Year") + xlab("Year") + ylab("Number of people searched") +
theme(text = element_text(size = 15),plot.title = element_text(hjust = 0.5)) +
geom_bar(stat="identity", position=position_dodge())+ scale_fill_discrete (name =
"Gender", labels = c( "Female", "Male"))
frisked_graph<-ggplot(data=nypd, aes(x=year, y=frisked, fill=sex)) +
labs(title = " Frisked in each Year") + xlab("Year") + ylab("Number of people frisked") +
theme(text = element_text(size = 15),plot.title = element_text(hjust = 0.5)) +
geom_bar(stat="identity", position=position_dodge())+ scale_fill_discrete (name
"Gender", labels = c( "Female", "Male"))
=
q <- ggplot(data=nypd, aes(year, y=stopped, fill=race)) +
labs(title = " Stopped in each Year") + xlab("Year") + ylab("Number of people stopped") +
geom_bar(stat="identity", position=position_dodge()) +
theme(text = element_text(size = 15),plot.title = element_text(hjust = 0.5)) +
scale_fill_discrete(name = "Race", labels = c("Asian", "Black", "American Indian", "White
Hispanic", "Black Hispanic", "White"))
19 | P a g e
r <- ggplot(data=nypd, aes(x=race, y=innocent, fill=race)) +
labs(title = " Innocent People stopped by Race") + xlab("Race") + ylab("Number of Innocent
People stopped") +
geom_bar(stat="identity", position=position_dodge()) + theme(text = element_text(size =
15),plot.title = element_text(hjust = 0.5)) + scale_fill_discrete(name = "Race", labels = c("A Asian", "B - Black", "I - American Indian", "P - White Hispanic", "Q - Black Hispanic", "W White"))
Chi-Square test for Independence.
#Critical Value
alpha<- 0.05
#Create a vector for each row
r1 <- c(115, 135, 139, 147,145,151,149,152,152,151, 143,109, 77)
r2<- c(152, 152, 152, 152, 152, 152, 152, 152,152, 152, 154 ,153, 148)
r3 <- c(72,91,110,111,114,122,119, 134,130,132, 102,56, 32)
r4<- c(142, 149, 152, 152, 151, 152, 151, 151, 151, 152, 150, 134, 120)
r5 <- c(151,152,152, 152, 152, 152, 152, 152,152,152,154,146,144)
r6<-c(152,152,152,152,152,152,152,152,152,152,152,133,134)
#Sate the number of rows
rows = 6
#Create a matrix from the rows
mtr = matrix(c(r1, r2, r3, r4,r5,r6), nrow= rows, byrow = T)
#Assign row names and column names
rownames(mtr) = c("Asian and Pacific Islander", "Black", "American Indian/Alaskan Native",
"White Hispanic", "Black-Hispanic", "White")
colnames(mtr)
=
c("2003","2004","2005","2006","2007","2008","2009",
"2010",
"2011","2012","2013","2014","2015")
mtr
20 | P a g e
#Find critical value
qchisq(0.05,5,lower.tail = F)
#run the test and save the result
test <- chisq.test(mtr)
test
test$p.value
#Compare p-value and aplha values and make the decision
ifelse(test$p.value > alpha, "Fail to reject the Null Hypothesis", "Reject the Null Hypothesis")
#All
install.packages("psych")
library("psych")
table1 <-psych::describe(data1)
setwd("~/東北/研究所/ALY6015/group")
write.csv(table1,"table1.csv")
mytable<- function(dataset) {
table1 <-psych::describe(dataset)
write.csv(table1,"table1.csv") }
mytable(data1)
names(table1)
mytable<- function(dataset) {
library(dplyr)
table1 <-psych::describe(dataset)
table1 <- table1 %>% select(n, mean, sd, min, max)
write.csv(table1,"data1sex.csv")
}
mytable(data1)
#Male
library("psych")
table2 <-psych::describe(Male)
setwd("~/東北/研究所/ALY6015/group")
write.csv(table2,"table2.csv")
mytable<- function(dataset) {
table1 <-psych::describe(dataset)
write.csv(table2,"table2.csv") }
mytable(Male)
names(table2)
mytable<- function(dataset) {
library(dplyr)
table2 <-psych::describe(dataset)
table2 <- table2 %>% select(n, mean, sd, min, max)
write.csv(table2,"data1male.csv")
21 | P a g e
}
mytable(Male)
#Female
library("psych")
table3 <-psych::describe(Female)
setwd("~/東北/研究所/ALY6015/group")
write.csv(table3,"table3.csv")
mytable<- function(dataset) {
table1 <-psych::describe(dataset)
write.csv(table3,"table3.csv") }
mytable(Female)
names(table3)
mytable<- function(dataset) {
library(dplyr)
table3 <-psych::describe(dataset)
table3 <- table3 %>% select(n, mean, sd, min, max)
write.csv(table3,"data1female.csv")
}
mytable(Female)
# Race
data2<- data[c("race", "stopped", "arrested", "frisked", "searched")]
Asian <- data2[data2$race=="A",]
Black <- data2[data2$race=="B",]
Indian <- data2[data2$race=="I",]
WHispanic <- data2[data2$race=="P",]
BHispanic <- data2[data2$race=="Q",]
White <- data2[data2$race=="W",]
##data2 table
#All
library("psych")
table4 <-psych::describe(data2)
setwd("~/東北/研究所/ALY6015/group")
write.csv(table4,"table4.csv")
mytable<- function(dataset) {
table1 <-psych::describe(dataset)
write.csv(table4,"table4.csv") }
mytable(data2)
names(table4)
mytable<- function(dataset) {
library(dplyr)
table4 <-psych::describe(dataset)
table4 <- table4 %>% select(n, mean, sd, min, max)
write.csv(table4,"data2.csv")
22 | P a g e
}
mytable(data2)
#A
library("psych")
table5 <-psych::describe(Asian)
setwd("~/東北/研究所/ALY6015/group")
write.csv(table5,"table5.csv")
mytable<- function(dataset) {
table5 <-psych::describe(dataset)
write.csv(table5,"table5.csv") }
mytable(Asian)
names(table5)
mytable<- function(dataset) {
library(dplyr)
table5 <-psych::describe(dataset)
table5 <- table5 %>% select(n, mean, sd, min, max)
write.csv(table5,"data2A.csv")
}
mytable(Asian)
#B
library("psych")
table6 <-psych::describe(Black)
setwd("~/東北/研究所/ALY6015/group")
write.csv(table6,"table6.csv")
mytable<- function(dataset) {
table6 <-psych::describe(dataset)
write.csv(table6,"table6.csv") }
mytable(Black)
names(table6)
mytable<- function(dataset) {
library(dplyr)
table6 <-psych::describe(dataset)
table6 <- table6 %>% select(n, mean, sd, min, max)
write.csv(table6,"data2B.csv")
}
mytable(Black)
View(table6)
#I
library("psych")
table7 <-psych::describe(Indian)
setwd("~/東北/研究所/ALY6015/group")
write.csv(table7,"table7.csv")
mytable<- function(dataset) {
23 | P a g e
table7 <-psych::describe(dataset)
write.csv(table7,"table7.csv") }
mytable(Indian)
names(table7)
mytable<- function(dataset) {
library(dplyr)
table7 <-psych::describe(dataset)
table7 <- table7 %>% select(n, mean, sd, min, max)
write.csv(table7,"data2I.csv")
}
mytable(Indian)
View(table7)
#P
library("psych")
table8 <-psych::describe(WHispanic)
setwd("~/東北/研究所/ALY6015/group")
write.csv(table8,"table8.csv")
mytable<- function(dataset) {
table8 <-psych::describe(dataset)
write.csv(table8,"table8.csv") }
mytable(WHispanic)
names(table8)
mytable<- function(dataset) {
library(dplyr)
table8 <-psych::describe(dataset)
table8 <- table8 %>% select(n, mean, sd, min, max)
write.csv(table8,"data2WH.csv")
}
mytable(WHispanic)
View(table8)
#Q
library("psych")
table9 <-psych::describe(BHispanic)
setwd("~/東北/研究所/ALY6015/group")
write.csv(table9,"table9.csv")
mytable<- function(dataset) {
table9 <-psych::describe(dataset)
write.csv(table9,"table9.csv") }
mytable(BHispanic)
names(table9)
mytable<- function(dataset) {
library(dplyr)
table9 <-psych::describe(dataset)
table9 <- table9 %>% select(n, mean, sd, min, max)
24 | P a g e
write.csv(table9,"data2BH.csv")
}
mytable(BHispanic)
#W
library("psych")
table10 <-psych::describe(White)
setwd("~/東北/研究所/ALY6015/group")
write.csv(table10,"table10.csv")
mytable<- function(dataset) {
table10 <-psych::describe(dataset)
write.csv(table10,"table10.csv") }
mytable(White)
names(table10)
mytable<- function(dataset) {
library(dplyr)
table10 <-psych::describe(dataset)
table10 <- table10 %>% select(n, mean, sd, min, max)
write.csv(table10,"data2W.csv")
}
mytable(White)
anova<- aov(stopped~sex, data= data)
summary(anova)
25 | P a g e
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )