Observed versus Expected – Chi Square Test

in R

http://rpubs.com/newajay/chisquaretest

#http://www.r-tutor.com/elementary-statistics/goodness-fit/chi-squared-test-independence

library(MASS)
tbl = table(survey$Smoke, survey$Exer)
tbl
##        
##         Freq None Some
##   Heavy    7    1    3
##   Never   87   18   84
##   Occas   12    3    4
##   Regul    9    1    7
table(survey$Smoke)
## 
## Heavy Never Occas Regul 
##    11   189    19    17
dim(survey)
## [1] 237  12
#Test the hypothesis whether the students 
#smoking habit is independent of
#their exercise level at .05 significance level.
chisq.test(tbl)
## Warning in chisq.test(tbl): Chi-squared approximation may be incorrect
## 
##  Pearson's Chi-squared test
## 
## data:  tbl
## X-squared = 5.4885, df = 6, p-value = 0.4828
#As the p-value 0.4828 is greater than the .05 significance level, we do not reject the null hypothesis that the smoking habit is 
#independent of the exercise level of the students.
ctbl = cbind(tbl[,"Freq"], tbl[,"None"] + tbl[,"Some"]) 
ctbl 
##       [,1] [,2]
## Heavy    7    4
## Never   87  102
## Occas   12    7
## Regul    9    8
chisq.test(ctbl)
## 
##  Pearson's Chi-squared test
## 
## data:  ctbl
## X-squared = 3.2328, df = 3, p-value = 0.3571
#As the p-value 0.3571 is greater than the .05 significance level, we do not reject the null hypothesis that the smoking habit is 
#independent of the exercise level of the students.


#The warning message found in the solution
#above is due to the small cell values in
#the contingency table. 

in Python

https://github.com/decisionstats/pythonfordatascience/blob/master/chi%2Bsquare%2Btest.ipynb

In [11]:
from scipy.stats import chi2_contingency
import numpy as np
In [13]:
obs = np.array([[7, 87, 12,9], [4, 102, 7,8]])
In [15]:
chi2, p, dof, expected = chi2_contingency(obs)
In [16]:
print (p)
0.357103080041
In [17]:
print (chi2)
3.23281822261
In [18]:
print (dof)
3
In [19]:
print (expected)
[[  5.36016949  92.09745763   9.25847458   8.28389831]
 [  5.63983051  96.90254237   9.74152542   8.71610169]]
In [ ]:

Analysing NDA martyrs using R #rstats

NDA – National Defence Academy

The National Defence Academy (NDA) is the Joint Services academy of the Indian Armed Forces, where cadets of the three services, the Army, the Navy and the Air Force train together before they go on to pre-commissioning training in their respective service academies. The NDA is located at Khadakwasla near Pune, Maharashtra. It is the first tri-service academy in the world.

NDA alumni have led and fought in every major conflict in which the Indian Armed Forces has been called to action since the academy was established. The alumni include 3 Param Vir Chakra recipients and 9 Ashoka Chakra recipients. National Defence Academy has produced 27 service Chiefs Of Staff till date. Current Chiefs Of Staff of the Army, the Navy and the Air Force are all NDA alumni.

http://rpubs.com/newajay/ndamartyrs

