-
Notifications
You must be signed in to change notification settings - Fork 0
/
01-stat.Rmd
1477 lines (1061 loc) · 34.7 KB
/
01-stat.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# (PART) Statistics {-}
# Preliminary Concepts
## Statistics: What & How
<img src="img/stat.jpg"/>
## Topics
- What is statistics?
- How Statistics works?
- Probability and Statistics
- Application of Statistics
- Example Problem
## What is statistics?
Three Meanings
- Plural of statistic
- Table of data
- Methodology
## How Statistics works?
Takes a sample from a population.
<img src="img/Simple_random_sampling.png" alt="drawing" width="450"/>
There are many sampling techniques.
## Probability and Statistics
## Application of Statistics
<img src = "img/2250-02.jpg" width="650"/>
## Examples{.la}
- Identification of unwanted spam messages in e-mail
- Segmentation of customer behavior for targeted advertising
- Forecasts of weather behavior and long-term climate changes
- Prediction of popular election outcomes
- Development of algorithms for auto-piloting drones and self-driving cars
- Optimization of energy use in homes and office buildings
- Projection of areas where criminal activity is most likely
- Discovery of genetic sequences linked to diseases
## Chapter Overview
- Definition
- Population and sample
- Variable and its types
- Scale of measurement
- Use of summation sign
- Main Discussion
## Definition
**Coxton and Crowden**
*Statistics may be defined as the science of collection, presentation, analysis and interpretation of numerical data.*
## Mechanism
- Data Collection
- Organization
- Analysis
- Interpretation
- Presentation
## Population and Sample
**Population: A set of similar items or events which is of interest**
**Sample: Any subset of population**
<img src="img/Simple_random_sampling.png" alt="drawing" width="400"/>
- Finite
- Infinite
## Variable and Constant
- Variable
- Random Variable
- Constant
**Examples**
- Income of a regular employee
- Income of a freelancer
- Any unchanging number, e.g, $\pi$
- Result of a die throw
- Father's name
- Mark of a subject
- GPA of a student
## Types of Variable{#bluetext}
- Qualitative
- Quantitative
- Discrete: Limited and pre-specified
- Continuous: Can take on any values between any two given number
## Univariate, Multivariate
## Scale of Measurement
Describes nature of information within the values.
- Nominal: Name of Insignificant number, e.g., color, Street no.,
- Ordinal: Order matters, e.g., rating
- Interval: Zero may not be zero, like temperature
- Ratio: Zero is 0; most variables fall in this category
## Examples
- Gender
- Religion
- Temperature
- Income group (Lower class, Low, Middle, High)
- Income
- Distance of stars
- Radius of screws
- Diameter of trees
- Room no.
## Another Example
Match as per suitable scale
|Movie Rating | Scale |
| ------------- |-------------:|
| Poor, bad, good, excellent | ratio |
| **In a scale of -10 to 10:** -10, -2, 0, 5, 10 | interval |
| Awesome, Amazing, Mind-blowing, Stunning | nominal |
| **In a scale of 0 to 10:** 0, 5, 8, 10 | ordinal |
## Operation with scales
<img src="img/scale.png" alt="drawing" width="600"/>
## Shifting origin and scale
Say we have values, $x_1, x_2, \cdot \cdot \cdot , x_n$
- Origin shift: Adding/Subtracting
- $y_1 = x_1-a \space or \space x_1+a$
- Scale shift: Multiplying/Division
- $y_1 = b \cdot x_1 \space or \space x_1/b$
- both: $y_i = \frac{x_i-a}{b}$
## Use of Summation sign
$$x_1 + x_2 + x_3 + x_4 = \sum_{i=1}^4 x_i$$
$$x_1 + x_2 + ... x_n = \sum_{i=1}^n x_i$$
$$x_1 + x_2 + ... x_{10} = ?$$
## Theorems
1. $$\sum_{i=1}^n bx_i=b \sum_{i=1}^n x_i$$
2. $$\sum_{i=1}^n (ax_i-b)=a \sum_{i=1}^n x_i-nb$$
3. $$\sum_{i=1}^n (ax_i^2-bx_i+c)=a\sum_{i=1}^n x_i^2-b\sum_{i=1}^n x_i + nc$$
4. $$\sum_{i=1}^n (ax_i-by_i)=a\sum_{i=1}^n x_i - b \sum_{i=1}^n y_i$$
5. $$\sum_{i=1}^n (ax_i-b)^2=a^2 \sum_{i=1}^n x_i^2 - 2ab \sum_{i=1}^n x_i + nb^2$$
6. $$(\sum_{i=1}^n x_i)^2=\sum_{i=1}^n x_i^2 + \sum_{i \ne j}^n\sum x_ix_j$$
7. $$\prod_{i=1}^k x_iy_i = (\prod_{i=1}^k x_i)(\prod_{i=1}^k y_i)$$
8. $$\sum_{i=1}^m \sum_{i=1}^n (x_i+y_j)=n\sum_{i=1}^m x_i + m \sum_{i=1}^n y_j$$
9. m$\sum_{i=1}^m \sum_{i=1}^n (x_iy_j)=(\sum_{i=1}^n x_i) (\sum_{i=1}^n y_j)$
## Quick tips
- $\sum_{i=1}^n a = na$
- Can you prove it?
- $$\prod_{i=1}^k x_i = x_1 \times x_2 \times \cdot \cdot \cdot \times x_n$$
## Example
Given
$f_1=2, f_2 = 4, f_3 = 6$
$x_1 = -3, x_2 =7, x_3 = 4$
Find the values of
i. $\sum f_ix_i$
ii. $\sum f_ix_i^2$
iii. $\sum f_i(x_i-5)^2$
## Textbook Exercise -01
13. Find the value of $\sum_{i=1}^{10} (x_i-4)$
where $\sum_{i=1}^{10} x_i = 20$
## Exercises
Discrete vs continuous variable
Prove
$$\sum_{i=1}^k abx_i = ab \sum_{i=1}^k x_i$$
Prove
$$\prod_{i=1}^n c =c^n$$
Find the value of
$$\sum_{i=1}^{10} (x_i-4)$$
where
$$\sum_{i=1}^{10}=20$$
## Creative Questions
Given below are the daily income and expense of ten workers.
<section>
<table>
<thead><tr>
<th>Income (x)</th>
<th>120</th>
<th>130</th>
</tr></thead>
<tbody><tr>
<td>Expense (y)</td>
<td>80</td>
<td>120</td>
</tr>
</tbody>
</table>
</section>
From above data, prove
- $$\sum_{i=1}^{2}x_iy_i \ne (\sum_{i=1}^{2}x_i)(\sum_{i=1}^{2}y_j)$$
<br/>
- $$\sum_{i=1}^{2} \sum_{j=1}^{2}x_iy_j=(\sum_{i=1}^{2}x_i)(\sum_{j=1}^{2}y_j)$$
<br/>
- $$\sum_{i=1}^{2} \sum_{j=1}^{2}(x_i-y_j)=2 \times \sum_{i=1}^{2}x_i- 2 \times \sum_{j=1}^{2}y_j$$
**Question 02**
Given below are the daily income and expense of ten workers.
<section>
<table>
<thead><tr>
<th>Income (x)</th>
<th>120</th>
<th>130</th>
<th>88</th>
<th>150</th>
<th>175</th>
<th>144</th>
<th>180</th>
<th>200</th>
<th>160</th>
<th>155</th>
</tr></thead>
<tbody><tr>
<td>Expense (y)</td>
<td>80</td>
<td>120</td>
<td>70</td>
<td>100</td>
<td>160</td>
<td>114</td>
<td>170</td>
<td>195</td>
<td>140</td>
<td>131</td>
</tr>
</tbody>
</table>
</section>
a. What do you mean by bivariate data?
b. From above data, prove
$$\sum_{i=1}^{10} \sum_{j=1}^{10}x_iy_j=(\sum_{i=1}^{10}x_i)(\sum_{j=1}^{10}y_j)$$
c. $$\sum_{i=1}^{10} \sum_{j=1}^{10}(x_i-y_j)=10 \times \sum_{i=1}^{10}x_i- 10 \times \sum_{j=1}^{10}y_j$$
d. Prove $$\sum_{i=1}^{10}x_iy_i \ne (\sum_{i=1}^{10}x_i)(\sum_{i=1}^{10}y_j)$$
# Collection, Presentation, and Organization of Data
## Types of Data
- Qualitative
- Quantitative
## Sources of Data
- Primary: Obtained directly (not collected from someone else)
- Secondary: Using pre-collected data from someone else/some organization
**Example** (Guess Types)
- A researcher buys data from BMD to build a model of rainfall behavior
- A researcher runs an experiment to measure speed of light using a novel technique.
- A researcher makes use of the data generated by the one in example 2
## Method of Data Collection
- Direct personal Inquiry
- Indirect oral inquiry
- Mail
- Telephone etc.
- <div class ="bluetext">Each method has its own advantages and disadvantages;</div>
## Sources of Secondary Data
- Published: Scientific Journals, Newspapers etc.
- Unpublished: BBS, WHO, IMF, FAO, ICDDR,B
## Disadvantages of Secondary Data
- Purpose might be different
- Suitability
- Reliability
- Unit
## Tabluation
![](img/stat/table.jpg)
## Data Classification
- Geographical
- Chronological
- Quantitative
- Qualitative
## Example
<section>
Geographical
<table>
<thead><tr>
<th>Country</th>
<th>Bangladesh</th>
<th>USA</th>
</tr></thead>
<tbody><tr>
<td>GDP(m)</td>
<td>120</td>
<td>500</td>
</tr>
</tbody>
</table>
</section>
<section>
*Chronological (Time series data)*
<table>
<thead><tr>
<th>Year</th>
<th>2015</th>
<th>2016</th>
</tr></thead>
<tbody><tr>
<td>GDP(m)</td>
<td>120</td>
<td>500</td>
</tr>
</tbody>
</table>
</section>
<section>
*Quantitative Classification*
<table>
<thead><tr>
<th>Income level</th>
<th>40,000-50,000</th>
<th>50,000-1,00,000</th>
</tr></thead>
<tbody><tr>
<td>Frequency</td>
<td>120</td>
<td>34</td>
</tr>
</tbody>
</table>
</section>
## Histogram
- Inclusive vs exclusive
What does it tell us
```{r, echo=FALSE, out.width="70%"}
hist(rnorm(300, 20, 2), main = "A Histogram of Randam Data", xlab = "Intervals",
col = c("blue", "grey"))
```
## Histogram Intervals
Can these intervals be readily used?
(5-10); (10-15); (15-20)
(5-9); (10-14); (15-20)
If not, what should we do?
## Stem and Leaf
- key in stem and leaf plot
- How to interpret stem and leaf plot
```{r}
data <- c(16, 26, 12, 10, 27, 30, 14, 1, 25, 20)
stem(data)
```
## How to interpret cf and rf
| Class | Frequency | Cumulative <br><br>Frequency (cf) | Relative <br><br>Frequency (rf) | Cumulative <br><br>Relative <br><br>Frequency (crf) |
|:-:|:-:|:-:|:-:|:-:|
| 30-35 | 4 | 4 | 0.09 | 0.09 |
| 35-40 | 10 | 14 | 0.23 | 0.32 |
| 40-45 | 20 | 34 | 0.45 | 0.77 |
| 45-50 | 8 | 42 | 0.18 | 0.95 |
| 50-55 | 2 | 44 | 0.04 | 1 |
| | n=44 | n=44 | | |
## What Ogives tell us
```{r, echo=F, fig.show='hide'}
data <- c(16, 26, 12, 10, 27, 30, 14, 1, 25, 20)
h <- hist(data)
```
```{r, echo=F}
intervals <- seq(from = min(h$breaks), to = max(h$breaks), by = h$breaks[2] - h$breaks[1])
intervals <- c(0, intervals[-1])
## Cumulative sums
cf = c(0, cumsum(h$counts))
plot(intervals, cf, type = "b", col = "blue", pch = 20)
```
## Bar vs Pie
- When to use which?
- How to calculate angles?
- Can we draw on 180 degrees?
## Choose Diagram
<div class="container">
<div class="col">
| year | Sales ($) |
|-|-|
| 1996 | 76 |
| 1997 | 58 |
| 1998 | 95 |
| 1999 | 85 |
```{r, echo=FALSE, out.width="1100%"}
x <- c(76, 58, 95, 85)
pie(x, c(1996:1999),
col = c('#0292D8', '#F7EA39', '#C4B632'),
init.angle = 130, border = NA,
main="Is this a suitable choice of diagram")
```
</div>
<div class="col">
| Category | Cost(Tk.) |
|-|-|
| House rent | 10,000 |
| Utility Bill | 3,000 |
| Telecom | 2000 |
```{r, echo = F}
```
</div>
</div>
## Bar Diagram vs Histogram
# Measures of Central Tendency
## What is Central Tendency?
`r options(scipen=999)`
Why needed?
<div class="container">
<div class="col">
```{r, echo=F}
(h <- head(mtcars[1:5], 8))
summary(h[1:3])
```
</div>
<div class="col">
- Summary
- Comparison
- A value to represent all
</div>
</div>
## Criteria for a Good Measure of Central Tendency{data-transition="convex"}
- Well-defined
> - Understandable
> - Considers all values
> - Suitable for further analysis
> - Not affected by sample fluctuation
## Measures (Averages)
- Arithmetic Mean (AM)
- Geometric Mean (GM)
- Harmonic Mean (HM)
- Median
- Mode
- Partition Values (Quartiles, Deciles, Percentiles etc.)
## AM
$AM=\bar x=\frac{\sum x}{n}$
If there are frequencies or weights
$\bar x=\frac{\sum f_i x_i}{\sum f_i} \space or \space \frac{\sum w_i x_i}{w_i=n}$
## Find AM
```{r, echo=FALSE}
set.seed(100)
x <- sample(60,10)
x
```
<div onclick="klikaj('rad1')"><span style="color: blue;">Answer (click to see)</span></div>
<div id="rad1" style="visibility: hidden">
```{r, echo = FALSE}
mean(x)
```
</div>
<script>
function klikaj(i) {
document.getElementById(i).style.visibility='visible';
}
</script>
Find AM: 2, 2, 3, 3, 5, 5, 5, 8, 8, 9
There are 2 ways.
$\bar x = \frac{2+2+...+9}{10}$
<div onclick="klikaj('rad2')"><span style="color: blue;">Answer (click to see)</span></div>
<div id="rad2" style="visibility: hidden">
```{r, echo=FALSE}
x <- c(2, 2, 3, 3, 5, 5, 5, 8, 8, 9)
mean(x)
```
</div>
<script>
function klikaj(i) {
document.getElementById(i).style.visibility='visible';
}
</script>
## Mean Using Frequency
For grouped data
| Working hours<br>(x) | Employee<br>(f) | fx |
|:-:|:-:|:-:|
| 2 | 2 | 4 |
| 3 | 2 | 6 |
| 5 | 3 | 15 |
| 8 | 2 | 10 |
| 9 | 1 | 9 |
| | $\sum f =10$ | $\sum fx = 50$ |
$\therefore \bar x = \frac{\sum fx}{\sum f} =\frac{50}{10}=5$
## Freuency vs Weight
<div class="container">
<div class="col">
Suppose, different judges give different scores, but not all evaluation has same weight.
| Judge | Rating<br>(x) | Weight<br>(w) | wx |
|:-:|:-:|:-:|:-:|
| 1 | 8 | 2 | 16 |
| 2 | 7 | 3 | 21 |
| 3 | 4 | 5 | 20 |
| 4 | 5 | 1 | 5 |
| 5 | 7 | 3 | 21 |
| | | $\sum w_i = 14$ | $\sum w_ix_i = 83$ |
</div>
<div class="col">
$\therefore \bar x = \frac{\sum w_ix_i}{\sum w_i}$
<div onclick="klikaj('rad3')"><span style="color: blue;">Answer (click to see)</span></div>
<div id="rad3" style="visibility: hidden">
$\frac{83}{14}$
```{r, echo=FALSE}
round(83/14, 2)
```
</div>
<script>
function klikaj(i) {
document.getElementById(i).style.visibility='visible';
}
</script>
</div>
</div>
## Shortcut Method for AM
<div class="container">
<div class="col">
Calculate the mean in a smart way
```{r, echo=FALSE}
set.seed(100)
x <- sample(1000:1050, 6)
x
```
</div>
<div class="col">
<div onclick="klikaj('rad4')"><span>Show (click to see)</span></div>
<div id="rad4" style="visibility: hidden">
<small>Subtract a number from all, say 1020</small>
```{r, echo=F}
y <- x-1020
print("The new values are")
y
```
```{r, echo=F}
paste0("Mean of y is ", round(mean(y),2))
paste0("Mean of x is ", round(mean(y)+1020,2))
```
</div>
<script>
function klikaj(i) {
document.getElementById(i).style.visibility='visible';
}
</script>
</div>
</div>
## Shortcut Method Formula
<div class="container">
<div class="col">
Consider the values: 1005, 1010, 1015
If 1000 is subtracted: 5, 10, 15
If again divided by 5: 1, 2, 3
Converted Mean = 2
Original Mean = $2 \times 5 + 1000=1010$
</div>
<div class="col">
<div onclick="klikaj('rad5')"><span style="color: blue;">Show (click to see)</span></div>
<div id="rad5" style="visibility: hidden">
x = 1005, 1010, 1015
> - a = 1000
> - c = 5
> - y = 1, 2, 3
> - $\bar x = 2 \times 5 + 1000=1010 = a+\bar y \times c$
> - $\bar x = a+\frac{\sum y}{n} \times c$
</div>
<script>
function klikaj(i) {
document.getElementById(i).style.visibility='visible';
}
</script>
</div>
</div>
## Properties of AM
- $\sum (x_i-\bar x)=0$; can you prove it?
> - $\sum (x_i-\bar x)^2 \le \sum (x_i-a)^2, \space a \ne \bar x$
> - Depends on change of origin and scale?
> - $\bar x + \bar y =\frac{\sum x+\sum y}{n_x+n_y}$
> - Combined mean: $\bar x_c=\frac{n_1 \bar x_1+n_2 \bar x_2+...+n_k \bar x_k}{n_1+n_2+...+n_k}$
> - $AM\ge GM \ge HM$ & $AM \times HM = (GM)^2$
> - AM of first n natural numbers = $\frac{n+1}{2}$
## (Dis)advantages of AM
> - Well-defined
> - Less affected by sample fluctuation
> - Comparison among sets is easy
> - Uses all values
> - <span>Suitable for further analysis.<span>
> - <span style="color:red;">Affected by outliers
## Geometric Mean (GM)
$GM=(x_1 \times x_2 \times ... \times x_n)^{(1/n)}$ or
$GM=(x_1^{f_1} \times x_2^{f_2} \times ... \times x_n^{f_n})^{(1/\sum f_i)}$
Find GM: 2, 4, 6
`r x = c(2, 4, 6)`
<div onclick="klikaj('rad6')"><span style="color: blue;">Answer (click to see)</span></div>
<div id="rad6" style="visibility: hidden">
`r round(exp(mean(log(x))),2)`
</div>
<script>
function klikaj(i) {
document.getElementById(i).style.visibility='visible';
}
</script>
Try this one: 20020, 30080, 50086, 40130
## Concept of Logarithm
<small>
> "An admirable artifice which, by reducing to a few days the labour of many months, doubles the life of the astronomer, and spares him the errors and disgust inseparable from long calculations."
>
> --- Pierre-Simon Laplace
</small>
- Log and Antilog
- $log_24=?$
- if $log_2x=3$, then x=?
## GM Easier Formula
x = 20020, 30080, 50086, 40130
`r x = c(20020, 30080, 50086, 40130)`
> - log x = `r round(log(x),2)`
> - Mean of logx = $\frac{\sum logx}{n}$
> - Original Mean = $antilog(\frac{\sum logx}{n})$
<div onclick="klikaj('rad7')"><span style="color: blue;">Answer (click to see)</span></div>
<div id="rad7" style="visibility: hidden">
33168.96
</div>
<script>
function klikaj(i) {
document.getElementById(i).style.visibility='visible';
}
</script>
## Calculate GM
<div class="container">
<div class="col">
| Marks | # Students |
|:-:|:-:|
| 10-12 | 4 |
| 12-14 | 5 |
| 14-16 | 3 |
| 16-18 | 5 |
| 18-20 | 7 |
| 20-22 | 2 |
</div>
<div class="col">
Make a table using these columns: $x_i, f_i, logx_i, f_ilogx_i$
> - $GM =antilog(\frac{\sum f_i logx_i}{\sum f_i})$
```{r, echo =F}
x <- seq(11,21,2)
f <- c(4,5,3,5,7,2)
```
<div onclick="klikaj('rad8')"><span style="color: blue;">Answer (click to see)</span></div>
<div id="rad8" style="visibility: hidden">
`r exp(sum(log(x)*f)/sum(f))`
</div>
<script>
function klikaj(i) {
document.getElementById(i).style.visibility='visible';
}
</script>
</div>
</div>
## (Dis)advantages of GM
- [x] Not affected by outliers
x = `r (x = c(5,10,15,20,100,1000))`
log(x) = `r round(log10(x),2)`
- [x] Less affected by sample fluctuation
- [x] Suitable for further analysis
- [ ] <span style="color:ff1a1a;">What if one or some x = 0?</span>
- [ ] <span style="color:ff1a1a;">What if one or some x < 0? </span>
## Story of Oil Scam
<div class="container">
<div class="col">
S = 150 km
$v_1=\space 10 km/h, v_2=\space 15 km/h, v_3=\space 20 km/h$
What is the average speed?
> - $AM=\frac{10+15+20}{3}=15 \space km/h$
> - Think more fundamentally
> - $\sum S=3\times 150=450$
> - $t_1=15h, t_2=10h, t_3=7.5h$
> - $\bar v = \frac{\sum S}{\sum t}=\frac{450}{32.5}=13.84 \lt AM$
</div>
<div class="col">
> - $=\frac{450}{15+10+7.5}$
> - $=\frac{450}{\frac{150}{10}+\frac{150}{15}+\frac{150}{20}}$
> - $=\frac{450}{150(\frac{1}{10}+\frac{1}{15}+\frac{1}{20})}$
> - $=\frac{3}{\frac{1}{10}+\frac{1}{15}+\frac{1}{20}}$
> - $=\frac{3}{\frac{1}{v_1}+\frac{1}{v_2}+\frac{1}{v_3}}$
</div>
</div>
## Harmonic Mean
<div class="container">
<div class="col">
Formula: Reciprocal of Mean of $\frac{1}{x_i}$
Reciprocal of $\frac{\frac{1}{x_1}+\frac{1}{x_2}+...+\frac{1}{x_n}}{n}$
Thus, $HM = \frac{n}{\sum \frac{1}{x_i}}$
Calculate: 2, 4, 8
<div onclick="klikaj('rad9')"><span style="color: blue;">Answer (click to see)</span></div>
<div id="rad9" style="visibility: hidden">
`r x = c(2,4,8)`
`r round(1/mean(1/x),2)`
</div>
<script>
function klikaj(i) {
document.getElementById(i).style.visibility='visible';
}
</script>
</div>
<div class="col">
For grouped data
> - $HM=\frac{\sum f}{\sum \frac{f}{x}}$
> - For wighted data: $\frac{\sum w}{\sum \frac{w}{x}}$
</div>
</div>
## Why and When HM
- When there are rates associated, say speed, and numerator is fixed.
- $Speed, v = \frac{S}{t}$; HM if S is fixed
- Example: A man travels 120 km the first day at 12 kph, the same distance at 10 kph on the 2nd day, and at 8 kph on the 3rd day. Find his average speed.
## Wighted AM vs Weighted HM
Suppose, a bus travels 10 km at 10 kph, another 15 km at 20 kph, and another 20 km at 25 kph. What is the average speed.
HM $\rightarrow$ consider distances as weights
AM $\rightarrow$ consider times as weights
Time, $t=\frac d v=$ `r d = c(10,15,20); v = c(10,20,25); d/v`
> - $WHM = \frac{10+15+20}{\frac{10}{10}+\frac{15}{20}+\frac{20}{25}}$=`r round((45)/(1+15/20+20/25),2)`
> - $WAM = \frac{1\times 10 + 0.75 \times 20 + 0.80 \times 25}{1+0.75+0.80}$ = `r round((10+0.75*20+0.80*25)/2.55,2)`
> - True mean, $\bar v=\frac{\sum d}{\sum t}=\frac{45}{2.55}=$ `r round(45/2.55,2)`
## HM Example 2
- A passerby travels 10 km at 20 kph, 5 km at 15 kph, and 4 km at 12 kph. What is the average speed? (Use weighted HM)
- Here, distances are different. Consider them weights.
> - $HM=\frac{w_1+w_2+w_3}{\frac{w_1}{x_1}+\frac{w_2}{x_2}+\frac{w_3}{x_3}}$
```{r, echo=F}
x <- c(20,15,12)
w <- c(10,5,4)
```
> - HM = `r round(sum(w)/sum(w/x),3)`
## Quadratic Mean
$QM=\sqrt{\frac{x_1^2+x_2^2+...+x_n^2}{n}}=\sqrt{\frac{\sum x_i^2}{n}}$
> - Also known as Root mean square
> - More at: https://en.wikipedia.org/wiki/Root_mean_square#Uses
> - For grouped data?
## Partition Values
## Find medians
x = 4,5,6,8,9,11,16
y = 4,5,6,8,9,11,16,19
`r x = c(4,5,6,8,9,11,16)`
`r y = c(4,5,6,8,9,11,16,19)`
> - `r paste0("Median of x is ", median(x))`
> - `r paste0("Median of y is ", median(y))`
> - Formula for odd n = $\frac{n+1}{2}th \space value$
> - Formula for even n = $\frac{\frac{n}{2}th+(\frac{n}{2}+1)th}{2}$
## Dis(advantages) of Median
- Unaffected by outliers (extreme values)
- Graphically estimable
- Affected by sample fluctuation
- Not based on all values
- Not suitable for further mathematical analysis
## Quartiles, Deciles, and Percentiles
$Q_1= \frac{(n+1)}{4}th \space$
$Q_2, Q_3=?$
Find $Q_1, Q_2, Q_3$
X = `r set.seed(100); (x = sort(sample(20,11)))`
> - `r summary(x)`
> - What are the formulae for Deciles ($D_i$ and $P_i$)
## General Formula for Partition Values
<div class="container">
<div class="col">
For odd n,
$A_i= \frac{i \times (n+1)}{k}th \space value$
</div>
<div class="col">
For even n,
$A_i=\frac{\frac{i \times n}{k}th+(\frac{i\times n}{k}+1)th}{k}$
</div>
</div>
where, k = no. of partitions
For median, for example, k = 2.
> - What if we divide the data set into 20 segments?