-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMedicalStatisNotes.tex
More file actions
6175 lines (4997 loc) · 385 KB
/
MedicalStatisNotes.tex
File metadata and controls
6175 lines (4997 loc) · 385 KB
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
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{article}
\usepackage{lmodern}
\usepackage{amssymb,amsmath,ctex}
\usepackage{ifxetex,ifluatex}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
\KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
hidelinks,
pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{248,248,248}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\BuiltInTok}[1]{#1}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
\newcommand{\ExtensionTok}[1]{#1}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ImportTok}[1]{#1}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\NormalTok}[1]{#1}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\RegionMarkerTok}[1]{#1}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\usepackage{longtable,booktabs}
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
\makesavenoteenv{longtable}
\usepackage{graphicx,grffile}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{5}
\usepackage{booktabs}
\usepackage{amsthm}
\makeatletter
\def\thm@space@setup{%
\thm@preskip=8pt plus 2pt minus 4pt
\thm@postskip=\thm@preskip
}
\makeatother
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{array}
\usepackage{multirow}
\usepackage{wrapfig}
\usepackage{float}
\usepackage{colortbl}
\usepackage{pdflscape}
\usepackage{tabu}
\usepackage{threeparttable}
\usepackage{threeparttablex}
\usepackage[normalem]{ulem}
\usepackage{makecell}
\usepackage{xcolor}
\usepackage[]{natbib}
\bibliographystyle{plainnat}
\author{}
\date{\vspace{-2.5em}}
\begin{document}
{
\setcounter{tocdepth}{2}
\tableofcontents
}
\hypertarget{ux7b80ux4ecbux4e0eux4f20ux9001ux95e8}{%
\section{简介与传送门}\label{ux7b80ux4ecbux4e0eux4f20ux9001ux95e8}}
日期: 2020-11-10
作者:wxhyihuan
\hypertarget{ux7b80ux4ecb}{%
\subsection{简介}\label{ux7b80ux4ecb}}
这份笔记主要是我个人在学习孙振球,徐勇勇老师的\textless{}\textgreater{} 第4版的过程中,尽量使用编程语言R对书中的示例进行实现的记录,
并用\href{https://github.com/rstudio/bookdown}{Bookdown}形成的。
\begin{verbatim}
<<医学统计学>> 孙振球, 徐勇勇. 第4版[M]. 人民卫生出版社, 2014.
\end{verbatim}
\begin{center}\includegraphics[width=0.25\linewidth]{image/Ms_logo} \end{center}
虽然在学习,整理过程中尽量将笔记的形式,内容结构进行力所能及的梳理,这里要特别感谢在学习过程中,在网络上找到的一些参考资料带来的帮助,然后将一些
示例与原书进行对照,以避免一些学习错误,但个人能力和精力实在有限,也容易会有理解不当,表述错误的情况,
如果您在参考的过程中,发现了这样的错误,请您尽量可以告诉我,我会确认并努力修正,如果您对文档有疑问或建议,都可以 \textbf{\href{mailto:wxh244295043@gamil.com}{邮件}} 告知我。
建议您购买原版教材结合本笔记学习,您也可以在网络上找到电子书方便参考。
形成此文档对我来讲是一个很大的挑战,需要耗费巨大精力。另外,因为本人特殊情况,难以像以前正常工作,所以也是以此方式
保持学习能力,和提升自己。希望这份文档能对您有所助益,如果正是如此,您愿意的话可以捐助我,这里先谢过鼓励和支持的朋友\textasciitilde{}
\begin{center}\includegraphics[width=0.7\linewidth]{image/SponsorshipFig} \end{center}
\hypertarget{ux8f6fux4ef6ux51c6ux5907}{%
\subsubsection{软件准备}\label{ux8f6fux4ef6ux51c6ux5907}}
本文档使用到的主要软件 \href{https://www.r-project.org/}{R}版本是4.0.3, 和 \href{https://rstudio.com/}{RStudio},版本是 1.3.1093 .
如果您R语言的新手,您可以在下面找到一些快速上手的学习资料:
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
\href{https://rstudio.com/resources/cheatsheets/}{RStudio Cheatsheets}
\item
\href{https://cran.r-project.org/doc/contrib/Paradis-rdebuts_en.pdf}{R for Beginners}
\end{enumerate}
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{sessionInfo}\NormalTok{()}
\CommentTok{## R version 4.0.3 (2020-10-10)}
\CommentTok{## Platform: x86_64-w64-mingw32/x64 (64-bit)}
\CommentTok{## Running under: Windows 10 x64 (build 19041)}
\CommentTok{## Matrix products: default}
\CommentTok{## locale:}
\CommentTok{## [1] LC_COLLATE=Chinese (Simplified)_China.936 }
\CommentTok{## [2] LC_CTYPE=Chinese (Simplified)_China.936 }
\CommentTok{## [3] LC_MONETARY=Chinese (Simplified)_China.936}
\CommentTok{## [4] LC_NUMERIC=C }
\CommentTok{## [5] LC_TIME=Chinese (Simplified)_China.936 }
\CommentTok{## attached base packages:}
\CommentTok{## [1] stats graphics grDevices utils datasets methods base }
\CommentTok{## loaded via a namespace (and not attached):}
\CommentTok{## [1] compiler_4.0.3 bookdown_0.21 htmltools_0.5.0 tools_4.0.3 }
\CommentTok{## [5] yaml_2.2.1 tinytex_0.27 rmarkdown_2.5 knitr_1.30 }
\CommentTok{## [9] digest_0.6.27 xfun_0.19 rlang_0.4.8 evaluate_0.14 }
\end{Highlighting}
\end{Shaded}
\hypertarget{ux4f20ux9001ux95e8}{%
\subsection{传送门}\label{ux4f20ux9001ux95e8}}
如果您希望快速找到R处理数据的方法,可以通过下面几张插图里面的传送门进行传送。注意的是,似乎Rmarkdown里面对
SVG插图中包含链接展示无法支持,所以你可以
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
\emph{``右击''}插图,选择在 \emph{``新标签页打开图片''},然后新标页签打开的图片。这样可以找到图片中包含的超链接,快速找到合适的章节内容。
\item
\emph{``右击''}插图,选择在 \emph{``图片另存为''},这样包含的超链接图片保存下来,可以在需要的时候快速找到合适的章节内容。
\end{enumerate}
\begin{figure}
\includegraphics[width=0.9\linewidth]{image/ChoiceStatisticalMethods_href} \hfill{}
\caption{完全随机设计的统计方法选择思路(目前, 传送门还不完整,在随书更新ing)}\label{fig:Gateway1}
\end{figure}
\hypertarget{ux81f4ux8c22}{%
\subsection{致谢}\label{ux81f4ux8c22}}
谨以此书献给我的家人,想在此感谢母亲和父亲,纪念祝愿我的姐姐及她的两个丫头。
最后,祝愿到此一游的你我他! ̄▽ ̄
\hypertarget{ux58f0ux660e}{%
\subsection{声明}\label{ux58f0ux660e}}
本笔记可供选修《医学统计学》课程的同学学习使用,如果您需要将素材和代码作其它用途,请联系作者:\href{mailto:wxh244295043@gmail.com}{\nolinkurl{wxh244295043@gmail.com}}。
\hypertarget{ux7b2cux4e8cux7ae0-ux8ba1ux91cfux8d44ux6599ux7684ux7edfux8ba1ux63cfux8ff0}{%
\section{第二章 计量资料的统计描述}\label{ux7b2cux4e8cux7ae0-ux8ba1ux91cfux8d44ux6599ux7684ux7edfux8ba1ux63cfux8ff0}}
日期: 2020-11-10
作者:wxhyihuan
\hypertarget{ux63cfux8ff0ux7edfux8ba1}{%
\subsection{描述统计}\label{ux63cfux8ff0ux7edfux8ba1}}
描述统计学(广义上的描述统计学,Descriptive statistics)是统计学的一个分支,旨在概括、描述和呈现一系列值或数据集(比如对单样本的分析)。
由于难以识别数据中的任何模式,没有任何准备或没有任何汇总度量的长系列值通常无法提供信息。
描述统计通常是统计分析的第一步,也是统计分析的重要组成部分。它允许通过检测潜在的异常值(即似乎与其他数据分离的数据点)、
收集或编码错误来检查数据的质量。它还有助于``理解''数据,如果表述得当,描述性统计是进一步分析的一个很好的起点。
位置与离散度量是两种不同的总结数据的测量方法。其中一些给出了关于数据位置的理解,另一些给出了关于数据分散性的理解。
在实践中,这两种度量方法经常一起使用,以便以最简洁和完整的方式总结数据。
位置度量允许查看数据位于``何处'',围绕哪个值。换句话说,位置度量可了解什么是总体趋势,即数据整体的``位置''。
它主要包括:\emph{平均值,中位数,四分位数,第三、四分位数,众数,最大值,最小值等}。
常见的离散度量,它有助于了解离散度和数据的可变性(在何种程度上分布被压缩或拉伸):\emph{范围,标准偏差,方差,四分位间距,变异系数}。
\hypertarget{ux6d4bux8bd5ux6570ux636e}{%
\subsection{测试数据}\label{ux6d4bux8bd5ux6570ux636e}}
\begin{table}
\caption{\label{tab:tab1}某医院用随机抽样的方法检测了138名正常成年女子的红细胞数目(RBC, $*10^{12}/L$),其测量结果如下表:}
\centering
\begin{tabular}[t]{cccccccccccc}
\toprule
V1 & V2 & V3 & V4 & V5 & V6 & V7 & V8 & V9 & V10 & V11 & V12\\
\midrule
3.96 & 4.23 & 4.42 & 3.59 & 5.12 & 4.02 & 4.32 & 3.72 & 4.76 & 4.16 & 4.61 & 4.26\\
3.77 & 4.20 & 4.36 & 3.07 & 4.89 & 3.97 & 4.28 & 3.64 & 4.66 & 4.04 & 4.55 & 4.25\\
4.63 & 3.91 & 4.41 & 3.52 & 5.03 & 4.01 & 4.30 & 4.19 & 4.75 & 4.14 & 4.57 & 4.26\\
4.56 & 3.79 & 3.89 & 4.21 & 4.95 & 3.98 & 4.29 & 3.67 & 4.69 & 4.12 & 4.56 & 4.26\\
4.66 & 4.28 & 3.83 & 4.20 & 5.24 & 4.02 & 4.33 & 3.76 & 4.81 & 4.17 & 3.96 & 3.27\\
\addlinespace
4.61 & 4.26 & 3.96 & 4.23 & 3.76 & 4.01 & 4.29 & 3.67 & 3.39 & 4.12 & 4.27 & 3.61\\
4.98 & 4.24 & 3.83 & 4.20 & 3.71 & 4.03 & 4.34 & 4.69 & 3.62 & 4.18 & 4.26 & 4.36\\
5.28 & 4.21 & 4.42 & 4.36 & 3.66 & 4.02 & 4.31 & 4.83 & 3.59 & 3.97 & 3.96 & 4.49\\
5.11 & 4.20 & 4.36 & 4.54 & 3.72 & 3.97 & 4.28 & 4.76 & 3.21 & 4.04 & 4.56 & 4.25\\
4.92 & 4.23 & 4.47 & 3.60 & 5.23 & 4.02 & 4.32 & 4.68 & 4.76 & 3.69 & 4.61 & 4.26\\
\addlinespace
3.89 & 4.21 & 4.36 & 3.42 & 5.01 & 4.01 & 4.29 & 3.68 & 4.71 & 4.13 & 4.57 & 4.26\\
4.03 & 5.46 & 4.16 & 3.64 & 4.16 & 3.76 & & & & & & \\
\bottomrule
\end{tabular}
\end{table}
\hypertarget{ux6570ux636eux8f93ux5165ux548cux9891ux7387ux7edfux8ba1}{%
\subsection{数据输入和频率统计}\label{ux6570ux636eux8f93ux5165ux548cux9891ux7387ux7edfux8ba1}}
\hypertarget{ux8bfbux53d6ux6570ux636eux5e76ux5c06ux6570ux636eux8f6cux6362ux6210ux5355ux5217ux5f62ux5f0f}{%
\subsubsection{读取数据,并将数据转换成单列形式}\label{ux8bfbux53d6ux6570ux636eux5e76ux5c06ux6570ux636eux8f6cux6362ux6210ux5355ux5217ux5f62ux5f0f}}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{RBC<-}\KeywordTok{read.table}\NormalTok{(}\StringTok{"ExampleData/02-01.txt"}\NormalTok{,}\DataTypeTok{sep=}\StringTok{"}\CharTok{\textbackslash{}t}\StringTok{"}\NormalTok{)}
\NormalTok{RBC<-}\KeywordTok{as.matrix}\NormalTok{(RBC)}
\NormalTok{RBC_q <-}\StringTok{ }\KeywordTok{c}\NormalTok{()}
\ControlFlowTok{for}\NormalTok{ (i }\ControlFlowTok{in} \KeywordTok{seq}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\KeywordTok{nrow}\NormalTok{(RBC)))\{}
\NormalTok{ RBC_q <-}\StringTok{ }\KeywordTok{c}\NormalTok{(RBC_q, RBC[i,])}
\NormalTok{\}}
\NormalTok{RBC_v<-}\KeywordTok{as.vector}\NormalTok{(RBC_q)}
\NormalTok{RBC_v<-}\KeywordTok{na.omit}\NormalTok{(RBC_v)}
\end{Highlighting}
\end{Shaded}
\hypertarget{ux8ba1ux7b97ux6781ux5dee-maxminrange}{%
\subsubsection{计算极差, max()/min()/range()}\label{ux8ba1ux7b97ux6781ux5dee-maxminrange}}
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#range(RBC_v) 返回最小值和最大值}
\NormalTok{rge<-}\KeywordTok{max}\NormalTok{(RBC_v)}\OperatorTok{-}\KeywordTok{min}\NormalTok{(RBC_v)}
\NormalTok{rge}
\CommentTok{## [1] 2.39}
\end{Highlighting}
\end{Shaded}
\hypertarget{ux786eux5b9aux7ec4ux6bb5ux6570ux548cux7ec4ux8ddd}{%
\subsubsection{确定组段数和组距}\label{ux786eux5b9aux7ec4ux6bb5ux6570ux548cux7ec4ux8ddd}}
可以参考PAST软件中的the zero-stage rule of Wand 1997方式计算分段``最佳''个数。\(h=3.49min(s,IQ/1.349)n^{1/3}\),其中s是样本标准差,IQ是四分位数范围。
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#sd()计算标准差,quantile()计算分位数}
\NormalTok{s<-}\KeywordTok{sd}\NormalTok{(RBC_v)}
\CommentTok{## [1] 0.4457298}
\NormalTok{quan<-}\KeywordTok{quantile}\NormalTok{(RBC_v,}\KeywordTok{c}\NormalTok{(}\FloatTok{0.25}\NormalTok{,}\FloatTok{0.75}\NormalTok{))}
\NormalTok{iq<-quan[}\DecValTok{2}\NormalTok{]}\OperatorTok{-}\NormalTok{quan[}\DecValTok{1}\NormalTok{]}
\CommentTok{## 0.565}
\NormalTok{h<-}\FloatTok{3.49}\OperatorTok{*}\KeywordTok{min}\NormalTok{(s,iq}\OperatorTok{/}\FloatTok{1.349}\NormalTok{)}\OperatorTok{*}\NormalTok{(}\KeywordTok{length}\NormalTok{(RBC_v)}\OperatorTok{^}\NormalTok{(}\DecValTok{1}\OperatorTok{/}\DecValTok{3}\NormalTok{))}
\CommentTok{## 7.553617}
\NormalTok{h<-}\KeywordTok{ceiling}\NormalTok{(h)}
\CommentTok{## 8}
\NormalTok{i<-rge}\OperatorTok{/}\NormalTok{h}
\end{Highlighting}
\end{Shaded}
\hypertarget{ux8ba1ux7b97ux9891ux6570ux5206ux5e03}{%
\subsubsection{计算频数分布}\label{ux8ba1ux7b97ux9891ux6570ux5206ux5e03}}
根据计算的短组段数(h=8),极差值(rge=2.39))和组距(i=rge/h=0.3164)计算各组段的频数。
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{breaks =}\StringTok{ }\KeywordTok{seq}\NormalTok{(}\KeywordTok{min}\NormalTok{(RBC_v), }\KeywordTok{max}\NormalTok{(RBC_v), }\DataTypeTok{length.out =} \DecValTok{8}\NormalTok{)}
\NormalTok{RBC_v.cut =}\StringTok{ }\KeywordTok{cut}\NormalTok{(RBC_v, breaks, }\DataTypeTok{right=}\NormalTok{T,}\DataTypeTok{include.lowest=}\NormalTok{T)}
\NormalTok{RBC_v.freq =}\StringTok{ }\KeywordTok{table}\NormalTok{(RBC_v.cut)}
\CommentTok{## [3.07,3.41) [3.41,3.75) [3.75,4.09) [4.09,4.44) [4.44,4.78) }
\CommentTok{## 4 17 29 51 23 }
\CommentTok{## [4.78,5.12) [5.12,5.46) }
\CommentTok{## 9 4 }
\KeywordTok{hist}\NormalTok{(RBC_v, }\DataTypeTok{right=}\OtherTok{FALSE}\NormalTok{, }
\DataTypeTok{breaks =}\NormalTok{ breaks, }\DataTypeTok{labels =}\OtherTok{TRUE}\NormalTok{, }
\DataTypeTok{freq =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{col =} \StringTok{"#A8D6FF"}\NormalTok{, }
\DataTypeTok{border =} \StringTok{"white"}\NormalTok{, }\DataTypeTok{ylim=}\KeywordTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{, }\KeywordTok{max}\NormalTok{(RBC_v.freq))) }
\KeywordTok{hist}\NormalTok{(RBC_v, }\DataTypeTok{right=}\OtherTok{FALSE}\NormalTok{, }
\DataTypeTok{breaks =}\NormalTok{ breaks, }\DataTypeTok{labels =}\OtherTok{TRUE}\NormalTok{, }
\DataTypeTok{freq =} \OtherTok{FALSE}\NormalTok{, }\DataTypeTok{col =} \StringTok{"#A8D6FF"}\NormalTok{, }
\DataTypeTok{border =} \StringTok{"white"}\NormalTok{, }\DataTypeTok{ylim=}\KeywordTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{,}\DecValTok{1}\NormalTok{))}
\KeywordTok{lines}\NormalTok{(}\KeywordTok{density}\NormalTok{(RBC_v),}\DataTypeTok{col=}\StringTok{"red"}\NormalTok{,}\DataTypeTok{lwd=}\DecValTok{2}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{figure}
{\centering \includegraphics[width=0.49\linewidth,height=0.49\textheight]{image/a1e3904af844b14d3b57d1448690aea} \includegraphics[width=0.49\linewidth,height=0.49\textheight]{image/5ba23e818daa7c71b147707f9b5dfd6}
}
\caption{红细胞含量的频数分布}\label{fig:histgrah}
\end{figure}
\hypertarget{ux63cfux8ff0ux6027ux7edfux8ba1ux7684ux5ea6ux91cf}{%
\subsection{描述性统计的度量}\label{ux63cfux8ff0ux6027ux7edfux8ba1ux7684ux5ea6ux91cf}}
\hypertarget{ux7b97ux672fux5e73ux5747ux503c}{%
\subsubsection{算术平均值}\label{ux7b97ux672fux5e73ux5747ux503c}}
算术均数简称均值(mean),用于反映组呈对称分布的变量值在数量上的平均水平。
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{mean}\NormalTok{(RBC_v)}
\CommentTok{## [1] 4.227029}
\end{Highlighting}
\end{Shaded}
\hypertarget{ux51e0ux4f55ux5e73ux5747ux503c}{%
\subsubsection{几何平均值}\label{ux51e0ux4f55ux5e73ux5747ux503c}}
几何均数(geometric mean)可用于反映一组经 \textbf{对数转换} 后呈对称分布的变量值在数量上的平均水平。
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{exp}\NormalTok{(}\KeywordTok{mean}\NormalTok{(}\KeywordTok{log}\NormalTok{(RBC_v)))}
\CommentTok{## [1] 4.203676}
\end{Highlighting}
\end{Shaded}
\hypertarget{ux4e2dux4f4dux6570ux4e0eux767eux5206ux4f4dux6570}{%
\subsubsection{中位数与百分位数}\label{ux4e2dux4f4dux6570ux4e0eux767eux5206ux4f4dux6570}}
中位数(median)是将n个变量值从小到大排列,位置居于中间的那个数。当为奇数时取位次居中 的变量值,当n为偶数时取位次居中的两个变量值的均数。
它适用于各种分布类型的资料,尤其是偏态分 布资料和一端或两端无确切数值的资料。
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#中位数(=50百分位)}
\KeywordTok{median}\NormalTok{(RBC_v)}
\KeywordTok{quantile}\NormalTok{(RBC_v, }\FloatTok{0.5}\NormalTok{)}
\CommentTok{## 4.23}
\CommentTok{#百分位}
\KeywordTok{quantile}\NormalTok{(RBC_v, }\KeywordTok{c}\NormalTok{(}\FloatTok{0.1}\NormalTok{, }\FloatTok{0.25}\NormalTok{, }\FloatTok{0.5}\NormalTok{,}\FloatTok{0.75}\NormalTok{,}\FloatTok{0.9}\NormalTok{))}
\CommentTok{## 10% 25% 50% 75% 90% }
\CommentTok{##3.6670 3.9625 4.2300 4.5275 4.7750 }
\end{Highlighting}
\end{Shaded}
\hypertarget{ux6781ux5dee}{%
\subsubsection{极差}\label{ux6781ux5dee}}
极差即一组变量值的最大值与最小值之差。
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{max}\NormalTok{(RBC_v)}\OperatorTok{-}\KeywordTok{min}\NormalTok{(RBC_v)}
\KeywordTok{range}\NormalTok{(RBC_v)}
\end{Highlighting}
\end{Shaded}
\hypertarget{ux56dbux5206ux4f4dux95f4ux8ddd}{%
\subsubsection{四分位间距}\label{ux56dbux5206ux4f4dux95f4ux8ddd}}
四分位数(quartile)是把全部变量值分为四部分的分位数,即第1四分位数(Q .=Ps)、第2四分位数 M=P)、第3四分位数 (Qu=Ps)。 四分位数间距(quartile range)是由第3四分位数和第1四分位数相减行得,
记为 R.它般和中位数起描述偏态分们资料的分布特征
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#四分位间距interquartile range}
\KeywordTok{IQR}\NormalTok{(RBC_v)}
\CommentTok{## 0.565}
\KeywordTok{quantile}\NormalTok{(RBC_v, }\FloatTok{0.75}\NormalTok{)}\OperatorTok{-}\KeywordTok{quantile}\NormalTok{(RBC_v, }\FloatTok{0.25}\NormalTok{)}
\CommentTok{## 0.565}
\end{Highlighting}
\end{Shaded}
\hypertarget{ux65b9ux5deeux4e0eux6807ux51c6ux5dee}{%
\subsubsection{方差与标准差}\label{ux65b9ux5deeux4e0eux6807ux51c6ux5dee}}
方差(variance,var)也称均方差(mean Square deviation),反映一组数据的平均离散水平。
标准差(standard deviation,sd)是方差的正平方根,其单位与原变量值的单位相同。
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#计算标准差}
\KeywordTok{sd}\NormalTok{(RBC_v)}
\CommentTok{## [1] 0.4457298}
\CommentTok{#计算方差}
\KeywordTok{var}\NormalTok{(RBC_v)}
\CommentTok{## [1] 0.1986751}
\KeywordTok{sd}\NormalTok{(RBC_v)}\OperatorTok{^}\DecValTok{2}
\NormalTok{(}\KeywordTok{sum}\NormalTok{((RBC_v}\OperatorTok{-}\KeywordTok{mean}\NormalTok{(RBC_v))}\OperatorTok{^}\DecValTok{2}\NormalTok{))}\OperatorTok{/}\NormalTok{(}\KeywordTok{length}\NormalTok{(RBC_v)}\OperatorTok{-}\DecValTok{1}\NormalTok{)}
\CommentTok{## 0.1986751}
\end{Highlighting}
\end{Shaded}
\hypertarget{ux53d8ux5f02ux7cfbux6570}{%
\subsubsection{变异系数}\label{ux53d8ux5f02ux7cfbux6570}}
变异系数(Cefficient of variation,CV),当进行两个或多个资料变异程度的比较时,如果度量单位与平均数相同,
可以直接利用标准差来比较。如果单位和(或)平均数不同时,比较其变异程度就不能采用标准差,
而需采用标准差与平均数的比值(相对值)来比较。标准差与平均数的比值称为变异系数,。
变异系数可以消除单位和(或)平均数不同对两个或多个资料变异程度比较的影响。
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{sd}\NormalTok{(RBC_v)}\OperatorTok{/}\KeywordTok{mean}\NormalTok{(RBC_v)}\OperatorTok{*}\DecValTok{100}
\CommentTok{## [1] 10.54475}
\NormalTok{raster}\OperatorTok{::}\KeywordTok{cv}\NormalTok{(RBC_v)}
\CommentTok{## [1] 10.54475}
\end{Highlighting}
\end{Shaded}
\hypertarget{ux5176ux4ed6ux7684ux63cfux8ff0ux7edfux8ba1}{%
\subsubsection{其他的描述统计}\label{ux5176ux4ed6ux7684ux63cfux8ff0ux7edfux8ba1}}
\hypertarget{summary}{%
\paragraph{Summary}\label{summary}}
R语言中,可以使用summary()来计算最小,第1四分位数,中位数,平均值,第3,4分位数和最大值的数据集的所有数值变量。
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{dat <-}\StringTok{ }\NormalTok{iris}
\KeywordTok{summary}\NormalTok{(dat)}
\CommentTok{## Sepal.Length Sepal.Width Petal.Length Petal.Width Species }
\CommentTok{## Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100 setosa :50 }
\CommentTok{## 1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300 versicolor:50 }
\CommentTok{## Median :5.800 Median :3.000 Median :4.350 Median :1.300 virginica :50 }
\CommentTok{## Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199 }
\CommentTok{## 3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800 }
\CommentTok{## Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500 }
\end{Highlighting}
\end{Shaded}
\hypertarget{ux4f17ux6570}{%
\paragraph{众数}\label{ux4f17ux6570}}
众数(Mode)是指在统计分布上具有明显集中趋势点的数值,代表数据的一般水平。 也是一组数据中出现次数最多的数值,有时众数在一组数中有好几个。
可以利用table()和sort()来寻找数据集中的众数。
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{# 计算每个元素的出现的次数}
\NormalTok{RBC_t <-}\StringTok{ }\KeywordTok{table}\NormalTok{(RBC_v) }
\CommentTok{# 对计算的次数进行排序}
\KeywordTok{sort}\NormalTok{(RBC_t, }\DataTypeTok{decreasing =} \OtherTok{TRUE}\NormalTok{) }
\CommentTok{## 4.26 4.36 3.96 4.02 4.2 3.76 3.97 4.01 4.16 4.21 4.23 4.28 4.29 4.56 4.61 4.76 }
\CommentTok{## 7 5 4 4 4 3 3 3 3 3 3 3 3 3 3 3 }
\CommentTok{## 3.59 3.64 3.67 3.72 3.83 3.89 4.03 4.04 4.12 4.25 4.32 4.42 4.57 4.66 4.69 3.07 }
\CommentTok{## 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 }
\CommentTok{## 3.21 3.27 3.39 3.42 3.52 3.6 3.61 3.62 3.66 3.68 3.69 3.71 3.77 3.79 3.91 3.98 }
\CommentTok{## 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 }
\CommentTok{## 4.13 4.14 4.17 4.18 4.19 4.24 4.27 4.3 4.31 4.33 4.34 4.41 4.47 4.49 4.54 4.55 }
\CommentTok{## 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 }
\CommentTok{## 4.63 4.68 4.71 4.75 4.81 4.83 4.89 4.92 4.95 4.98 5.01 5.03 5.11 5.12 5.23 5.24 }
\CommentTok{## 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 }
\CommentTok{## 5.28 5.46 }
\CommentTok{## 1 1 }
\CommentTok{#或者结合 which()函数确定众数和其次数}
\NormalTok{RBC_t[}\KeywordTok{which}\NormalTok{(((RBC_t}\OperatorTok{==}\KeywordTok{max}\NormalTok{(RBC_t))}\OperatorTok{==}\NormalTok{T))]}
\CommentTok{## 4.26 }
\CommentTok{## 7 }
\end{Highlighting}
\end{Shaded}
\hypertarget{ux6b63ux6001ux5206ux5e03ux548cux6807ux51c6ux6b63ux6001ux5206ux5e03}{%
\subsection{正态分布和标准正态分布}\label{ux6b63ux6001ux5206ux5e03ux548cux6807ux51c6ux6b63ux6001ux5206ux5e03}}
\href{https://zh.wikipedia.org/zh-cn/\%E6\%AD\%A3\%E6\%80\%81\%E5\%88\%86\%E5\%B8\%83}{正态分布}(Normal distribution)又名高斯分布(Gaussian distribution),是一个非常常见的连续概率分布。
\textbf{正态分布}在统计学上十分重要,经常用在自然和社会科学来代表一个不明的随机变量。
可以说,弄懂正态分布是灵活运用统计学中各种假设检验方法、理解p值,均数置信区间的前提。
R包含有很丰富的正态分布相关的\href{https://stat.ethz.ch/R-manual/R-devel/library/stats/html/Normal.html}{函数功能},
比如概率密度函数dnorm(),概率累积分布函数pnorm(),正态分位函数qnorm()和用来生成特定正态分布数据序列的函数rnorm(),
以及检测数据时候符合正态分布的方法,这里主要做下面一些介绍。
\hypertarget{ux6982ux7387ux5bc6ux5ea6ux51fdux6570dnorm}{%
\subsubsection{概率密度函数dnorm()}\label{ux6982ux7387ux5bc6ux5ea6ux51fdux6570dnorm}}
\href{https://zh.wikipedia.org/zh-cn/\%E6\%A9\%9F\%E7\%8E\%87\%E5\%AF\%86\%E5\%BA\%A6\%E5\%87\%BD\%E6\%95\%B8}{概率密度函数(Probability density function)},R中即为dnorm(),
它可以给出了指定均值和标准差下每个点的\textbf{概率分布的高度},
越高就代表着这个点/区间的概率越密集(大)。概率密度函数有时也被称为概率分布函数,但这种称法可能会和累积分布函数pnorm()混淆。
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#在-10~10区间等分的 100个 数据集x}
\NormalTok{x <-}\StringTok{ }\KeywordTok{seq}\NormalTok{(}\OperatorTok{-}\DecValTok{10}\NormalTok{, }\DecValTok{10}\NormalTok{, }\DataTypeTok{by =} \FloatTok{.1}\NormalTok{)}
\CommentTok{#创建一个均值是2.5,标准差是0.5正态分布 y}
\NormalTok{y <-}\StringTok{ }\KeywordTok{dnorm}\NormalTok{(x, }\DataTypeTok{mean =} \FloatTok{2.5}\NormalTok{, }\DataTypeTok{sd =} \FloatTok{0.5}\NormalTok{)}
\CommentTok{#将 y 中的落在x数据集上的数据画出来}
\KeywordTok{plot}\NormalTok{(x,y,}\DataTypeTok{col=}\StringTok{"red"}\NormalTok{,}\DataTypeTok{pch=}\DecValTok{20}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{figure}
{\centering \includegraphics[width=0.49\linewidth,height=0.49\textheight]{figs/dnorm}
}
\caption{概率密度函数示例}\label{fig:dnorm}
\end{figure}
\hypertarget{ux6982ux7387ux7d2fux79efux5206ux5e03ux51fdux6570pnorm}{%
\subsubsection{概率累积分布函数pnorm()}\label{ux6982ux7387ux7d2fux79efux5206ux5e03ux51fdux6570pnorm}}
\href{https://zh.wikipedia.org/wiki/\%E7\%B4\%AF\%E7\%A7\%AF\%E5\%88\%86\%E5\%B8\%83\%E5\%87\%BD\%E6\%95\%B0}{累积分布函数(Cumulative Distribution Function)},R中即为pnorm(),
又叫分布函数,是概率密度函数的积分,能完整描述一个实随机变量X的概率分布,它给出一个正态分布中小于一个给定数字的累计概率(即指定定点的左边范围的曲线面积)。
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#在-10~10区间等分的 40个 数据集x}
\NormalTok{x <-}\StringTok{ }\KeywordTok{seq}\NormalTok{(}\OperatorTok{-}\DecValTok{10}\NormalTok{, }\DecValTok{10}\NormalTok{, }\DataTypeTok{by =} \FloatTok{.5}\NormalTok{)}
\CommentTok{#创建一个均值是2.5,标准差是0.5正态分布 y}
\NormalTok{y <-}\StringTok{ }\KeywordTok{pnorm}\NormalTok{(x, }\DataTypeTok{mean =} \FloatTok{2.5}\NormalTok{, }\DataTypeTok{sd =} \FloatTok{0.5}\NormalTok{)}
\CommentTok{#将 y 中的落在x数据集上的累计概率画出来}
\KeywordTok{plot}\NormalTok{(x,y,}\DataTypeTok{col=}\StringTok{"red"}\NormalTok{,}\DataTypeTok{pch=}\DecValTok{20}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{figure}
{\centering \includegraphics[width=0.49\linewidth,height=0.49\textheight]{figs/pnorm}
}
\caption{累积分布函数示例}\label{fig:pnorm}
\end{figure}
\hypertarget{ux6b63ux6001ux5206ux4f4dux51fdux6570qnorm}{%
\subsubsection{正态分位函数qnorm()}\label{ux6b63ux6001ux5206ux4f4dux51fdux6570qnorm}}
正态分位函数,R中即为qnorm(),它可以给出一个累积分布概率达到指定值的数字。
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#在0~1区间等分的 50个 数据集x}
\NormalTok{x <-}\StringTok{ }\NormalTok{x <-}\StringTok{ }\KeywordTok{seq}\NormalTok{(}\DecValTok{0}\NormalTok{, }\DecValTok{1}\NormalTok{, }\DataTypeTok{by =} \FloatTok{0.02}\NormalTok{)}
\CommentTok{#创建一个均值是2,标准差是1正态分布 y}
\NormalTok{y <-}\StringTok{ }\KeywordTok{qnorm}\NormalTok{(x, }\DataTypeTok{mean =} \DecValTok{2}\NormalTok{, }\DataTypeTok{sd =} \DecValTok{1}\NormalTok{)}
\CommentTok{#将 y 中的落在x数据集上的数字画出来}
\KeywordTok{plot}\NormalTok{(x,y,}\DataTypeTok{col=}\StringTok{"red"}\NormalTok{,}\DataTypeTok{pch=}\DecValTok{20}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{figure}
{\centering \includegraphics[width=0.49\linewidth,height=0.49\textheight]{figs/qnorm}
}
\caption{正态分位函数示例}\label{fig:qnorm}
\end{figure}
\hypertarget{ux751fux6210ux6b63ux6001ux5206ux5e03ux51fdux6570rnorm}{%
\subsubsection{生成正态分布函数rnorm()}\label{ux751fux6210ux6b63ux6001ux5206ux5e03ux51fdux6570rnorm}}
rnorm()函数用于生成符合指定均值和标准差的分布为正态分布的随机数,默认是标准正态分布,即均值为0,标准差1的正态分布。
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#设置随机种子,便于重复后续的数据选取}
\KeywordTok{set.seed}\NormalTok{(}\DecValTok{50}\NormalTok{)}
\CommentTok{#在标准正态分布中随机选取50个数据}
\NormalTok{y <-}\StringTok{ }\KeywordTok{rnorm}\NormalTok{(}\DecValTok{50}\NormalTok{)}
\CommentTok{#对选区的数据绘制频率分布图}
\KeywordTok{hist}\NormalTok{(y,}\DataTypeTok{col=}\StringTok{"#A8D6FF"}\NormalTok{,}\DataTypeTok{labels =}\OtherTok{TRUE}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{figure}
{\centering \includegraphics[width=0.49\linewidth,height=0.49\textheight]{figs/rnorm}
}
\caption{随机正态分布数据示例}\label{fig:rnorm}
\end{figure}
\hypertarget{ux6b63ux6001ux5206ux5e03ux68c0ux9a8c}{%
\subsection{正态分布检验}\label{ux6b63ux6001ux5206ux5e03ux68c0ux9a8c}}
许多计量资料的分析方法要求数据分布是正态或近似正态,因此对原始独立测定数据进行正态性检验是十分必要的。通过绘制数据的频数分布直方图来定性地判断数据分布正态性。
以下正态检验的资料整理自:
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\item
\href{https://blog.csdn.net/u013524655/article/details/41053105?utm_medium=distribute.pc_relevant.none-task-blog-baidulandingword-7\&spm=1001.2101.3001.4242}{用R语言做正态分布检验}
\item
\href{https://www.statsandr.com/blog/do-my-data-follow-a-normal-distribution-a-note-on-the-most-widely-used-distribution-and-how-to-test-for-normality-in-r/}{How to test the normality assumption}
\end{enumerate}
正态性检验主要有三类方法:
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\item
计算综合统计量
如动差法、夏皮罗-威尔克Shapiro-Wilk 法(W 检验) 、达戈斯提诺D′Agostino 法(D 检验) 、Shapiro-Francia 法(W′检验)。
\item
正态分布的拟合优度检验
如皮尔逊χ2 检验 、对数似然比检验 、柯尔莫哥洛夫Kolmogorov-Smirov 法检验。
\item
图示法(正态概率图Normal Probability plot)
如分位数图(Quantile Quantileplot ,简称QQ 图) 、百分位数(Percent Percent plot ,简称PP 图) 和稳定化概率图(Stablized Probability plot ,
简称SP 图) 等。
\end{enumerate}
统计软件中常用的正态性检验方法
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\item
用偏态系数和峰态系数检验数据正态性
偏态系数Sk,它用于检验不对称性;峰态系数Ku,它用于检验峰态。 S k= 0, K u= 0 时, 分布呈正态, S k\textgreater{} 0 时, 分布呈正偏态,S k \textless{} 0 时, 分布呈负偏态。适用条件:样本含量应大于200
\item
用夏皮罗-威尔克(Shapiro-Wilk)法检验数据正态性
即W检验,1965 年提出,适用于样本含量n ≤50 时的正态性检;。
\item
用达戈斯提诺(D′Agostino)法检验数据正态性
即D检验,1971提出,正态性D检验该方法效率高,是比较精确的正态检验法。
\item
Shapiro-Francia 法
即W′检验,于1972 年提出,适用于50 \textless{} n \textless{} 100 时的正态性检验。
\item
QQ图或PP图
散点聚集在固定直线的周围,可以认为数据资料近似服从正态分布
\end{enumerate}
\textbf{常用的规则}:
\textbf{SPSS 规定}:当样本含量3 ≤n ≤5000 时,结果以Shapiro - Wilk (W 检验) 为难,当样本含量n \textgreater{} 5000 结果以Kolmogorov - Smirnov 为准。
\textbf{SAS 规定}:当样本含量n ≤2000 时,结果以Shapiro - Wilk (W 检验) 为准,当样本含量n \textgreater2000 时,结果以Kolmogorov - Smirnov (D 检验) 为准。
参考:
刘庆武,胡志艳,如何用SPSS、SAS 统计软件进行正态性检验,湘南学院学报(自然科学版),2005
朱红兵,何丽娟,在SPSS10.0 中进行数据资料正态性检验的方法,首都体育学院学报,2004
\hypertarget{ux76f4ux65b9ux56fe}{%
\subsubsection{直方图}\label{ux76f4ux65b9ux56fe}}
直方图显示了分布的分布范围和形状,因此它是评估正态性的一个很好的起点。本文开始测试的红细胞浓度遵循正态曲线,因此数据似乎遵循正态分布。
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{hist}\NormalTok{(RBC_v, }\DataTypeTok{right=}\OtherTok{FALSE}\NormalTok{, }
\DataTypeTok{breaks =}\NormalTok{ breaks, }\DataTypeTok{labels =}\OtherTok{TRUE}\NormalTok{, }
\DataTypeTok{freq =} \OtherTok{FALSE}\NormalTok{, }\DataTypeTok{col =} \StringTok{"#A8D6FF"}\NormalTok{, }
\DataTypeTok{border =} \StringTok{"white"}\NormalTok{, }\DataTypeTok{ylim=}\KeywordTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{,}\DecValTok{1}\NormalTok{))}
\KeywordTok{lines}\NormalTok{(}\KeywordTok{density}\NormalTok{(RBC_v),}\DataTypeTok{col=}\StringTok{"red"}\NormalTok{,}\DataTypeTok{lwd=}\DecValTok{2}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{figure}
{\centering \includegraphics[width=0.49\linewidth,height=0.49\textheight]{image/5ba23e818daa7c71b147707f9b5dfd6}
}
\caption{正态分布检验与直方图}\label{fig:histtest}
\end{figure}
\hypertarget{ux6982ux7387ux5bc6ux5ea6ux56fe}{%
\subsubsection{概率密度图}\label{ux6982ux7387ux5bc6ux5ea6ux56fe}}
概率密度图图提供了关于数据是否服从正态分布的直观判断。它们类似于直方图,因为它们也允许分析分布的传播和形状。但是,它们是直方图的平滑版本。
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{maintxt<-}\KeywordTok{paste}\NormalTok{(}\StringTok{"N="}\NormalTok{,}\KeywordTok{length}\NormalTok{(RBC_v),}\StringTok{","}\NormalTok{,}\StringTok{"Mean="}\NormalTok{,}\KeywordTok{round}\NormalTok{(}\KeywordTok{mean}\NormalTok{(RBC_v),}\DecValTok{3}\NormalTok{),}\StringTok{","}\NormalTok{,}\StringTok{"Sd="}\NormalTok{,}\KeywordTok{round}\NormalTok{(s,}\DecValTok{3}\NormalTok{))}
\KeywordTok{plot}\NormalTok{(}\KeywordTok{density}\NormalTok{(RBC_v),}\DataTypeTok{col=}\StringTok{"red"}\NormalTok{,}\DataTypeTok{lwd=}\DecValTok{2}\NormalTok{,}\DataTypeTok{main =}\NormalTok{ maintxt)}
\end{Highlighting}
\end{Shaded}
\begin{figure}
{\centering \includegraphics[width=0.49\linewidth,height=0.49\textheight]{image/Densitytest}
}
\caption{正态分布检验与密度图}\label{fig:densitytest}
\end{figure}
\hypertarget{qq-plot}{%
\subsubsection{QQ-plot}\label{qq-plot}}
有的数据从直方图和密度图很难检验正态性,因此建议用qq图来确证这些图。QQ-plot,又称正态图。在QQ-plots中,
我们只需要确定数据点是否沿着直线(有时也称为Henry's line),而不是查看数据的扩散情况(如直方图和密度图)。
如果点靠近参考线并且在置信区间内,则认为满足了正态性假设。点与参考线之间的偏差越大,偏离置信区间越远,
满足正态条件的可能性就越小。这12个成年人的身高似乎服从正态分布,因为所有的点都在置信区间内。
如果qq图所示的非正态分布(系统地偏离参考线)时,通常第一步是对数据进行对数变换,
并重新检查对数变换后的数据是否正态分布。可以应用log()函数进行对数变换。
另外,qq图也是评估回归分析的残差是否服从正态分布的一种方便的方法。
\begin{figure}
{\centering \includegraphics[width=0.49\linewidth,height=0.49\textheight]{figs/qqPlottest1}
}
\caption{难以判断正态分布的密度图}\label{fig:qqPlottest1}
\end{figure}
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{#qqPlot是car包中的函数,因此需要载入包,可以使用groups参数,同时对多组数据分别处理}
\KeywordTok{library}\NormalTok{(car)}
\KeywordTok{set.seed}\NormalTok{(}\DecValTok{42}\NormalTok{)}
\NormalTok{dat_hist <-}\StringTok{ }\KeywordTok{data.frame}\NormalTok{( }\DataTypeTok{value =} \KeywordTok{rnorm}\NormalTok{(}\DecValTok{12}\NormalTok{, }\DataTypeTok{mean =} \DecValTok{165}\NormalTok{, }\DataTypeTok{sd =} \DecValTok{5}\NormalTok{))}
\KeywordTok{qqPlot}\NormalTok{(dat_hist}\OperatorTok{$}\NormalTok{value)}
\end{Highlighting}
\end{Shaded}
\begin{figure}
{\centering \includegraphics[width=0.49\linewidth,height=0.49\textheight]{figs/qqplot}
}
\caption{正态分布检验与QQ-plot (1)}\label{fig:qqplot}
\end{figure}
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{library}\NormalTok{(car)}
\KeywordTok{qqPlot}\NormalTok{(}\KeywordTok{as.numeric}\NormalTok{(RBC_v),}\DataTypeTok{ylab=}\StringTok{"RBC"}\NormalTok{, }\DataTypeTok{main=}\StringTok{"RBC QQ-plot"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{figure}
{\centering \includegraphics[width=0.49\linewidth,height=0.49\textheight]{image/qqPlot}
}
\caption{正态分布检验与QQ-plot (2)}\label{fig:qqplot1}
\end{figure}
\hypertarget{ux6b63ux6001ux68c0ux9a8c}{%
\subsubsection{正态检验}\label{ux6b63ux6001ux68c0ux9a8c}}
上述3种方法是对常态的目视检查。然而,目测有时可能不可靠,因此也有可能通过统计检验正式检验数据是否服从正态分布。
这些正态性检验将数据的分布与正态分布进行比较,以评估观察结果是否显示出偏离正态性的重要偏差。
最常用的两种正态性检验是Shapiro-Wilk检验(K检验)和Kolmogorov-Smirnov检验(D检验)。两种测试都有相同的假设,即:
\textbf{\emph{H0}} : 数据服从正态分布
\textbf{\emph{H1}} : 数据不服从正态分布
正态性检验推荐使用Shapiro-Wilk检验,因为它比Kolmogorov-Smirnov检验提供更好的效用。
在R中,正态性的Shapiro-Wilk检验可以通过函数shapiro.test()进行。
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{set.seed}\NormalTok{(}\DecValTok{42}\NormalTok{)}
\NormalTok{dat_hist <-}\StringTok{ }\KeywordTok{data.frame}\NormalTok{( }\DataTypeTok{value =} \KeywordTok{rnorm}\NormalTok{(}\DecValTok{12}\NormalTok{, }\DataTypeTok{mean =} \DecValTok{165}\NormalTok{, }\DataTypeTok{sd =} \DecValTok{5}\NormalTok{))}
\KeywordTok{shapiro.test}\NormalTok{(dat_hist}\OperatorTok{$}\NormalTok{value)}
\CommentTok{## Shapiro-Wilk normality test}
\CommentTok{## }
\CommentTok{## data: dat_hist$value}
\CommentTok{## W = 0.9, p-value = 0.5}
\end{Highlighting}
\end{Shaded}
从输出中,我们看到p-value\textgreater0.05意味着我们不拒绝数据服从正态分布的原假设。
该检验与qq图的方向相同,qq图与正态性没有显著偏差(因为所有点都在置信区间内)。
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{shapiro.test}\NormalTok{(RBC_v)}
\CommentTok{## Shapiro-Wilk normality test}
\CommentTok{## }
\CommentTok{## data: as.numeric(RBC_v)}
\CommentTok{## W = 1, p-value = 0.4}
\end{Highlighting}
\end{Shaded}
对RBC数据同样的结果。
注意的是,在实践中,正态检验通常被认为过于保守,因为对于大样本(n\textgreater50),对正态条件的一个
小偏差可能会导致违反正态判断的条件。由于正态性检验是一种假设检验,所以随着样本量的增加,其检测较小差
异的能力也会增加。因此,随着观测数的增加,Shapiro-Wilk检验变得非常敏感,甚至对正态性的一个
微小偏差也非常敏感。所以,根据正态性检验,数据不服从正态分布,尽管偏离正态分布的情况可以忽略不计,但数据
实际上服从正态分布。因此,通常情况下,正态性条件的验证是基于本文所介绍的所有方法的组合,即目视检验
(使用直方图和q-q图)和正式化检验(例如使用shapio-wilk检验)。
R中还有其他一些正态检验的方法,比如 ks.test() 函数实现Kolmogorov-Smirnov Test(D检验),
是对经验分布的拟合检验,检验的是经验分布函数和假设总体分布函数的差异,适应于大样本(n\textgreater5000)。
另外有一些package包含了丰富的检验函数,比如fBasics,nortest等。
\hypertarget{ux7b2cux4e09ux7ae0-ux603bux4f53ux5747ux6570ux7684ux4f30ux8ba1ux4e0eux5047ux8bbeux68c0ux9a8c}{%
\section{第三章 总体均数的估计与假设检验}\label{ux7b2cux4e09ux7ae0-ux603bux4f53ux5747ux6570ux7684ux4f30ux8ba1ux4e0eux5047ux8bbeux68c0ux9a8c}}
日期: 2020-11-14
作者:wxhyihuan
\hypertarget{ux63a8ux8bbaux7edfux8ba1}{%
\subsection{推论统计}\label{ux63a8ux8bbaux7edfux8ba1}}
推论统计(或称统计推断,Statistical inference),指统计学中,研究如何根据样本数据去推断总体数量特征的方法。
它是在对样本数据进行描述的基础上,对统计总体的未知数量特征做出以概率形式表述的推断。更概括地说,
是在一段有限的时间内,通过对一个随机过程的观察来进行推断的。统计学中,统计推断与描述统计相对应。
推论统计(Statistical inferences)是借助抽样调查,从局部推断总体,以对不肯定的事物做出决策的一种统计。
有总体\emph{参数估计}与\emph{假设检验}两种。前者以一次性抽样实验为依据,对整个总体的某个数字特征做出估计。后者则是对
某种假设进行检验,根据计算结果推断所做的假设是否可以接受。如平均数、标准差、相关系数、回归系数等特征的
总体估计及差异显著性检验。推断统计的理论基础是概率论,它更多地需要借助抽样理论与方法。
\hypertarget{ux53c2ux6570ux4f30ux8ba1ux4e0eux5047ux8bbeux68c0ux9a8c}{%
\subsubsection{参数估计与假设检验}\label{ux53c2ux6570ux4f30ux8ba1ux4e0eux5047ux8bbeux68c0ux9a8c}}
参数估计背后的思想是通过对从总体中抽取的样本进行统计显著性检验(如t检验),为研究人员提供关于总体的统计推断。
最常用的就是t检验,其参数检验是基于W.S.Gosset的t统计量,该统计数据假设变量来自正态总体。t检验统计量中的总体均值是已知的。
这种分布称为t分布,其形状与正态分布类似,即钟形曲线。t检验用于检验那些样本小于30的样本比正态分布要好,
在大样本上做的和正态分布一样好。
假设检验(Hypothesis test)过去也叫做显著性检验(Significance test),是利用小概率反证法思想,从问题的对立面(\(H_0\))出发,
间接判断解决问题(\(H_1\))是否成立。即在假设\(H_0\)成立的条件下,计算检验统计量(Test static),然后根据\(P\)值(P-value)来判断。
\hypertarget{ux7edfux8ba1ux91cfux4e0eux6807ux51c6ux8bef}{%
\subsubsection{统计量与标准误}\label{ux7edfux8ba1ux91cfux4e0eux6807ux51c6ux8bef}}
样本是总体的代表和反映,也是统计推断的依据,为了对总体的分布或数字特征进行各种统计推断,还需要对样本作加工处理,
把样本中应关心的事物和信息集中起来,针对不同的问题构造出样本的不同函数(如均值,方差,极差,标准差,中位数,众数等),这种样本的函数我们称其为统计量。
样本统计量的标准差即为标准误(Stand error,SE),反映了抽样的统计量的离散程度或误差大小。如样本均数的标准差也称为均数标准误
(Stand error of mean, SEM),反映了样本均数的离散程度。
\hypertarget{t-ux5206ux5e03}{%
\subsection{\texorpdfstring{\emph{t} 分布}{t 分布}}\label{t-ux5206ux5e03}}
若某一随机变量\emph{X}服从总体均数为\emph{μ},总体标标准差为\emph{σ}的正态分布\(N(μ,σ^2)\),通过\emph{u}变换(也称Z变换)可将一般正态分布
转化为标准正态分布\(N(0,1^2)\),即u分布(也称Z分布)。同理,若样本含量为n的样本均数 \(\bar{X}\) 服从总体均数为\emph{μ},
总体标准差为\(σ_\bar{x}\)的正态分布\(N(μ,σ_\bar{x}^2)\),则可通过\emph{u}变换(\(\frac{\bar{X}-μ}{σ_\bar{x}}\))将其转换为标准正态分布。
但是,实际中总体标准差(\(σ_\bar{x}\))是未知的,所以用均数标准误的估计值(\(S_\bar{x}=\frac{S}{\sqrt{n}}\),其中S为样本标准差)代替,
这就使得(\(\frac{\bar{X}-μ}{S_\bar{x}}\))不再是标准正态分布,而是服从t-分布(t-distribution),
即:
\[t=\frac{\bar{X}-μ}{S_\bar{x}}=\frac{\bar{X}-μ}{\frac{S}{\sqrt{n}}}\]
t-分布 对应的概率密度函数是:
\[f(x)=\frac{\Gamma(\frac{v+1}{2})}{\sqrt{v\pi}\Gamma(\frac{v}{2})}{\left(1+\frac{x^2}{v}\right)^\frac{-v+1}{2}}\]
其中\(\Gamma\)是伽马函数(Gamma function),\(v\)是自由度(Degree of freedom,df)。
\textbf{自由度(df)}在数学上只能自由取值的变量个数,如\(X+Y+Z=1\),有3个变量,但是能够自由取值的自由两个,故其自由度\(v=2\)。
在统计学中,自由度计算方式为:
\[v=n-m\]
其中\emph{n}为计算某一统计量是用到的数据个数,\emph{m}为计算该统计量是用到的其他独立统计量个数。比如根据肿瘤位置,大小,组织活检,生化指标
判断肿瘤的类型是A,也可能是B,这里有\(n=4\)个独立的信息,和\(m=2\)个估计,所以自由度就是\(df=4-2=2\)。一般的希望估计(推测)的越可靠,
当然是自由度越大越好了。
t分布是一簇曲线,其形态变化与n(即其自由度)大小有关。自由度n越小,t分布曲线越低平;自由度n越大,t分布曲线越接近标准正态分布(u分布)
曲线,当自由度无限大时,t分布就成了正态分布。
\hypertarget{ux6982ux7387ux5bc6ux5ea6ux51fdux6570dt}{%
\subsubsection{概率密度函数dt()}\label{ux6982ux7387ux5bc6ux5ea6ux51fdux6570dt}}
R中,t分布的概率密度函数为dt(),它可以给出了指定均值和标准差下每个点的概率分布的高度,
越高就代表着这个点/区间的概率越密集(大)。从下免得概率密度图见,当df=20时,t分布曲线已经非常接近标准正态曲线了。
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{curve}\NormalTok{(}\KeywordTok{dnorm}\NormalTok{(x),}\DataTypeTok{xlim=}\KeywordTok{c}\NormalTok{(}\OperatorTok{-}\DecValTok{5}\NormalTok{,}\DecValTok{5}\NormalTok{),}\DataTypeTok{ylim=}\KeywordTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{,}\FloatTok{0.45}\NormalTok{),}\DataTypeTok{ylab=}\StringTok{"Student's t Density"}\NormalTok{,}\DataTypeTok{col=}\StringTok{"red"}\NormalTok{,}\DataTypeTok{lty=}\DecValTok{1}\NormalTok{,}\DataTypeTok{lwd=}\DecValTok{2}\NormalTok{)}
\KeywordTok{abline}\NormalTok{(}\DataTypeTok{v=}\DecValTok{0}\NormalTok{,}\DataTypeTok{lwd=}\DecValTok{1}\NormalTok{,}\DataTypeTok{col=}\StringTok{"black"}\NormalTok{)}
\KeywordTok{curve}\NormalTok{(}\KeywordTok{dt}\NormalTok{(x,}\DecValTok{1}\NormalTok{),}\DataTypeTok{col=}\StringTok{"green"}\NormalTok{,}\DataTypeTok{lty=}\DecValTok{2}\NormalTok{,}\DataTypeTok{add=}\OtherTok{TRUE}\NormalTok{)}
\KeywordTok{curve}\NormalTok{(}\KeywordTok{dt}\NormalTok{(x,}\DecValTok{2}\NormalTok{),}\DataTypeTok{col=}\StringTok{"brown"}\NormalTok{,}\DataTypeTok{lty=}\DecValTok{3}\NormalTok{,}\DataTypeTok{add=}\OtherTok{TRUE}\NormalTok{)}
\KeywordTok{curve}\NormalTok{(}\KeywordTok{dt}\NormalTok{(x,}\DecValTok{5}\NormalTok{),}\DataTypeTok{col=}\StringTok{"blue"}\NormalTok{,}\DataTypeTok{lty=}\DecValTok{4}\NormalTok{,}\DataTypeTok{add=}\OtherTok{TRUE}\NormalTok{)}
\KeywordTok{curve}\NormalTok{(}\KeywordTok{dt}\NormalTok{(x,}\DecValTok{20}\NormalTok{),}\DataTypeTok{col=}\StringTok{"dark green"}\NormalTok{,}\DataTypeTok{lty=}\DecValTok{5}\NormalTok{,}\DataTypeTok{add=}\OtherTok{TRUE}\NormalTok{)}
\KeywordTok{legend}\NormalTok{(}\DecValTok{2}\NormalTok{,}\FloatTok{0.38}\NormalTok{,}\KeywordTok{c}\NormalTok{(}\StringTok{"normal"}\NormalTok{,}\StringTok{"df=1"}\NormalTok{,}\StringTok{"df=2"}\NormalTok{,}\StringTok{"df=5"}\NormalTok{,}\StringTok{"df=20"}\NormalTok{),}
\DataTypeTok{col=}\KeywordTok{c}\NormalTok{(}\StringTok{"red"}\NormalTok{,}\StringTok{"green"}\NormalTok{,}\StringTok{"brown"}\NormalTok{,}\StringTok{"blue"}\NormalTok{,}\StringTok{"dark green"}\NormalTok{),}\DataTypeTok{lty=}\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{figure}
{\centering \includegraphics[width=0.49\linewidth,height=0.49\textheight]{figs/tdist}
}
\caption{t分布检验与正态分布}\label{fig:tdist}
\end{figure}
\hypertarget{ux6982ux7387ux7d2fux79efux5206ux5e03ux51fdux6570pt}{%
\subsubsection{概率累积分布函数pt()}\label{ux6982ux7387ux7d2fux79efux5206ux5e03ux51fdux6570pt}}
同所有连续数值型分布一样,统计应用中最关心的是分布曲线下的尾部面积(即概率\(P\)或α)与横轴间的关系。
R中即为pt(),它给出一个正态分布中小于一个给定数字的累计概率(即指定定点的左边范围的曲线面积)。
一侧尾部面积称为单侧概率或单尾概率(one-tailed probability,\(t_{α,v}\)),两侧尾部的面积之和称为双侧概率或双尾概率
(two-tailes probability,\(t_{α/2,v}\))。
\textbf{单侧的p值计算}
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{# t-stat=1.9, df=5}
\CommentTok{# 单侧 p值}
\CommentTok{# P(t => 1.9)}
\KeywordTok{pt}\NormalTok{(}\DataTypeTok{q=}\FloatTok{1.9}\NormalTok{, }\DataTypeTok{df=}\DecValTok{5}\NormalTok{, }\DataTypeTok{lower.tail =}\NormalTok{ F)}
\CommentTok{## [1] 0.05793165}
\end{Highlighting}
\end{Shaded}
\textbf{双侧的p值计算}
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{## 双侧 p-value}
\CommentTok{## 两边对称单侧相加}