Data analysis in social science research and AI

Prof. Indranil Dutta
School of Languages and Linguistics
Jadavpur University

Purpose of the lectures

What we will learn

Topics

Quantiative aspects of any analysis

Testing our hypotheses

Hypotheses

Sampling

Samples and populations

Statistical environment

Describing data

ncrb <- read.csv("NCRB-2021.csv", header=TRUE)
hist(ncrb$Arrested_Total)

head(ncrb)
##   Sl..No.                                          crime_head Arrested_Male
## 1       1                                              Murder          4907
## 2       2           Culpable Homicide not amounting to Murder           385
## 3       3                         Causing Death by Negligence          6261
## 4     3.1 Deaths due to Negligence relating to Road Accidents          5177
## 5   3.1.1                                         Hit and Run          1880
## 6   3.1.2                                     Other Accidents          3297
##   Arrested_Female Arrested_Transgender Arrested_Total Chargesheeted_Male
## 1             178                    2           5087               3950
## 2              12                    0            397                333
## 3             160                    0           6421               6202
## 4             150                    0           5327               5208
## 5              43                    0           1923               1875
## 6             107                    0           3404               3333
##   Chargesheeted._Female Chargesheeted_Transgender Chargesheeted_Total
## 1                   141                         2                4093
## 2                     9                         0                 342
## 3                   154                         0                6356
## 4                   143                         0                5351
## 5                    37                         0                1912
## 6                   106                         0                3439
##   Convicted_Male Convicted_Female Convicted_Transgender Convicted_Total
## 1            446               20                     0             466
## 2             44                0                     0              44
## 3           1118               47                     0            1165
## 4            772               46                     0             818
## 5            338               22                     0             360
## 6            434               24                     0             458
##   Discharged_Male Discharged_Female Discharged_Transgender Discharged_Total
## 1              16                 0                      0               16
## 2               4                 0                      0                4
## 3              61                 0                      0               61
## 4              58                 0                      0               58
## 5               6                 0                      0                6
## 6              52                 0                      0               52
##   Acquitted_Male Acquitted_Female Acquitted_Transgender Acquitted_Total
## 1            592               29                     0             621
## 2             53                0                     0              53
## 3           1184               14                     0            1198
## 4            734               11                     0             745
## 5            264                6                     0             270
## 6            470                5                     0             475
male_data=ncrb$Arrested_Male

female_data=ncrb$Arrested_Female

plot(male_data,female_data, main="Male Female data of arrests", xlab="Total number of males arrested", ylab="Total number of females arrested")

Generating data

x = round(rnorm(36,4.5,2))
x = rnorm(36, 4.5, 2)#notice that this is different from round(rnorm(36,4.5,2)) where we had asked for rounded/integer values
x
##  [1]  4.04586014  4.38159300  3.82399352  0.39672292  5.54689333  4.10067467
##  [7]  5.41834930  4.63787503  3.49470473  5.26120287  7.28048118  3.65898937
## [13]  5.80899707  5.86495062  1.64628987  3.71969255  4.00454054  5.99906269
## [19]  6.30300031  2.16548280  6.65337178  5.23121171  4.11077328  7.14945722
## [25]  3.10398847  4.52115090  6.39688798  5.81747550  7.20851970  6.26455324
## [31] -0.09690014  6.15190801  6.12879334  3.67732989  5.00083944  2.37631433
hist(x,breaks=30000, xlim = c(0,10))

hist(x, xlim = c(0,10))

#Lets look at another example
x = rnorm(10000, 4.5, 2)
hist(x,breaks=100,freq=FALSE,xlim = c(0,10))
plot(function(x)dnorm(x, mean=4.5, sd=2), 0,10, add=TRUE)

Frequency distribution in R

Theoretical distributions

Adding the normal curve

The normal distribution

Distribution types - Uniform

plot(function(x)dunif(x,min=-3,max=3), -3,3, main="Uniform")

Distribution - Normal

plot(function(x)dnorm(x), -3,3, main="Normal")

Distribution - Skewed right

plot(function(x)df(x, 3, 100), 0,4, main="Skewed right")

Distribution - J-shaped

plot(function(x)df(x, 1, 10)/3, 0.2,3, main="J-Shaped")

Distribution - Bimodal

plot(function(x)(dnorm(x, mean=3, sd=1)+dnorm(x, mean=-3, sd=1))/2,-6,6, main="Bimodal")

Distribution - U Shaped

plot(function(x)-dnorm(x),-3,3, main="U shaped")

Measures of central tendency

plot(function(x)df(x, 5, 100),0,4, main="Measures of central tendency")
lines(x=c(0.6,0.6),y=c(0,df(0.6,5,100)))
skew.data <-rf(10000,5,100)
lines(
  x=c(mean(skew.data),mean(skew.data)),
  y=c(0,df(mean(skew.data),5,100)))
lines(
  x=c(median(skew.data),median(skew.data)),
  y=c(0,df(median(skew.data),5,100))
)
text(1,0.75,labels="mode")
text(1.3,0.67,labels="median")
text(1.35,0.6,labels="mean")

Weighted means

The notion of deviation

Measures of dispersion

Why the n-1

Measures of Dispersion

Population standard deviation =\(\sqrt\sigma^2\)

Sample standard deviation s=\(\sqrt s^2\)

Relating our data with the normal distribution

Z-score normalization

\(z_i\)=\(\frac{x_i-\overline{x}}{s}\)

#View(ncrb)

x_bar_male = mean(ncrb$Arrested_Male)
sd_male = sd(ncrb$Arrested_Male)

z-score normlaization

\(z_i\)=\(\frac{x_i-\overline{x}}{s}\)

Standardization and probability

Central limit theorem

Probability density

# create sample data
sample_Data = rnorm(500)

# calculate CDF
CDF <- ecdf(sample_Data )

# draw the cdf plot
plot(CDF)

How to test hypotheses regarding means

H\(_0\): \(\mu\)

t-test: our first hypothesis test

Two-sample t-test

t.test(ncrb$Chargesheeted_Male, ncrb$Chargesheeted._Female, alternative = "two.sided", var.equal = FALSE)
## 
##  Welch Two Sample t-test
## 
## data:  ncrb$Chargesheeted_Male and ncrb$Chargesheeted._Female
## t = 2.8866, df = 59.618, p-value = 0.005416
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  1077.059 5940.807
## sample estimates:
## mean of x mean of y 
## 3741.3167  232.3833

Topics to look at individually

Research questions

Thank you