Professional Documents
Culture Documents
Safety in Delhi Districts
Safety in Delhi Districts
Exercise-1
Date: 29 August 2022
Note: Work on this exercise tonight. We will discuss this in the class tomorrow.
A survey was conducted to assess the feeling of safety of adult males and females in different
districts of Delhi. The collected data is enclosed. Note that the data file provides the number of
males and females who feel safe or unsafe in different districts. We want to estimate the effect of
gender and district on feeling of safety.
a. Identify the explanatory and response variables. What are their scales of measurement?
b. Is the response a random variable? If yes, what distribution is it likely to follow? What
assumptions did you make to identify the distribution?
c. State the problem in terms of a statistical model.
d. Find the effect of districts on feeling of safety. Construct a suitable contingency table
(marginal table) and study the effect.
e. Study the effect of gender on feeling of safety using a marginal table.
f. Construct partial tables to verify whether the feeling of safety across districts changes as the
gender changes. In other words, examine whether gender and districts have an interaction
effect on feeling of safety. How will you examine the interaction effect graphically?
[18]: safety_data
1
6 North West Female 14 32 46 NaN NaN
7 Outer Female 9 42 51 NaN NaN
8 Rohini Female 30 25 55 NaN NaN
9 Shahdara Female 4 15 19 NaN NaN
10 South Female 8 29 37 NaN NaN
11 South East Female 17 24 41 NaN NaN
12 South West Female 4 16 20 NaN NaN
13 West Female 12 27 39 NaN NaN
14 Central Male 7 15 22 NaN NaN
15 Dwarka Male 5 22 27 NaN NaN
16 East Male 9 21 30 NaN NaN
17 New Delhi Male 1 1 2 NaN NaN
18 North Male 7 18 25 NaN NaN
19 North East Male 6 34 40 NaN NaN
20 North West Male 10 36 46 NaN NaN
21 Outer Male 9 28 37 NaN NaN
22 Rohini Male 20 23 43 NaN NaN
23 Shahdara Male 7 20 27 NaN NaN
24 South Male 9 27 36 NaN NaN
25 South East Male 8 31 39 NaN NaN
26 South West Male 5 13 18 NaN NaN
27 West Male 11 23 34 NaN NaN
[19]: safety_data.columns
[19]: Index(['District', 'Gender', 'Unsafe', 'Safe', 'Sum', 'Unnamed: 5', ' '],
dtype='object')
[21]: safety_data.sort_values(by='District',inplace=True)
[22]: safety_data.reset_index(inplace=True,drop=True)
[8]: safety_data
2
10 North East Female 7 21 28
11 North East Male 6 34 40
12 North West Female 14 32 46
13 North West Male 10 36 46
14 Outer Male 9 28 37
15 Outer Female 9 42 51
16 Rohini Female 30 25 55
17 Rohini Male 20 23 43
18 Shahdara Male 7 20 27
19 Shahdara Female 4 15 19
20 South Male 9 27 36
21 South Female 8 29 37
22 South East Male 8 31 39
23 South East Female 17 24 41
24 South West Male 5 13 18
25 South West Female 4 16 20
26 West Female 12 27 39
27 West Male 11 23 34
[28]: safety_data_partial_table.insert(5,'Unsafe_percentage','')
[30]: safety_data_partial_table
3
18 Shahdara Male 7 20 27 25.93
19 Shahdara Female 4 15 19 21.05
20 South Male 9 27 36 25.00
21 South Female 8 29 37 21.62
22 South East Male 8 31 39 20.51
23 South East Female 17 24 41 41.46
24 South West Male 5 13 18 27.78
25 South West Female 4 16 20 20.00
26 West Female 12 27 39 30.77
27 West Male 11 23 34 32.35
[35]: safety_data_marginal.drop(['Gender'],axis=1)
4
[42]: safety_data_marginal_table = safety_data_marginal.
,→groupby(['District'],as_index=False).sum()
[47]: safety_data_marginal_table.insert(4,'Unsafe_percentage','')
[49]: safety_data_marginal_table
[50]: safety_data_marginal_table.Unsafe_percentage.plot()
[50]: <AxesSubplot:>
5
[ ]: