Statistical inference in quantitative analyses: Correlations and Model-fitting

Day 1

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]  3.97140775  5.08689321  5.17729375  8.20023746  3.06957316  5.79466757
##  [7]  4.66753117  7.19614977  6.94237176  1.02516118  3.60091181  7.08618677
## [13]  6.03737347  2.18349699  3.84640617  3.94052865  4.06714608  4.97069518
## [19]  3.27752935  1.15228733 -0.01937894  5.10308874  3.35191410  2.58478757
## [25]  8.60667044  1.08066772  4.42827309  7.71344363  5.07283930  1.41772009
## [31]  4.41576347  4.16155545  2.77593139  3.45994160  4.48977290  6.74695488
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

Day 2

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)