library(XML)
url="http://nda.nic.in/martyrs.html"
tables=readHTMLTable(url)
str(tables)
## List of 13
##  $ NULL   :'data.frame': 303 obs. of  5 variables:
##   ..$ V1: Factor w/ 23 levels "","2/LT","BRIG",..: 1 1 1 8 1 18 17 17 16 1 ...
##   ..$ V2: Factor w/ 279 levels "","A    BANDYOPADHYAY",..: 79 NA NA NA NA NA 89 NA NA NA ...
##   ..$ V3: Factor w/ 183 levels "","-","1    DOGRA",..: NA NA NA NA NA NA NA NA NA NA ...
##   ..$ V4: Factor w/ 91 levels "1","10","100",..: NA NA NA NA NA NA NA NA NA NA ...
##   ..$ V5: Factor w/ 16 levels "A","B","C","D",..: NA NA NA NA NA NA NA NA NA NA ...
##  $ NULL   :'data.frame': 301 obs. of  5 variables:
##   ..$ V1: Factor w/ 23 levels "","2/LT","BRIG",..: 1 8 1 18 17 17 16 1 14 20 ...
##   ..$ V2: Factor w/ 278 levels "","A    BANDYOPADHYAY",..: NA NA NA NA 88 NA NA NA NA 139 ...
##   ..$ V3: Factor w/ 183 levels "","-","1    DOGRA",..: NA NA NA NA NA NA NA NA NA 183 ...
##   ..$ V4: Factor w/ 91 levels "1","10","100",..: NA NA NA NA NA NA NA NA NA 91 ...
##   ..$ V5: Factor w/ 16 levels "A","B","C","D",..: NA NA NA NA NA NA NA NA NA 16 ...
##  $ NULL   : NULL
##  $ NULL   :'data.frame': 295 obs. of  5 variables:
##   ..$ V1: Factor w/ 21 levels "","2/LT","BRIG",..: 16 15 1 13 18 10 11 4 9 9 ...
##   ..$ V2: Factor w/ 278 levels "","A    BANDYOPADHYAY",..: NA NA NA NA 139 199 165 148 87 163 ...
##   ..$ V3: Factor w/ 183 levels "","-","1    DOGRA",..: NA NA NA NA 183 138 104 112 179 179 ...
##   ..$ V4: Factor w/ 91 levels "1","10","100",..: NA NA NA NA 91 18 49 2 9 10 ...
##   ..$ V5: Factor w/ 16 levels "A","B","C","D",..: NA NA NA NA 16 1 1 1 1 1 ...
##  $ NULL   :'data.frame': 284 obs. of  5 variables:
##   ..$ V1: Factor w/ 21 levels "","2/LT","BRIG",..: 16 15 1 13 18 10 11 4 9 9 ...
##   ..$ V2: Factor w/ 276 levels "A    BANDYOPADHYAY",..: NA NA NA NA 137 197 163 146 86 161 ...
##   ..$ V3: Factor w/ 182 levels "-","1    DOGRA",..: NA NA NA NA 182 137 103 111 178 178 ...
##   ..$ V4: Factor w/ 91 levels "1","10","100",..: NA NA NA NA 91 18 49 2 9 10 ...
##   ..$ V5: Factor w/ 16 levels "A","B","C","D",..: NA NA NA NA 16 1 1 1 1 1 ...
##  $ NULL   :'data.frame': 1 obs. of  1 variable:
##   ..$ Our Heroes: Factor w/ 1 level "": 1
##  $ martyrs: NULL
##  $ martyrs:'data.frame': 272 obs. of  5 variables:
##   ..$ RANK  : Factor w/ 15 levels "2/LT","BRIG",..: 9 10 3 8 8 6 13 1 1 1 ...
##   ..$ NAME  : Factor w/ 270 levels "A    BANDYOPADHYAY",..: 192 158 141 85 156 64 181 80 260 135 ...
##   ..$ UNIT  : Factor w/ 179 levels "-","1    DOGRA",..: 135 103 111 176 176 175 175 130 121 162 ...
##   ..$ COURSE: Factor w/ 90 levels "1","10","100",..: 18 49 2 9 10 12 13 16 16 17 ...
##   ..$ SQN   : Factor w/ 15 levels "A","B","C","D",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ martyrs: NULL
##  $ martyrs:'data.frame': 5 obs. of  5 variables:
##   ..$ RANK  : Factor w/ 4 levels "CAPT","FLG OFFR",..: 2 1 1 3 4
##   ..$ NAME  : Factor w/ 5 levels "GR SINGH","JS MALIK",..: 5 3 1 4 2
##   ..$ UNIT  : Factor w/ 4 levels "5 ASSAM","5 SIKH",..: 4 2 1 4 3
##   ..$ COURSE: Factor w/ 5 levels "23","26","28",..: 3 4 5 2 1
##   ..$ SQN   : Factor w/ 5 levels "D","H","J","K",..: 1 2 3 4 5
##  $ NULL   :'data.frame': 10 obs. of  3 variables:
##   ..$ V1: Factor w/ 1 level "": 1 1 1 1 1 1 1 1 1 1
##   ..$ V2: Factor w/ 2 levels "","JOINING INSTRUCTIONS - 136TH COURSE\r\n                      \r\n                     SUO MOTU DISCLOSURE UNDER"| __truncated__: 1 1 1 1 1 1 2 1 2 1
##   ..$ V3: Factor w/ 1 level "": NA NA NA NA NA NA NA NA NA 1
##  $ NULL   :'data.frame': 1 obs. of  2 variables:
##   ..$ : Factor w/ 1 level "": 1
##   ..$ : Factor w/ 1 level "JOINING INSTRUCTIONS - 136TH COURSE\r\n                      \r\n                     SUO MOTU DISCLOSURE UNDER"| __truncated__: 1
##  $ NULL   :'data.frame': 1 obs. of  1 variable:
##   ..$ V1: Factor w/ 1 level "Designed & Developed by National Defence Academy. Site hosted by NIC. \r\n    Copyright 2014 National Defence A"| __truncated__: 1
names(tables)
##  [1] "NULL"    "NULL"    "NULL"    "NULL"    "NULL"    "NULL"    "martyrs"
##  [8] "martyrs" "martyrs" "martyrs" "NULL"    "NULL"    "NULL"
tables[8]
## $martyrs
##         RANK                                        NAME
## 1     LT COL                                 RP    SINGH
## 2        MAJ                                 PS    RAMAN
## 3       CAPT                                NM    CHADHA
## 4     LT CDR                    JOGINDER    KRISHNA PURI
## 5     LT CDR                            PRABHAT    KUMAR
## 6     FLT LT                                 GS    AHUJA
## 7    SQN LDR                               RC    SACHDEV
## 8       2/LT                                  IM    KHAN
## 9       2/LT                                VN    ATHALE
## 10      2/LT                                 NC    KOHLI
## 11       COL                                SSS    RAMAN
## 12      CAPT                            MANJEET    SINGH
## 13      CAPT                                 PK    JOHRI
## 14       MAJ                             SP    SINGH, SM
## 15      2/LT                                 VR    DUBAL
## 16      BRIG                                  BS SHERGIL
## 17      CAPT                                YV    PRASAD
## 18       MAJ                          MANWINDRA    SINGH
## 19       MAJ                                    A MATHUR
## 20      CAPT                            R    SUBRAMANIAM
## 21   SQN LDR                                 PK CHHIKARA
## 22      CAPT                              AMIT    SEMVAL
## 23      CAPT                                KHAWAR SAEED
## 24      CAPT                                 SS    MALIK
## 25    FLT LT                                  AMIT SINGH
## 26    LT COL                              ONKAR    SINGH
## 27   SQN LDR                                 NK    MALIK
## 28       MAJ                          YOGENDRA    TANDON
## 29       MAJ                                   SM    DEV
## 30      CAPT             GS    SALARIA, PVC (Posthumous)
## 31       MAJ             SM    SHARMA, Vr C (Posthumous)
## 32       MAJ                            RANVEER    SINGH
## 33       MAJ                             VR    CHOUDHARY
## 34        LT                            MANVEER    SINGH
## 35       MAJ                                 GC    VERMA
## 36       MAJ                              BS    RANDHAWA
## 37      2/LT                                  S    DAGAR
## 38       MAJ                                 BS    MEHTA
## 39       MAJ                             BHAGAT    SINGH
## 40        LT                             SH    KUNDANMAL
## 41      2/LT                           MARINDER    SINGH
## 42      2/LT                              GK    MOHINDRA
## 43      2/LT                                   DK    DAS
## 44      2/LT                                 KJ    SINGH
## 45   SQN LDR                                 R    PUNDIR
## 46       MAJ                             PR    TATHAWADE
## 47       MAJ                           AJAY    PAL SINGH
## 48      2/LT            RAKESH    SINGH, AC (Posthumous)
## 49       MAJ                                    SJ SINGH
## 50      CAPT                                    VK SINGH
## 51      CAPT                     GURJINDER    SINGH SURI
## 52      CAPT                            NITIN    CHAVHAN
## 53      CAPT                          JAGDISH    CHANDRA
## 54      CAPT                            AMARJIT    SINGH
## 55    LT COL                                 RK    DIWAN
## 56      CAPT                                DPS    DUTTA
## 57        LT                                 MR    PALTA
## 58      CAPT                                 JS    MALIA
## 59      CAPT                             SURJIT    SINGH
## 60       MAJ                                SKS    WALIA
## 61    FLT LT                                 VV    TAMBE
## 62      2/LT                                 RVS    RANA
## 63        LT                                     PK GAUR
## 64        LT                             IGNATIOUS LOPEZ
## 65        LT                               UMA MAHESHWAR
## 66        LT                                   SEN GUPTA
## 67      2/LT                                  SS    GILL
## 68      2/LT                                 UC    GUPTA
## 69      2/LT                           NAVNEET    SWARAJ
## 70       MAJ                              DILIP    SINGH
## 71       MAJ                                MS    DAHIYA
## 72       MAJ                                 SUSHIL AIMA
## 73       MAJ                                 M    TALWAR
## 74       MAJ                            SAMEER    KOTWAL
## 75    FLT LT                         V    KRISHNAMURTHAY
## 76      CAPT                           HARI    RAJ KUMAR
## 77       MAJ                                 JOJY JOSEPH
## 78        LT                              ASHOK    KUMAR
## 79    FLT LT                                ANSHUL KHATI
## 80       MAJ                                 J    PRATAP
## 81    LT COL                                 MD    ANAND
## 82    LT COL                                  VP    GHAI
## 83       MAJ                                   MS    BAL
## 84    LT COL                                 D    NARANG
## 85    LT COL                                 SS    MALIK
## 86      CAPT                                KL    SHUKLA
## 87    FLT LT                                 VM    JOSHI
## 88      2/LT                               VK    GOSWAMI
## 89      2/LT                                 KS    GOPAL
## 90        LT                            CHARANJEET SINGH
## 91    LT COL                           R    VISHWANATHAN
## 92      CAPT                     RAVINDER    SINGH MADAR
## 93   SQN LDR                               AJAY    AHUJA
## 94      2/LT                             RAJESH    KUMAR
## 95       COL                                 NEERAJ SOOD
## 96       MAJ                             NAVNEET    VATS
## 97    FLT LT                                 SR    KAGDI
## 98      CAPT                            ADITYA    MISHRA
## 99      CAPT                           RAMESH    CHANDER
## 100      MAJ                              P SHYAM SUNDER
## 101     CAPT                               ATUL    SOMRA
## 102     CAPT                     BADAL    SINGH SIKARWAR
## 103      MAJ                                SR    MANDKE
## 104       LT                               BI    GOSWAMI
## 105       LT                                 DS    BARAR
## 106     2/LT                               CS    DHILLON
## 107     2/LT                         CHATRAPATI    SINGH
## 108     2/LT                              ROMESH    PURI
## 109      MAJ                                 DS    PANNU
## 110     2/LT                            HARJEET    SINGH
## 111     CAPT                          DALJINDER    SINGH
## 112      MAJ                          RANJIT    MUTHANNA
## 113      COL                                 JAI PRAKASH
## 114     CAPT                            SUNIL    CHANDRA
## 115   LT COL                               SCHNJ    RAJA
## 116      MAJ                                SS    SHARMA
## 117      MAJ                               ROHIT    DUTT
## 118      COL                             GS    SARNA, KC
## 119     CAPT ARUN    SINGH JASROTIA, AC (Posthumous), SM
## 120     2/LT        PUNEET    NATH DUTT, AC (Posthumous)
## 121     CAPT                              ANUJ    NAYYAR
## 122     CAPT                          KC    DHARASHIVKAR
## 123     CAPT                       AMIT    KUMAR CHANDAN
## 124      MAJ                                PUNEET KAROL
## 125       LT                            RANJEET    SINGH
## 126   LT CDR                          RAJAT    KUMAR SEN
## 127   FLT LT                             TK    CHAUDHARY
## 128     CAPT                             GP    BHATNAGAR
## 129     CAPT                                  AK    DUTT
## 130       LT                                SC    CHAWLA
## 131     2/LT                         GURUCHARAN    SINGH
## 132      MAJ                    MANMOHAN SINGH BAJAJ, SC
## 133     CAPT                                HC    GUJRAL
## 134   FLT LT                     HARBIR    SINGH SHIROHI
## 135      MAJ                                  RD    VATS
## 136   FLT LT                                 RB    MEHTA
## 137     CAPT                               KS    CHILLAR
## 138      MAJ                                 RK    ARORA
## 139     2/LT                                KS    PIRHAR
## 140       LT                            RAVI    LARORIYA
## 141      MAJ                           YASHJIT    SEHGAL
## 142   FLT LT                                  PV    APTE
## 143     CAPT                                 RM    GUPTA
## 144     CAPT                                MS    DUGGAL
## 145     CAPT                              MS    PATHANIA
## 146     2/LT                            VP    SINGH, VrC
## 147      COL                                    DJ SINGH
## 148     2/LT         ARUN    KHETARPAL, PVC (Posthumous)
## 149      MAJ                                NJD    SINGH
## 150     CAPT                       ARUN    SHANKAR KURUR
## 151   LT COL                               MAHAVIR SINGH
## 152    MAJOR                              GURPREET SINGH
## 153     CAPT                              RAJESH    GARG
## 154   WG CDR                             RS DHALIVAL, VM
## 155      MAJ                                MH PITAMBARE
## 156     CAPT                           JITESH    BHUTANI
## 157      MAJ                          N    JAWAHAR REDDY
## 158     CAPT                                RVR    REDDY
## 159      MAJ                         RUSHIKESH BB RAMANI
## 160     CAPT                           RAJINDER    SINGH
## 161     CAPT                                 BB    GHOSH
## 162      MAJ                               CHAMAN    LAL
## 163   FLT LT                               S    BHARDWAJ
## 164     2/LT                          AMIR    LAKHAN PAL
## 165     CAPT                                RC    BAKSHI
## 166      MAJ                                AK    KANNAL
## 167      MAJ                                JVS    MAKIN
## 168     CAPT                               DS    AHLAWAT
## 169     2/LT                               M    GHANEKAR
## 170     2/LT                                B    MASSAND
## 171     2/LT                             KR    BHADBHADE
## 172      COL                                     PB GOLE
## 173   LT COL                          AJIT    BHANDARKAR
## 174      MAJ                              SANJAY    SOOD
## 175  SQN LDR                                SANDEEP JAIN
## 176     CAPT                        RAVINDRA    CHIKKARA
## 177     CAPT                            PANKAJ    SHARMA
## 178       LT                              GAUTAM    JAIN
## 179       LT                               SS    DHINDSA
## 180     CAPT                  HARSHAN R, AC (Posthumous)
## 181   FLT LT                                    AB KOLHE
## 182     CAPT                                DS    JASWAL
## 183      MAJ                                  KS    RANA
## 184      MAJ                                  KR    PURI
## 185   LT COL                                 IBS    BAWA
## 186     CAPT                               SP    DHINGRA
## 187     2/LT                                SK    JASWAL
## 188   LT COL                                AS    SEKHON
## 189     2/LT                            MPS    CHOUDHARY
## 190      MAJ                                 SM    BHATT
## 191     CAPT                             PRAMOD    JOLLY
## 192   SUB LT                           SARAN    SURENDRA
## 193   FLT LT                                     S SINGH
## 194 FLG OFFR                                  UP BHAGWAT
## 195   FLT LT                                 M    TRIKHA
## 196      MAJ                            MUKESH CHAURASIA
## 197     CAPT                          A    BANDYOPADHYAY
## 198     CAPT                              MMS    GAMBHIR
## 199   LT CDR                                ASHOK    RAI
## 200     CAPT                                  G    MUBAI
## 201     2/LT                                PK    UKPPAL
## 202     CAPT                                KS    RATHEE
## 203     CAPT                                 U    RAMDAS
## 204 FLG OFFR                                  PK    SAHU
## 205      COL             NJ    NAIR, AC (Posthumous), KC
## 206      MAJ                                 SANTANU NAG
## 207      MAJ                                 U    JAITLY
## 208     CAPT                          DHANWANT    SHARMA
## 209     CAPT                                 S    BURMAN
## 210      MAJ                             DEEPAK    RAWAT
## 211      MAJ                                 AS BHADURIA
## 212     CAPT                      AMARDEEP    SINGH SARA
## 213      MAJ           MOHIT SHARMA, AC (Posthumous), SM
## 214 PLT OFFR                              RB    UMRALKAR
## 215      MAJ                            RK    CHATURVEDI
## 216      MAJ                              MANOJ    KUMAR
## 217     CAPT                            N    MURLIDHARAN
## 218     2/LT                             RAMESH    RAWAT
## 219      MAJ SUDHIR    KUMAR WALIA, AC (Posthumous), SM*
## 220      MAJ                              AK    TRIPATHI
## 221      MAJ                      MILTON    BOBAN KURIAN
## 222   WG CDR                                    D BHATIA
## 223      MAJ                             YOGESH    GUPTA
## 224     CAPT                              KEVIN    KUMAR
## 225       LT                               AMIT    SINGH
## 226     CAPT                               GAUTAM SHARMA
## 227     CAPT                                  KS    MANN
## 228       LT                             VIKRAM    SINGH
## 229     2/LT                                RPS    KALRA
## 230      MAJ                         SATPRAKASH    VERMA
## 231     CAPT                               SPS    SEKHON
## 232     2/LT                                 V    KAYAST
## 233      MAJ                                LM    BHATIA
## 234     2/LT                               VP SAPATNEKAR
## 235     CAPT                                 HK    MEHTA
## 236     2/LT                               N    SHISODIA
## 237     2/LT                               SK    VASHIST
## 238     CAPT                             SANJAY    DOGRA
## 239      MAJ             RK    JOON, AC (Posthumous), SC
## 240      MAJ                              VIVEK    GUPTA
## 241     CAPT                         SHAILESH    RIALACH
## 242     CAPT                               SUMEET    ROY
## 243      MAJ                             SAMRAT    MAITI
## 244       LT                             PANKAJ    JUYAL
## 245   FLT LT                               A SHARMA, VSM
## 246   FLT LT                                   TS CHAVAN
## 247      MAJ                           SURINDER    KUMAR
## 248       LT                        PAWAN    KUMAR SINGH
## 249     2/LT                                  LS    MODI
## 250     2/LT                                 IK    GUPTA
## 251     CAPT                                 PN    PATHE
## 252     2/LT                            KAMAL    GAMBHIR
## 253       LT                                 AG    PATIL
## 254     2/LT                                RM    NARESH
## 255      MAJ                           SANJAY    LOHCHAB
## 256  SQN LDR                          SANJAY    BHARDWAJ
## 257      MAJ                          LALSON    VARGHESH
## 258       LT                             HEMANT    SINGH
## 259      MAJ                          SALAMAN AHMAD KHAN
## 260     CAPT                                     VK RANA
## 261  SQN LDR                                   KR MURTHY
## 262   FLT LT                              ABHIJIT GADGIL
## 263     CAPT     MANOJ    KUMAR PANDEY, PVC (Posthumous)
## 264     CAPT                            SOORAJ    SHARMA
## 265     CAPT                                    NS SIDHU
## 266  SQN LDR                                  S BASU, SC
## 267       LT            ATUL    KATARIA, SM (Posthumous)
## 268   LT CDR                           SAURABH    SAXENA
## 269   FLT LT                                   RK SERRAO
## 270     CAPT                               AMOL    KALIA
## 271      MAJ       SANDEEP UNNIKRISHNAN, AC (Posthumous)
## 272     <NA>                                        <NA>
##                      UNIT COURSE  SQN
## 1               7    PARA      2    A
## 2            4    SIKH LI      6    A
## 3            5    FD REGT     10    A
## 4                      IN     11    A
## 5                      IN     12    A
## 6                     IAF     14    A
## 7                     IAF     15    A
## 8            65    FD COY     18    A
## 9       52    PARA FD BTY     18    A
## 10            9    PUNJAB     19    A
## 11          340INF    BDR     25    A
## 12          35    LT REGT     28    A
## 13              4/5    GR     34    A
## 14         5/5    GR (FF)     34    A
## 15              4    PARA     37    A
## 16            HQ 7 SEC RR     39    A
## 17         1    PARA (SF)     56    A
## 18               28    RR     73    A
## 19              ENGINEERS     77    A
## 20         1    PARA (SF)     87    A
## 21                    IAF     88    A
## 22            16    DOGRA     91    A
## 23               7 KUMAON     96    A
## 24        10    PARA (SF)     99    A
## 25                    IAF     99    A
## 26         10    GARH RIF      1    B
## 27                    IAF      2    B
## 28            4    RAJPUT      4    B
## 29          85    LT REGT      7    B
## 30              3/1    GR     10    B
## 31              8 JAK RIF     11    B
## 32           19    PUNJAB     13    B
## 33         9    ENGR REGT     13    B
## 34           4    INF DIV     16    B
## 35             3    DOGRA     17    B
## 36            4    RAJPUT     18    B
## 37              1    SIKH     19    B
## 38        70    ARMD REGT     19    B
## 39            6    GUARDS     20    B
## 40                     IN     22    B
## 41          14    FD REGT     25    B
## 42              6/5    GR     26    B
## 43           12    KUMAON     37    B
## 44            14    HORSE     37    B
## 45                    IAF     62    B
## 46            8    JAK LI     64    B
## 47            3R    O FLT     74    B
## 48       22    GRANADIERS     79    B
## 49               12 DOGRA     79    B
## 50                   ARTY     84    B
## 51            12    BIHAR     90    B
## 52       115    ENGR REGT     92    B
## 53           18    FD COY      4    C
## 54            5    GUARDS      7    C
## 55        70    ARMD REGT      8    C
## 56           3    JAK RIF     14    C
## 57              4    SIKH     15    C
## 58          3    GARH RIF     16    C
## 59              7    SIKH     21    C
## 60          82    LT REGT     22    C
## 61                    IAF     22    C
## 62       19    MARATHA LI     24    C
## 63                   ARTY     25    C
## 64                      -     33    C
## 65                      -     33    C
## 66                      -     33    C
## 67             9    HORSE     35    C
## 68           1    JAK RIF     35    C
## 69         39    MED REGT     37    C
## 70         8    ENGR REGT     63    C
## 71           18    MADRAS     66    C
## 72                    ADA     73    C
## 73             9    MAHAR     81    C
## 74           21    KUMAON     85    C
## 75                    IAF     87    C
## 76        9    GRENADIERS     90    C
## 77          14 MARATHA LI     92    C
## 78             2    DOGRA     96    C
## 79                    IAF    108    C
## 80         163    FD REGT      2    D
## 81          67    FD REGT      5    D
## 82           16    MADRAS      5    D
## 83           7    CAVALRY      6    D
## 84          45    CAVALRY      9    D
## 85         9    ENGR REGT      9    D
## 86          4    SIKH LIU     11    D
## 87                    IAF     16    D
## 88          4    GARH RIF     17    D
## 89              4/8    GR     25    D
## 90                   ARTY     28    D
## 91       18    GRENADIERS     58    D
## 92           5    RAJ RIF     60    D
## 93                    IAF     66    D
## 94              14    JAT     73    D
## 95              8 RAJ RIF     81    D
## 96               92    RR     85    D
## 97                    IAF     87    D
## 98                SINGALS     88    D
## 99           14    RAJPUT     90    D
## 100     38 RR (10 MADRAS)     90    D
## 101        77    MED REGT     93    D
## 102         80    FD REGT     95    D
## 103             1/8    GR      7    E
## 104        22    MTN REGT     15    E
## 105           4    RAJPUT     15    E
## 106        22    MTN REGT     16    E
## 107           4    RAJPUT     17    E
## 108          5    FD REGT     19    E
## 109             5    SIKH     20    E
## 110           10    MAHAR     24    E
## 111            9    HORSE     28    E
## 112           5    RAJPUT     41    E
## 113    120 INF BN (BIHAR)     49    E
## 114            8    MAHAR     63    E
## 115        298    FD REGT     64    E
## 116         10    SIKH LI     69    E
## 117        513    AD REGT     71    E
## 118       9    GRENADIERS     71    E
## 119        9    PARA (SF)     73    E
## 120            1/11    GR     87    E
## 121             17    JAT     90    E
## 122           8    MADRAS     90    E
## 123      21    GRENADIERS     91    E
## 124        8 R&O FLT ARTY     94    E
## 125            14    SIKH     98    E
## 126                    IN      9    F
## 127                   IAF     11    F
## 128     52    PARA FD BTY     12    F
## 129          6    FD REGT     13    F
## 130     52    PARA FD BTY     15    F
## 131          5    FD REGT     16    F
## 132                     -     17    F
## 133              5    JAT     19    F
## 134                   IAF     19    F
## 135              3    JAT     21    F
## 136                   IAF     22    F
## 137       8    GRENADIERS     23    F
## 138           9    PUNJAB     23    F
## 139          2    RAJ RIF     24    F
## 140                  ARTY     25    F
## 141           15    DOGRA     27    F
## 142                   IAF     27    F
## 143        9    EMGR REGT     28    F
## 144        93    MTN REGT     29    F
## 145            5/11    GR     29    F
## 146        5/5    GR (FF)     35    F
## 147                1/5 GR     37    F
## 148           17    HORSE     38    F
## 149             4/5    GR     50    F
## 150        19    GARH RIF     65    F
## 151                 35 AR     68    F
## 152                 11 RR     76    F
## 153           ARMY    AVN     81    F
## 154                   IAF     86    F
## 155           3 PARA (SF)     88    F
## 156        5    ARMD REGT     89    F
## 157             2/8    GR     90    F
## 158         69    FD REGT     93    F
## 159             23 PUNJAB    106    F
## 160             6/8    GR     10    G
## 161             2/8    GR     11    G
## 162        99    MTN REGT     15    G
## 163                   IAF     18    G
## 164           1    MADRAS     19    G
## 165             6/8    GR     19    G
## 166             4    PARA     21    G
## 167            5    ASSAM     22    G
## 168           10    DOGRA     31    G
## 169       5    MARATHA LI     35    G
## 170             7    PARA     35    G
## 171       71    ARMD REGT     35    G
## 172                 9 JAT     52    G
## 173              25    RR     59    G
## 174              21    RR     72    G
## 175                   IAF     72    G
## 176       6    GRENADIERS     93    G
## 177          14    PUNJAB     94    G
## 178        178    FD REGT     96    G
## 179          19    PUNJAB     97    G
## 180           2 PARA (SF)    101    G
## 181                   IAF    103    G
## 182          7    CAVALRY     17    H
## 183          15    RAJPUT     23    H
## 184             4/5    GR     25    H
## 185             4/5    GR     30    H
## 186      106    ENGR REGT     31    H
## 187            1    DOGRA     35    H
## 188           7    MADRAS     35    H
## 189           10    BIHAR     39    H
## 190            102    BDE     42    H
## 191             12    JAT     51    H
## 192                    IN     75    H
## 193                   IAF     84    H
## 194                   IAF     86    H
## 195                   IAF     88    H
## 196             INT CORPS     91    H
## 197             1/4    GR     95    H
## 198             1/9    GR     10    I
## 199                    IN     16    I
## 200            2    DOGRA     23    I
## 201            2    DOGRA     24    I
## 202              8    JAT     33    I
## 203             7    PARA     33    I
## 204                   IAF     33    I
## 205      16    MARATHA LI     38    I
## 206                2/1 GR     69    I
## 207            3/11    GR     71    I
## 208        299    FD REGT     79    I
## 209                  ARTY     82    I
## 210           ARMY    AVN     83    I
## 211             18 MADRAS     84    I
## 212        2    ENGR REGT     90    I
## 213           1 PARA (SF)     95    I
## 214                   IAF     36    J
## 215          5    RAJ RIF     50    J
## 216          11    MADRAS     56    J
## 217       5    MARATHA LI     58    J
## 218            1/11    GR     70    J
## 219        9    PARA (SF)     72    J
## 220            19    SIKH     77    J
## 221             5    SIKH     80    J
## 222                   IAF     81    J
## 223              25    RR     90    J
## 224        9    PARA (SF)     93    J
## 225             1/9    GR     96    J
## 226              8 JAK LI    104    J
## 227 62    INF BDE SIG COY     10    K
## 228           6    KUMAON     15    K
## 229          6    FD REGT     19    K
## 230             3/8    GR     22    K
## 231          2    RAJ RIF     22    K
## 232         16    CAVALRY     25    K
## 233          15    RAJPUT     25    K
## 234                 ENGRS     29    K
## 235             3/4    GR     33    K
## 236             3/4    GR     37    K
## 237       58    ENGR REGT     38    K
## 238       1    MARATHA LI     69    K
## 239      22    GRANADIERS     78    K
## 240          2    RAJ RIF     80    K
## 241                   EME     91    K
## 242        18    GARH RIF     93    K
## 243             1    NAGA     95    K
## 244      201    ENGR REGT     98    K
## 245                   IAF     99    K
## 246                   IAF    100    K
## 247         69    FD REGT     10    L
## 248             3/9    GR     23    L
## 249        40    MED REGT     25    L
## 250        40    MED REGT     25    L
## 251             3    PARA     33    L
## 252      19    MARATHA LI     38    L
## 253                    IN     38    L
## 254              9    JAT     39    L
## 255             2/3    GR     71    L
## 256                   IAF     75    L
## 257           14    RR BN     88    L
## 258          17    GUARDS     94    L
## 259        INF 6 RR 4 SKH     94    L
## 260               9 HORSE     82    M
## 261                   IAF     86    M
## 262                   IAF     89    M
## 263            1/11    GR     90    M
## 264             2    PARA     92    M
## 265                 27 RR     95    M
## 266                   IAF     84    N
## 267          13    PUNJAB     88    N
## 268                    IN     92    N
## 269                   IAF    100    N
## 270          12    JAK LI     87    O
## 271               7 BIHAR     94    O
## 272                  <NA>   <NA> <NA>
martyrs=tables[8]$martyrs
str(martyrs)
## 'data.frame':    272 obs. of  5 variables:
##  $ RANK  : Factor w/ 15 levels "2/LT","BRIG",..: 9 10 3 8 8 6 13 1 1 1 ...
##  $ NAME  : Factor w/ 270 levels "A    BANDYOPADHYAY",..: 192 158 141 85 156 64 181 80 260 135 ...
##  $ UNIT  : Factor w/ 179 levels "-","1    DOGRA",..: 135 103 111 176 176 175 175 130 121 162 ...
##  $ COURSE: Factor w/ 90 levels "1","10","100",..: 18 49 2 9 10 12 13 16 16 17 ...
##  $ SQN   : Factor w/ 15 levels "A","B","C","D",..: 1 1 1 1 1 1 1 1 1 1 ...
attach(martyrs)
table(RANK)
## RANK
##     2/LT     BRIG     CAPT      COL FLG OFFR   FLT LT       LT   LT CDR 
##       43        1       74        7        2       19       23        5 
##   LT COL      MAJ    MAJOR PLT OFFR  SQN LDR   SUB LT   WG CDR 
##       13       70        1        1        9        1        2
library(RColorBrewer)

table(RANK)
## RANK
##     2/LT     BRIG     CAPT      COL FLG OFFR   FLT LT       LT   LT CDR 
##       43        1       74        7        2       19       23        5 
##   LT COL      MAJ    MAJOR PLT OFFR  SQN LDR   SUB LT   WG CDR 
##       13       70        1        1        9        1        2
hist(table(RANK),col = brewer.pal(9,"Oranges"),breaks = 15,xlab = RANK)

 

table(COURSE)
## COURSE
##   1  10 100 101 103 104 106 108  11  12  13  14  15  16  17  18  19   2 
##   1   6   2   1   1   1   1   1   5   2   3   2   7   6   5   4   9   3 
##  20  21  22  23  24  25  26  27  28  29  30  31  33  34  35  36  37  38 
##   2   3   7   5   4  10   1   2   4   3   1   2   8   2   8   1   6   5 
##  39   4  41  42  49   5  50  51  52  56  58  59   6  60  62  63  64  65 
##   3   2   1   1   1   2   2   1   1   2   2   1   2   1   1   2   2   1 
##  66  68  69   7  70  71  72  73  74  75  76  77  78  79   8  80  81  82 
##   2   1   3   3   1   4   3   4   1   2   1   2   1   3   1   2   4   2 
##  83  84  85  86  87  88  89   9  90  91  92  93  94  95  96  97  98  99 
##   1   4   2   3   5   6   2   3  10   4   4   5   5   5   4   1   2   3
hist(table(COURSE),col = brewer.pal(9,"Oranges"),breaks = 15,xlab = RANK)