-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathintro.html
960 lines (944 loc) · 59 KB
/
intro.html
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
<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Introduction to inferr • inferr</title>
<!-- jquery --><script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha384-nrOSfDHtoPMzJHjVTdCopGqIqeYETSXhZDFyniQ8ZHcVy08QesyHcnOUpMpqnmWq" crossorigin="anonymous"></script><!-- Bootstrap --><link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script><!-- Font Awesome icons --><link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-T8Gy5hrqNKT+hzMclPo118YTQO6cYprQmhrYwIiQ/3axmI1hQomh7Ud2hPOy8SP1" crossorigin="anonymous">
<!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
<script src="../jquery.sticky-kit.min.js"></script><script src="../pkgdown.js"></script><!-- mathjax --><script src="https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container template-vignette">
<header><div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="../index.html">inferr</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="../index.html">Home</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Guides
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="../articles/intro.html">Intro</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Reference
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="../reference/index.html">Functions</a>
</li>
<li>
<a href="../news/index.html">News</a>
</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/rsquaredacademy/inferr">
<span class="fa fa-github"></span>
</a>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container -->
</div>
<!--/.navbar -->
</header><div class="row">
<div class="col-md-9">
<div class="page-header toc-ignore">
<h1>Introduction to inferr</h1>
<h4 class="date">2018-02-13</h4>
</div>
<div class="contents">
<p>Inferential statistics allows us to make generalizations about populations using data drawn from the population. We use them when it is impractical or impossible to collect data about the whole population under study and instead, we have a sample that represents the population under study and using inferential statistics technique, we make generalizations about the population from the sample. <strong>inferr</strong> builds upon the solid set of statistical tests provided in <strong>stats</strong> package by including additional data types as inputs, expanding and restructuring the test results.</p>
<p>The <strong>inferr</strong> package:</p>
<ul>
<li>builds upon the statistical tests provided in <strong>stats</strong><br>
</li>
<li>provides additional and flexible options</li>
<li>more detailed and structured test results</li>
</ul>
<p>As of version 0.1, <strong>inferr</strong> includes a select set of parametric and non-parametric statistical tests which are listed below:</p>
<ul>
<li>One Sample t Test</li>
<li>Paired Sample t Test</li>
<li>Independent Sample t Test</li>
<li>One Sample Proportion Test</li>
<li>Two Sample Proportion Test</li>
<li>One Sample Variance Test</li>
<li>Two Sample Variance Test</li>
<li>Binomial Test</li>
<li>ANOVA</li>
<li>Chi Square Goodness of Fit Test</li>
<li>Chi Square Independence Test</li>
<li>Levene’s Test</li>
<li>Cochran’s Q Test</li>
<li>McNemar Test</li>
<li>Runs Test for Randomness</li>
</ul>
<p>These tests are described in more detail in the following sections.</p>
<div id="one-sample-t-test" class="section level2">
<h2 class="hasAnchor">
<a href="#one-sample-t-test" class="anchor"></a>One Sample t Test</h2>
<p>A one sample t-test is used to determine whether a sample of observations comes from a population with a specific mean. The observations must be continuous, independent of each other, approximately distributed and should not contain any outliers.</p>
<div id="example" class="section level3">
<h3 class="hasAnchor">
<a href="#example" class="anchor"></a>Example</h3>
<p>Using the hsb data, test whether the average of write differs significantly from 50.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" data-line-number="1"><span class="kw"><a href="../reference/infer_os_t_test.html">infer_os_t_test</a></span>(hsb, write, <span class="dt">mu =</span> <span class="dv">50</span>, <span class="dt">alternative =</span> <span class="st">'all'</span>)</a></code></pre></div>
<pre><code>## One-Sample Statistics
## ---------------------------------------------------------------------------------
## Variable Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
## ---------------------------------------------------------------------------------
## write 200 52.775 0.6702 9.4786 51.4537 54.0969
## ---------------------------------------------------------------------------------
##
## Ho: mean(write) ~=50
##
## Ha: mean < 50 Ha: mean ~= 50 Ha: mean > 50
## t = 4.141 t = 4.141 t = 4.141
## P < t = 1.0000 P > |t| = 0.0001 P > t = 0.0000</code></pre>
</div>
</div>
<div id="paired-t-test" class="section level2">
<h2 class="hasAnchor">
<a href="#paired-t-test" class="anchor"></a>Paired t test</h2>
<p>A paired (samples) t-test is used when you want to compare the means between two related groups of observations on some continuous dependent variable. In a paired sample test, each subject or entity is measured twice. It can be used to evaluate the effectiveness of training programs or treatments. If the dependent variable is dichotomous, use the McNemar test.</p>
<div id="examples" class="section level3">
<h3 class="hasAnchor">
<a href="#examples" class="anchor"></a>Examples</h3>
<p>Using the hsb data, test whether the mean of read is equal to the mean of write.</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" data-line-number="1"><span class="co"># Lower Tail Test</span></a>
<a class="sourceLine" id="cb3-2" data-line-number="2"><span class="kw"><a href="../reference/infer_ts_paired_ttest.html">infer_ts_paired_ttest</a></span>(hsb, read, write, <span class="dt">alternative =</span> <span class="st">'less'</span>)</a></code></pre></div>
<pre><code>## Paired Samples Statistics
## ----------------------------------------------------------------------------
## Variables Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
## ----------------------------------------------------------------------------
## read 200 52.23 0.7249921 10.25294 50.8 53.66
## write 200 52.775 0.6702372 9.478586 51.45 54.1
## ----------------------------------------------------------------------------
## diff 200 -0.545 0.6283822 8.886666 -1.78 0.69
## ----------------------------------------------------------------------------
##
## Paired Samples Correlations
## -------------------------------------------
## Variables Obs Correlation Sig.
## read & write 200 0.60 0
## -------------------------------------------
##
## Paired Samples Test
## -------------------
## Ho: mean(read - write) = 0
## Ha: mean(read - write) < 0
##
## ----------------------------------------
## Variables t df Sig.
## ----------------------------------------
## read - write -0.8673 199 0.193
## ----------------------------------------</code></pre>
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb5-1" data-line-number="1"><span class="co"># Test all alternatives</span></a>
<a class="sourceLine" id="cb5-2" data-line-number="2"><span class="kw"><a href="../reference/infer_ts_paired_ttest.html">infer_ts_paired_ttest</a></span>(hsb, read, write, <span class="dt">alternative =</span> <span class="st">'all'</span>)</a></code></pre></div>
<pre><code>## Paired Samples Statistics
## ----------------------------------------------------------------------------
## Variables Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
## ----------------------------------------------------------------------------
## read 200 52.23 0.7249921 10.25294 50.8 53.66
## write 200 52.775 0.6702372 9.478586 51.45 54.1
## ----------------------------------------------------------------------------
## diff 200 -0.545 0.6283822 8.886666 -1.78 0.69
## ----------------------------------------------------------------------------
##
## Paired Samples Correlations
## -------------------------------------------
## Variables Obs Correlation Sig.
## read & write 200 0.60 0
## -------------------------------------------
##
## Ho: mean(read - write) = mean(diff) = 0
##
## Ha: mean(diff) < 0 Ha: mean(diff) ~= 0 Ha: mean(diff) > 0
## t = -0.8673 t = -0.8673 t = -0.8673
## P < t = 0.193 P > |t| = 0.387 P > t = 0.807</code></pre>
</div>
</div>
<div id="two-independent-sample-t-test" class="section level2">
<h2 class="hasAnchor">
<a href="#two-independent-sample-t-test" class="anchor"></a>Two Independent Sample t Test</h2>
<p>An independent samples t-test is used to compare the means of a normally distributed continuous dependent variable for two unrelated groups. The dependent variable must be approximately normally distributed and the cases/subjects in the two groups must be different i.e. a subject in one group cannot also be a subject of the other group. It can be used to answer whether:</p>
<ul>
<li>average number of products produced by two machines differ significantly?</li>
<li>average salaries of graduate students differ based on gender?</li>
</ul>
<div id="example-1" class="section level3">
<h3 class="hasAnchor">
<a href="#example-1" class="anchor"></a>Example</h3>
<p>Using the hsb data, test whether the mean for write is the same for males and females.</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb7-1" data-line-number="1"><span class="kw"><a href="../reference/infer_ts_ind_ttest.html">infer_ts_ind_ttest</a></span>(hsb, female, write, <span class="dt">alternative =</span> <span class="st">'all'</span>)</a></code></pre></div>
<pre><code>## Group Statistics
## -----------------------------------------------------------------------------
## Group Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
## -----------------------------------------------------------------------------
## 0 91 50.121 1.080 10.305 47.97539 52.26661
## 1 109 54.991 0.779 8.134 53.44689 56.53511
## -----------------------------------------------------------------------------
## combined 200 52.775 0.67 9.479 51.45379 54.09621
## -----------------------------------------------------------------------------
## diff 200 -4.87 1.304 9.231 -7.42623 -2.31377
## -----------------------------------------------------------------------------
##
## Independent Samples Test
## ------------------------
##
## Ho: mean(0) - mean(1) = diff = 0
##
## Ha: diff < 0 Ha: diff ~= 0 Ha: diff > 0
##
## Pooled
## ------------------------------------------------------------------------
## t = -3.7341 t = -3.7341 t = -3.7341
## P < t = 0.0001 P > |t| = 0.0002 P > t = 0.9999
##
## Satterthwaite
## ------------------------------------------------------------------------
## t = -3.6564 t = -3.6564 t = -3.6564
## P < t = 0.0002 P > |t| = 0.0003 P > t = 0.9998
##
##
## Test for Equality of Variances
## ---------------------------------------------------------------
## Variable Method Num DF Den DF F Value P > F
## ---------------------------------------------------------------
## write Folded F 90 108 1.605 0.0188
## ---------------------------------------------------------------</code></pre>
</div>
</div>
<div id="one-sample-test-of-proportion" class="section level2">
<h2 class="hasAnchor">
<a href="#one-sample-test-of-proportion" class="anchor"></a>One Sample Test of Proportion</h2>
<p>One sample test of proportion compares proportion in one group to a specified population proportion.</p>
<div id="examples-1" class="section level3">
<h3 class="hasAnchor">
<a href="#examples-1" class="anchor"></a>Examples</h3>
<p>Using hsb data, test whether the proportion of females is 50%.</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb9-1" data-line-number="1"><span class="co"># Using Variables</span></a>
<a class="sourceLine" id="cb9-2" data-line-number="2"><span class="kw"><a href="../reference/infer_os_prop_test.html">infer_os_prop_test</a></span>(hsb, female, <span class="dt">prob =</span> <span class="fl">0.5</span>)</a></code></pre></div>
<pre><code>## Test Statistics
## -------------------------
## Sample Size 200
## Exp Prop 0.5
## Obs Prop 0.545
## z 1.2728
## Pr(|Z| > |z|) 0.2031
##
## -----------------------------------------------------------------
## Category Observed Expected % Deviation Std. Residuals
## -----------------------------------------------------------------
## 0 91 100 -9.00 -0.90
## 1 109 100 9.00 0.90
## -----------------------------------------------------------------</code></pre>
<p>Using Calculator</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb11-1" data-line-number="1"><span class="co"># Calculator</span></a>
<a class="sourceLine" id="cb11-2" data-line-number="2"><span class="kw"><a href="../reference/infer_os_prop_test.html">infer_os_prop_test</a></span>(<span class="dv">200</span>, <span class="dt">prob =</span> <span class="fl">0.5</span>, <span class="dt">phat =</span> <span class="fl">0.3</span>)</a></code></pre></div>
<pre><code>## Test Statistics
## --------------------------
## Sample Size 200
## Exp Prop 0.5
## Obs Prop 0.3
## z -5.6569
## Pr(|Z| > |z|) 0
##
## -----------------------------------------------------------------
## Category Observed Expected % Deviation Std. Residuals
## -----------------------------------------------------------------
## 0 140 100 40.00 4.00
## 1 60 100 -40.00 -4.00
## -----------------------------------------------------------------</code></pre>
</div>
</div>
<div id="two-sample-test-of-proportion" class="section level2">
<h2 class="hasAnchor">
<a href="#two-sample-test-of-proportion" class="anchor"></a>Two Sample Test of Proportion</h2>
<p>Two sample test of proportion performs tests on the equality of proportions using large-sample statistics. It tests that a categorical variable has the same proportion within two groups or that two variables have the same proportion.</p>
<div id="examples-2" class="section level3">
<h3 class="hasAnchor">
<a href="#examples-2" class="anchor"></a>Examples</h3>
<div id="using-variables" class="section level4">
<h4 class="hasAnchor">
<a href="#using-variables" class="anchor"></a>Using Variables</h4>
<p>Using the treatment data, test equality of proportion of two treatments</p>
<div class="sourceCode" id="cb13"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb13-1" data-line-number="1"><span class="co"># Using Variables</span></a>
<a class="sourceLine" id="cb13-2" data-line-number="2"><span class="kw"><a href="../reference/infer_ts_prop_test.html">infer_ts_prop_test</a></span>(treatment, treatment1, treatment2, <span class="dt">alternative =</span> <span class="st">'all'</span>)</a></code></pre></div>
<pre><code>## Test Statistics
## -----------------------------
## Total Observations 100
## z 0.403
## Pr(|Z| < |z|) 0.687
## Pr(Z < z) 0.656
## Pr(Z > z) 0.344</code></pre>
</div>
<div id="use-grouping-variable" class="section level4">
<h4 class="hasAnchor">
<a href="#use-grouping-variable" class="anchor"></a>Use Grouping Variable</h4>
<p>Using the treatment2 data, test whether outcome has same proportion for male and female</p>
<div class="sourceCode" id="cb15"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb15-1" data-line-number="1"><span class="co"># Using Grouping Variable</span></a>
<a class="sourceLine" id="cb15-2" data-line-number="2"><span class="kw"><a href="../reference/infer_ts_prop_test.html">infer_ts_prop_grp</a></span>(treatment2, outcome, female, <span class="dt">alternative =</span> <span class="st">'all'</span>)</a></code></pre></div>
<pre><code>## Test Statistics
## -----------------------------
## Total Observations 200
## z 0.351
## Pr(|Z| < |z|) 0.726
## Pr(Z < z) 0.637
## Pr(Z > z) 0.363</code></pre>
</div>
<div id="using-calculator" class="section level4">
<h4 class="hasAnchor">
<a href="#using-calculator" class="anchor"></a>Using Calculator</h4>
<p>Test whether the same proportion of people from two batches will pass a review exam for a training program. In the first batch of 30 participants, 30% passed the review, whereas in the second batch of 25 participants, 50% passed the review.</p>
<div class="sourceCode" id="cb17"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb17-1" data-line-number="1"><span class="co"># Calculator</span></a>
<a class="sourceLine" id="cb17-2" data-line-number="2"><span class="kw"><a href="../reference/infer_ts_prop_test.html">infer_ts_prop_calc</a></span>(<span class="dt">n1 =</span> <span class="dv">30</span>, <span class="dt">n2 =</span> <span class="dv">25</span>, <span class="dt">p1 =</span> <span class="fl">0.3</span>, <span class="dt">p2 =</span> <span class="fl">0.5</span>, <span class="dt">alternative =</span> <span class="st">'all'</span>)</a></code></pre></div>
<pre><code>## Test Statistics
## ------------------------------
## Total Observations 55
## z -1.514
## Pr(|Z| < |z|) 0.13
## Pr(Z < z) 0.065
## Pr(Z > z) 0.935</code></pre>
</div>
</div>
</div>
<div id="one-sample-variance-test" class="section level2">
<h2 class="hasAnchor">
<a href="#one-sample-variance-test" class="anchor"></a>One Sample Variance Test</h2>
<p>One sample variance comparison test compares the standard deviation (variances) to a hypothesized value. It determines whether the standard deviation of a population is equal to a hypothesized value. It can be used to answer the following questions:</p>
<ul>
<li>Is the variance equal to some pre-determined threshold value?</li>
<li>Is the variance greater than some pre-determined threshold value?</li>
<li>Is the variance less than some pre-determined threshold value?</li>
</ul>
<div id="examples-3" class="section level3">
<h3 class="hasAnchor">
<a href="#examples-3" class="anchor"></a>Examples</h3>
<p>Using the mtcars data, compare the standard deviation of mpg to a hypothesized value.</p>
<div class="sourceCode" id="cb19"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb19-1" data-line-number="1"><span class="co"># Lower Tail Test</span></a>
<a class="sourceLine" id="cb19-2" data-line-number="2"><span class="kw"><a href="../reference/infer_os_var_test.html">infer_os_var_test</a></span>(mtcars, mpg, <span class="fl">0.3</span>, <span class="dt">alternative =</span> <span class="st">'less'</span>)</a></code></pre></div>
<pre><code>## One-Sample Statistics
## -----------------------------------------------------------------------------
## Variable Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
## -----------------------------------------------------------------------------
## mpg 32 20.0906 1.0654 6.0269 3.8737 10.6527
## -----------------------------------------------------------------------------
##
## Lower Tail Test
## ---------------
## Ho: sd(mpg) >= 0.3
## Ha: sd(mpg) < 0.3
##
## Chi-Square Test for Variance
## ----------------------------------------
## Variable c DF Sig
## ----------------------------------------
## mpg 12511.635 31 1.0000
## ----------------------------------------</code></pre>
<div class="sourceCode" id="cb21"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb21-1" data-line-number="1"><span class="co"># Test all alternatives</span></a>
<a class="sourceLine" id="cb21-2" data-line-number="2"><span class="kw"><a href="../reference/infer_os_var_test.html">infer_os_var_test</a></span>(mtcars, mpg, <span class="fl">0.3</span>, <span class="dt">alternative =</span> <span class="st">'all'</span>)</a></code></pre></div>
<pre><code>## One-Sample Statistics
## -----------------------------------------------------------------------------
## Variable Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
## -----------------------------------------------------------------------------
## mpg 32 20.0906 1.0654 6.0269 3.8737 10.6527
## -----------------------------------------------------------------------------
##
## Ho: sd(mpg) = 0.3
##
## Ha: sd < 0.3 Ha: sd != 0.3 Ha: sd > 0.3
## c = 12511.6354 c = 12511.6354 c = 12511.6354
## Pr(C < c) = 1.0000 2 * Pr(C > c) = 0.0000 Pr(C > c) = 0.0000</code></pre>
</div>
</div>
<div id="two-sample-variance-test" class="section level2">
<h2 class="hasAnchor">
<a href="#two-sample-variance-test" class="anchor"></a>Two Sample Variance Test</h2>
<p>Two sample variance comparison tests equality of standard deviations (variances). It tests that the standard deviation of a continuous variable is same within two groups or the standard deviation of two continuous variables is equal.</p>
<div id="example-2" class="section level3">
<h3 class="hasAnchor">
<a href="#example-2" class="anchor"></a>Example</h3>
<div id="use-grouping-variable-1" class="section level4">
<h4 class="hasAnchor">
<a href="#use-grouping-variable-1" class="anchor"></a>Use Grouping Variable</h4>
<p>Using the mtcars data, compare the standard deviation in miles per gallon for automatic and manual vehicles.</p>
<div class="sourceCode" id="cb23"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb23-1" data-line-number="1"><span class="co"># Using Grouping Variable</span></a>
<a class="sourceLine" id="cb23-2" data-line-number="2"><span class="kw"><a href="../reference/infer_ts_var_test.html">infer_ts_var_test</a></span>(hsb, read, <span class="dt">group_var =</span> female, <span class="dt">alternative =</span> <span class="st">'all'</span>)</a></code></pre></div>
<pre><code>## Variance Ratio Test
## --------------------------------------------------
## Group Obs Mean Std. Err. Std. Dev.
## --------------------------------------------------
## 0 91 52.82 1.1 10.51
## 1 109 51.73 0.96 10.06
## --------------------------------------------------
## combined 200 52.23 0.72 10.25
## --------------------------------------------------
##
## Variance Ratio Test
## --------------------------------------------------
## F Num DF Den DF
## --------------------------------------------------
## 1.0913 90 108
## --------------------------------------------------
##
## Null & Alternate Hypothesis
## ----------------------------------------
## ratio = sd(0) / (1)
## Ho: ratio = 1
##
## Ha: ratio < 1 Ha: ratio > 1
## Pr(F < f) = 0.6694 Pr(F > f) = 0.3306
## ----------------------------------------</code></pre>
</div>
<div id="using-variables-1" class="section level4">
<h4 class="hasAnchor">
<a href="#using-variables-1" class="anchor"></a>Using Variables</h4>
<p>Using the hsb data, compare the standard deviation of reading and writing scores.</p>
<div class="sourceCode" id="cb25"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb25-1" data-line-number="1"><span class="co"># Using Variables</span></a>
<a class="sourceLine" id="cb25-2" data-line-number="2"><span class="kw"><a href="../reference/infer_ts_var_test.html">infer_ts_var_test</a></span>(hsb, read, write, <span class="dt">alternative =</span> <span class="st">'all'</span>)</a></code></pre></div>
<pre><code>## Variance Ratio Test
## --------------------------------------------------
## Group Obs Mean Std. Err. Std. Dev.
## --------------------------------------------------
## read 200 52.23 0.72 10.25
## write 200 52.77 0.67 9.48
## --------------------------------------------------
## combined 400 52.5 0.49 9.86
## --------------------------------------------------
##
## Variance Ratio Test
## --------------------------------------------------
## F Num DF Den DF
## --------------------------------------------------
## 1.1701 199 199
## --------------------------------------------------
##
## Null & Alternate Hypothesis
## ----------------------------------------
## ratio = sd(read) / (write)
## Ho: ratio = 1
##
## Ha: ratio < 1 Ha: ratio > 1
## Pr(F < f) = 0.8656 Pr(F > f) = 0.1344
## ----------------------------------------</code></pre>
</div>
</div>
</div>
<div id="binomial-probability-test" class="section level2">
<h2 class="hasAnchor">
<a href="#binomial-probability-test" class="anchor"></a>Binomial Probability Test</h2>
<p>A one sample binomial test allows us to test whether the proportion of successes on a two-level categorical dependent variable significantly differs from a hypothesized value.</p>
<div id="examples-4" class="section level3">
<h3 class="hasAnchor">
<a href="#examples-4" class="anchor"></a>Examples</h3>
<p>Using the hsb data, test whether the proportion of females and males are equal.</p>
<div class="sourceCode" id="cb27"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb27-1" data-line-number="1"><span class="co"># Using variables</span></a>
<a class="sourceLine" id="cb27-2" data-line-number="2"><span class="kw"><a href="../reference/infer_binom_calc.html">infer_binom_test</a></span>(hsb, female, <span class="dt">prob =</span> <span class="fl">0.5</span>)</a></code></pre></div>
<pre><code>## Binomial Test
## ---------------------------------------
## Group N Obs. Prop Exp. Prop
## ---------------------------------------
## 0 91 0.455 0.500
## 1 109 0.545 0.500
## ---------------------------------------
##
##
## Test Summary
## ----------------------------------------------
## Tail Prob p-value
## ----------------------------------------------
## Lower Pr(k <= 109) 0.910518
## Upper Pr(k >= 109) 0.114623
## ----------------------------------------------</code></pre>
<div id="using-calculator-1" class="section level4">
<h4 class="hasAnchor">
<a href="#using-calculator-1" class="anchor"></a>Using Calculator</h4>
<div class="sourceCode" id="cb29"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb29-1" data-line-number="1"><span class="co"># calculator</span></a>
<a class="sourceLine" id="cb29-2" data-line-number="2"><span class="kw"><a href="../reference/infer_binom_calc.html">infer_binom_calc</a></span>(<span class="dv">32</span>, <span class="dv">16</span>, <span class="dt">prob =</span> <span class="fl">0.5</span>)</a></code></pre></div>
<pre><code>## Binomial Test
## --------------------------------------
## Group N Obs. Prop Exp. Prop
## --------------------------------------
## 0 16 0.5 0.500
## 1 16 0.5 0.500
## --------------------------------------
##
##
## Test Summary
## --------------------------------------------
## Tail Prob p-value
## --------------------------------------------
## Lower Pr(k <= 16) 0.569975
## Upper Pr(k >= 16) 0.569975
## --------------------------------------------</code></pre>
</div>
</div>
</div>
<div id="anova" class="section level2">
<h2 class="hasAnchor">
<a href="#anova" class="anchor"></a>ANOVA</h2>
<p>The one-way analysis of variance (ANOVA) is used to determine whether there are any statistically significant differences between the means of two or more independent (unrelated) groups. It tests the null hypothesis that samples in two or more groups are drawn from populations with the same mean values. It cannot tell you which specific groups were statistically significantly different from each other but only that at least two groups were different and can be used only for numerical data.</p>
<div id="examples-5" class="section level3">
<h3 class="hasAnchor">
<a href="#examples-5" class="anchor"></a>Examples</h3>
<p>Using the hsb data, test whether the mean of write differs between the three program types.</p>
<div class="sourceCode" id="cb31"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb31-1" data-line-number="1"><span class="kw"><a href="../reference/infer_oneway_anova.html">infer_oneway_anova</a></span>(hsb, write, prog)</a></code></pre></div>
<pre><code>## ANOVA
## ----------------------------------------------------------------------
## Sum of
## Squares DF Mean Square F Sig.
## ----------------------------------------------------------------------
## Between Groups 3175.698 2 1587.849 21.275 0.0000
## Within Groups 14703.177 197 74.635
## Total 17878.875 199
## ----------------------------------------------------------------------
##
## Report
## -----------------------------------------
## Category N Mean Std. Dev.
## -----------------------------------------
## 1 45 51.333 9.398
## 2 105 56.257 7.943
## 3 50 46.760 9.319
## -----------------------------------------
##
## Number of obs = 200 R-squared = 0.1776
## Root MSE = 8.6392 Adj R-squared = 0.1693</code></pre>
</div>
</div>
<div id="chi-square-goodness-of-fit-test" class="section level2">
<h2 class="hasAnchor">
<a href="#chi-square-goodness-of-fit-test" class="anchor"></a>Chi Square Goodness of Fit Test</h2>
<p>A chi-square goodness of fit test allows us to compare the observed sample distribution with expected probability distribution. It tests whether the observed proportions for a categorical variable differ from hypothesized proportions. The proportion of cases expected in each group of categorical variable may be equal or unequal. It can be applied to any univariate distribution for which you can calculate the cumulative distribution function. It is applied to binned data and the value of the chi square test depends on how the data is binned. For the chi square approximation to be valid, the sample size must be sufficiently large.</p>
<div id="example-3" class="section level3">
<h3 class="hasAnchor">
<a href="#example-3" class="anchor"></a>Example</h3>
<p>Using the hsb data, test whether the observed proportions for race differs significantly from the hypothesized proportions.</p>
<div class="sourceCode" id="cb33"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb33-1" data-line-number="1"><span class="co"># basic example</span></a>
<a class="sourceLine" id="cb33-2" data-line-number="2"><span class="kw"><a href="../reference/infer_chisq_gof_test.html">infer_chisq_gof_test</a></span>(hsb, race, <span class="kw">c</span>(<span class="dv">20</span>, <span class="dv">20</span>, <span class="dv">20</span> , <span class="dv">140</span>))</a></code></pre></div>
<pre><code>## Test Statistics
## -----------------------
## Chi-Square 5.0286
## DF 3
## Pr > Chi Sq 0.1697
## Sample Size 200
##
## Variable: race
## -----------------------------------------------------------------
## Category Observed Expected % Deviation Std. Residuals
## -----------------------------------------------------------------
## 1 24 20 20.00 0.89
## 2 11 20 -45.00 -2.01
## 3 20 20 0.00 0.00
## 4 145 140 3.57 0.42
## -----------------------------------------------------------------</code></pre>
<div id="continuity-correction" class="section level4">
<h4 class="hasAnchor">
<a href="#continuity-correction" class="anchor"></a>Continuity Correction</h4>
<div class="sourceCode" id="cb35"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb35-1" data-line-number="1"><span class="co"># using continuity correction</span></a>
<a class="sourceLine" id="cb35-2" data-line-number="2"><span class="kw"><a href="../reference/infer_chisq_gof_test.html">infer_chisq_gof_test</a></span>(hsb, race, <span class="kw">c</span>(<span class="dv">20</span>, <span class="dv">20</span>, <span class="dv">20</span> , <span class="dv">140</span>), <span class="dt">correct =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<pre><code>## Test Statistics
## -----------------------
## Chi-Square 4.3821
## DF 3
## Pr > Chi Sq 0.2231
## Sample Size 200
##
## Variable: race
## -----------------------------------------------------------------
## Category Observed Expected % Deviation Std. Residuals
## -----------------------------------------------------------------
## 1 24 20 17.50 0.78
## 2 11 20 -47.50 -2.12
## 3 20 20 -2.50 -0.11
## 4 145 140 3.21 0.38
## -----------------------------------------------------------------</code></pre>
</div>
</div>
</div>
<div id="chi-square-test-of-independence" class="section level2">
<h2 class="hasAnchor">
<a href="#chi-square-test-of-independence" class="anchor"></a>Chi Square Test of Independence</h2>
<p>A chi-square test is used when you want to test if there is a significant relationship between two nominal (categorical) variables.</p>
<div id="examples-6" class="section level3">
<h3 class="hasAnchor">
<a href="#examples-6" class="anchor"></a>Examples</h3>
<p>Using the hsb data, test if there is a relationship between the type of school attended (schtyp) and students’ gender (female).</p>
<div class="sourceCode" id="cb37"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb37-1" data-line-number="1"><span class="kw"><a href="../reference/infer_chisq_assoc_test.html">infer_chisq_assoc_test</a></span>(hsb, female, schtyp)</a></code></pre></div>
<pre><code>## Chi Square Statistics
##
## Statistics DF Value Prob
## ----------------------------------------------------
## Chi-Square 1 0.0470 0.8284
## Likelihood Ratio Chi-Square 1 0.0471 0.8282
## Continuity Adj. Chi-Square 1 0.0005 0.9822
## Mantel-Haenszel Chi-Square 1 0.0468 0.8287
## Phi Coefficient 0.0153
## Contingency Coefficient 0.0153
## Cramer's V 0.0153
## ----------------------------------------------------</code></pre>
<p>Using the hsb data, test if there is a relationship between the type of school attended (schtyp) and students’ socio economic status (ses).</p>
<div class="sourceCode" id="cb39"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb39-1" data-line-number="1"><span class="kw"><a href="../reference/infer_chisq_assoc_test.html">infer_chisq_assoc_test</a></span>(hsb, schtyp, ses)</a></code></pre></div>
<pre><code>## Chi Square Statistics
##
## Statistics DF Value Prob
## ----------------------------------------------------
## Chi-Square 2 6.3342 0.0421
## Likelihood Ratio Chi-Square 2 7.9060 0.0192
## Phi Coefficient 0.1780
## Contingency Coefficient 0.1752
## Cramer's V 0.1780
## ----------------------------------------------------</code></pre>
</div>
</div>
<div id="levenes-test" class="section level2">
<h2 class="hasAnchor">
<a href="#levenes-test" class="anchor"></a>Levene’s Test</h2>
<p>Levene’s test is used to determine if k samples have equal variances. It is less sensitive to departures from normality and is an alternative to Bartlett’s test. This test returns Levene’s robust test statistic and the two statistics proposed by Brown and Forsythe that replace the mean in Levene’s formula with alternative location estimators. The first alternative replaces the mean with the median and the second alternative replaces the mean with the 10% trimmed mean.</p>
<div id="examples-7" class="section level3">
<h3 class="hasAnchor">
<a href="#examples-7" class="anchor"></a>Examples</h3>
<div id="use-grouping-variable-2" class="section level4">
<h4 class="hasAnchor">
<a href="#use-grouping-variable-2" class="anchor"></a>Use Grouping Variable</h4>
<p>Using the hsb data, test whether variance in reading score is same across race.</p>
<div class="sourceCode" id="cb41"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb41-1" data-line-number="1"><span class="co"># Using Grouping Variable</span></a>
<a class="sourceLine" id="cb41-2" data-line-number="2"><span class="kw"><a href="../reference/infer_levene_test.html">infer_levene_test</a></span>(hsb, read, <span class="dt">group_var =</span> race)</a></code></pre></div>
<pre><code>## Summary Statistics
## Levels Frequency Mean Std. Dev
## -----------------------------------------
## 1 24 46.67 10.24
## 2 11 51.91 7.66
## 3 20 46.8 7.12
## 4 145 53.92 10.28
## -----------------------------------------
## Total 200 52.23 10.25
## -----------------------------------------
##
## Test Statistics
## -------------------------------------------------------------------------
## Statistic Num DF Den DF F Pr > F
## -------------------------------------------------------------------------
## Brown and Forsythe 3 196 3.44 0.0179
## Levene 3 196 3.4792 0.017
## Brown and Forsythe (Trimmed Mean) 3 196 3.3936 0.019
## -------------------------------------------------------------------------</code></pre>
</div>
<div id="using-variables-2" class="section level4">
<h4 class="hasAnchor">
<a href="#using-variables-2" class="anchor"></a>Using Variables</h4>
<p>Using the hsb data, test whether variance is equal for reading, writing and social studies scores.</p>
<div class="sourceCode" id="cb43"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb43-1" data-line-number="1"><span class="co"># Using Variables</span></a>
<a class="sourceLine" id="cb43-2" data-line-number="2"><span class="kw"><a href="../reference/infer_levene_test.html">infer_levene_test</a></span>(hsb, read, write, socst)</a></code></pre></div>
<pre><code>## Summary Statistics
## Levels Frequency Mean Std. Dev
## -----------------------------------------
## 0 200 52.23 10.25
## 1 200 52.77 9.48
## 2 200 52.41 10.74
## -----------------------------------------
## Total 600 52.47 10.15
## -----------------------------------------
##
## Test Statistics
## -------------------------------------------------------------------------
## Statistic Num DF Den DF F Pr > F
## -------------------------------------------------------------------------
## Brown and Forsythe 2 597 1.1683 0.3116
## Levene 2 597 1.3803 0.2523
## Brown and Forsythe (Trimmed Mean) 2 597 1.3258 0.2664
## -------------------------------------------------------------------------</code></pre>
</div>
</div>
</div>
<div id="cochrans-q-test" class="section level2">
<h2 class="hasAnchor">
<a href="#cochrans-q-test" class="anchor"></a>Cochran’s Q Test</h2>
<p>Cochran’s Q test is an extension to the McNemar test for related samples that provides a method for testing for differences between three or more matched sets of frequencies or proportions. It is a procedure for testing if the proportions of 3 or more dichotomous variables are equal in some population. These outcome variables have been measured on the same people or other statistical units.</p>
<div id="example-4" class="section level3">
<h3 class="hasAnchor">
<a href="#example-4" class="anchor"></a>Example</h3>
<p>The exam data set contains scores of 15 students for three exams (exam1, exam2, exam3). Test if three exams are equally difficult.</p>
<div class="sourceCode" id="cb45"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb45-1" data-line-number="1"><span class="kw"><a href="../reference/infer_cochran_qtest.html">infer_cochran_qtest</a></span>(exam, exam1, exam2, exam3)</a></code></pre></div>
<pre><code>## Test Statistics
## ----------------------
## N 15
## Cochran's Q 4.75
## df 2
## p value 0.093
## ----------------------</code></pre>
</div>
</div>
<div id="mcnemar-test" class="section level2">
<h2 class="hasAnchor">
<a href="#mcnemar-test" class="anchor"></a>McNemar Test</h2>
<p>McNemar test is a non parametric test created by Quinn McNemar and first published in <strong>Psychometrika</strong> in 1947. It is similar to a paired t test but applied to a dichotomous dependent variable. It is used to test if a statistically significant change in proportions have occurred on a dichotomous trait at two time points on the same population. It can be used to answer whether:</p>
<ul>
<li>two products are equally appealing?</li>
<li>proportion of success vs failure significantly change after treatment?</li>
<li>proportion of voters significantly change prior to and following a significant political development?</li>
</ul>
<div id="examples-8" class="section level3">
<h3 class="hasAnchor">
<a href="#examples-8" class="anchor"></a>Examples</h3>
<p>Using the hsb data, test if the proportion of students in himath and hiread group is equal.</p>
<div class="sourceCode" id="cb47"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb47-1" data-line-number="1">hb <-</a>
<a class="sourceLine" id="cb47-2" data-line-number="2"><span class="st"> </span>hsb <span class="op">%>%</span></a>
<a class="sourceLine" id="cb47-3" data-line-number="3"><span class="st"> </span><span class="kw">mutate</span>(</a>
<a class="sourceLine" id="cb47-4" data-line-number="4"> <span class="dt">himath =</span> <span class="kw">if_else</span>(math <span class="op">></span><span class="st"> </span><span class="dv">60</span>, <span class="dv">1</span>, <span class="dv">0</span>),</a>
<a class="sourceLine" id="cb47-5" data-line-number="5"> <span class="dt">hiread =</span> <span class="kw">if_else</span>(read <span class="op">></span><span class="st"> </span><span class="dv">60</span>, <span class="dv">1</span>, <span class="dv">0</span>)</a>
<a class="sourceLine" id="cb47-6" data-line-number="6"> )</a>
<a class="sourceLine" id="cb47-7" data-line-number="7"><span class="kw"><a href="../reference/infer_mcnemar_test.html">infer_mcnemar_test</a></span>(hb, himath, hiread)</a></code></pre></div>
<pre><code>## Controls
## ---------------------------------
## Cases 0 1 Total
## ---------------------------------
## 0 135 21 156
## 1 18 26 44
## ---------------------------------
## Total 153 47 200
## ---------------------------------
##
## McNemar's Test
## ----------------------------
## McNemar's chi2 0.2308
## DF 1
## Pr > chi2 0.631
## Exact Pr >= chi2 0.7493
## ----------------------------
##
## Kappa Coefficient
## --------------------------------
## Kappa 0.4454
## ASE 0.075
## 95% Lower Conf Limit 0.2984
## 95% Upper Conf Limit 0.5923
## --------------------------------
##
## Proportion With Factor
## ----------------------
## cases 0.78
## controls 0.765
## ratio 1.0196
## odds ratio 1.1667
## ----------------------</code></pre>
<div class="sourceCode" id="cb49"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb49-1" data-line-number="1">himath <-<span class="st"> </span><span class="kw">ifelse</span>(hsb<span class="op">$</span>math <span class="op">></span><span class="st"> </span><span class="dv">60</span>, <span class="dv">1</span>, <span class="dv">0</span>)</a>
<a class="sourceLine" id="cb49-2" data-line-number="2">hiread <-<span class="st"> </span><span class="kw">ifelse</span>(hsb<span class="op">$</span>read <span class="op">></span><span class="st"> </span><span class="dv">60</span>, <span class="dv">1</span>, <span class="dv">0</span>)</a>
<a class="sourceLine" id="cb49-3" data-line-number="3"><span class="kw"><a href="../reference/infer_mcnemar_test.html">infer_mcnemar_test</a></span>(<span class="kw">table</span>(himath, hiread))</a></code></pre></div>
<pre><code>## Controls
## ---------------------------------
## Cases 0 1 Total
## ---------------------------------
## 0 135 21 156
## 1 18 26 44
## ---------------------------------
## Total 153 47 200
## ---------------------------------
##
## McNemar's Test
## ----------------------------
## McNemar's chi2 0.2308
## DF 1
## Pr > chi2 0.631
## Exact Pr >= chi2 0.7493
## ----------------------------
##
## Kappa Coefficient
## --------------------------------
## Kappa 0.4454
## ASE 0.075
## 95% Lower Conf Limit 0.2984
## 95% Upper Conf Limit 0.5923
## --------------------------------
##
## Proportion With Factor
## ----------------------
## cases 0.78
## controls 0.765
## ratio 1.0196
## odds ratio 1.1667
## ----------------------</code></pre>
<p>Perform the above test using matrix as input.</p>
<div class="sourceCode" id="cb51"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb51-1" data-line-number="1"><span class="kw"><a href="../reference/infer_mcnemar_test.html">infer_mcnemar_test</a></span>(<span class="kw">matrix</span>(<span class="kw">c</span>(<span class="dv">135</span>, <span class="dv">18</span>, <span class="dv">21</span>, <span class="dv">26</span>), <span class="dt">nrow =</span> <span class="dv">2</span>))</a></code></pre></div>
<pre><code>## Controls
## ---------------------------------
## Cases 0 1 Total
## ---------------------------------
## 0 135 21 156
## 1 18 26 44
## ---------------------------------
## Total 153 47 200
## ---------------------------------
##
## McNemar's Test
## ----------------------------
## McNemar's chi2 0.2308
## DF 1
## Pr > chi2 0.631
## Exact Pr >= chi2 0.7493
## ----------------------------
##
## Kappa Coefficient
## --------------------------------
## Kappa 0.4454
## ASE 0.075
## 95% Lower Conf Limit 0.2984
## 95% Upper Conf Limit 0.5923
## --------------------------------
##
## Proportion With Factor
## ----------------------
## cases 0.78
## controls 0.765
## ratio 1.0196
## odds ratio 1.1667
## ----------------------</code></pre>
</div>
</div>
<div id="runs-test-for-randomness" class="section level2">
<h2 class="hasAnchor">
<a href="#runs-test-for-randomness" class="anchor"></a>Runs Test for Randomness</h2>
<p>Runs Test can be used to decide if a data set is from a random process. It tests whether observations of a sequence are serially independent i.e. whether they occur in a random order by counting how many runs there are above and below a threshold. A run is defined as a series of increasing values or a series of decreasing values. The number of increasing, or decreasing, values is the length of the run. By default, the median is used as the threshold. A small number of runs indicates positive serial correlation; a large number indicates negative serial correlation.</p>
<div id="examples-9" class="section level3">
<h3 class="hasAnchor">
<a href="#examples-9" class="anchor"></a>Examples</h3>
<p>We will use runs test to check regression residuals for serial correlation.</p>
<div class="sourceCode" id="cb53"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb53-1" data-line-number="1"><span class="co"># basic example</span></a>
<a class="sourceLine" id="cb53-2" data-line-number="2"><span class="kw"><a href="../reference/infer_runs_test.html">infer_runs_test</a></span>(hsb, read)</a></code></pre></div>
<pre><code>## Runs Test
## Total Cases: 200
## Test Value : 50
## Cases < Test Value: 101
## Cases > Test Value: 99
## Number of Runs: 95
## Expected Runs: 100.99
## Variance (Runs): 49.73874
## z Statistic: -0.8493358
## p-value: 0.3956945</code></pre>
<div class="sourceCode" id="cb55"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb55-1" data-line-number="1"><span class="co"># drop values equal to threshold</span></a>
<a class="sourceLine" id="cb55-2" data-line-number="2"><span class="kw"><a href="../reference/infer_runs_test.html">infer_runs_test</a></span>(hsb, read, <span class="dt">drop =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<pre><code>## Runs Test
## Total Cases: 200
## Test Value : 50
## Cases < Test Value: 83
## Cases > Test Value: 99
## Number of Runs: 89
## Expected Runs: 91.2967
## Variance (Runs): 44.54805
## z Statistic: -0.3441046
## p-value: 0.7307676</code></pre>
<div class="sourceCode" id="cb57"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb57-1" data-line-number="1"><span class="co"># recode data in binary format</span></a>
<a class="sourceLine" id="cb57-2" data-line-number="2"><span class="kw"><a href="../reference/infer_runs_test.html">infer_runs_test</a></span>(hsb, read, <span class="dt">split =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<pre><code>## Runs Test
## Total Cases: 200
## Test Value : 50
## Cases < Test Value: 101
## Cases > Test Value: 99
## Number of Runs: 95
## Expected Runs: 100.99
## Variance (Runs): 49.73874
## z Statistic: -0.8493358
## p-value: 0.3956945</code></pre>
<div class="sourceCode" id="cb59"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb59-1" data-line-number="1"><span class="co"># use mean as threshold</span></a>
<a class="sourceLine" id="cb59-2" data-line-number="2"><span class="kw"><a href="../reference/infer_runs_test.html">infer_runs_test</a></span>(hsb, read, <span class="dt">mean =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<pre><code>## Runs Test
## Total Cases: 200
## Test Value : 52.23
## Cases < Test Value: 115
## Cases > Test Value: 85
## Number of Runs: 93
## Expected Runs: 98.75
## Variance (Runs): 47.52418
## z Statistic: -0.8340854
## p-value: 0.4042329</code></pre>
<div class="sourceCode" id="cb61"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb61-1" data-line-number="1"><span class="co"># threshold to be used for counting runs</span></a>
<a class="sourceLine" id="cb61-2" data-line-number="2"><span class="kw"><a href="../reference/infer_runs_test.html">infer_runs_test</a></span>(hsb, read, <span class="dt">threshold =</span> <span class="dv">0</span>)</a></code></pre></div>
<pre><code>## Runs Test
## Total Cases: 200
## Test Value : 0
## Cases < Test Value: 0
## Cases > Test Value: 200
## Number of Runs: 1
## Expected Runs: 1
## Variance (Runs): 0
## z Statistic: NaN
## p-value: NaN</code></pre>
</div>
</div>
<div id="credits" class="section level2">
<h2 class="hasAnchor">
<a href="#credits" class="anchor"></a>Credits</h2>
<p>The examples and the data set used in the vignette are borrowed from the below listed sources:</p>
<ul>
<li>What statistical analysis should I use? UCLA: Statistical Consulting Group. from <a href="http://www.ats.ucla.edu/stat/mult_pkg/whatstat/" class="uri">http://www.ats.ucla.edu/stat/mult_pkg/whatstat/</a>
</li>
</ul>
</div>
</div>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
<div id="tocnav">
<h2 class="hasAnchor">
<a href="#tocnav" class="anchor"></a>Contents</h2>
<ul class="nav nav-pills nav-stacked">
<li><a href="#one-sample-t-test">One Sample t Test</a></li>
<li><a href="#paired-t-test">Paired t test</a></li>
<li><a href="#two-independent-sample-t-test">Two Independent Sample t Test</a></li>
<li><a href="#one-sample-test-of-proportion">One Sample Test of Proportion</a></li>
<li><a href="#two-sample-test-of-proportion">Two Sample Test of Proportion</a></li>
<li><a href="#one-sample-variance-test">One Sample Variance Test</a></li>
<li><a href="#two-sample-variance-test">Two Sample Variance Test</a></li>
<li><a href="#binomial-probability-test">Binomial Probability Test</a></li>
<li><a href="#anova">ANOVA</a></li>
<li><a href="#chi-square-goodness-of-fit-test">Chi Square Goodness of Fit Test</a></li>
<li><a href="#chi-square-test-of-independence">Chi Square Test of Independence</a></li>
<li><a href="#levenes-test">Levene’s Test</a></li>
<li><a href="#cochrans-q-test">Cochran’s Q Test</a></li>
<li><a href="#mcnemar-test">McNemar Test</a></li>
<li><a href="#runs-test-for-randomness">Runs Test for Randomness</a></li>
<li><a href="#credits">Credits</a></li>
</ul>
</div>
</div>
</div>
<footer><div class="copyright">
<p>Developed by <a href="https://www.aravindhebbali.com/">Aravind Hebbali</a>.</p>
</div>
<div class="pkgdown">
<p>Site built with <a href="http://hadley.github.io/pkgdown/">pkgdown</a>.</p>
</div>
</footer>
</div>
</body>
</html>