Visual Statistics - cran.r-project.org

Visual Statistics

Use R!

Alexey Shipunov

TONGUE

¡ñ

PEAK

EARLOBE

¡ñ

TOE

¡ñ

¡ñ

¡ñ

¡ñ

PINKY

¡ñ

THUMB

ARM

¡ñ

CHIN

¡ñ

CHEEK

March 13, 2019 version

Shipunov, Alexey (and many others). Visual statistics. Use R!

March 13, 2019 version. 429 pp.

URL:

On the cover: R plot illustrating correlations between human phenotypic traits. See

the page 254 for more explanation.

This book is dedicated to the public domain

Contents

Foreword

I

9

One or two dimensions

13

1 The data

1.1 Origin of the data . . . . . . . . . . . . . .

1.2 Population and sample . . . . . . . . . . .

1.3 How to obtain the data . . . . . . . . . . .

1.4 What to ?nd in the data . . . . . . . . . .

1.4.1 Why do we need the data analysis

1.4.2 What data analysis can do . . . . .

1.4.3 What data analysis cannot do . . .

1.5 Answers to exercises . . . . . . . . . . . .

.

.

.

.

.

.

.

.

2 How to process the data

2.1 General purpose software . . . . . . . . . .

2.2 Statistical software . . . . . . . . . . . . . .

2.2.1 Graphical systems . . . . . . . . . .

2.2.2 Statistical environments . . . . . . .

2.3 The very short history of the S and R . . . .

2.4 Use, advantages and disadvantages of the R

2.5 How to download and install R . . . . . . .

2.6 How to start with R . . . . . . . . . . . . . .

2.6.1 Launching R . . . . . . . . . . . . .

2.6.2 First steps . . . . . . . . . . . . . . .

2.6.3 How to type . . . . . . . . . . . . . .

2.6.4 How to play with R . . . . . . . . . .

2.6.5 Overgrown calculator . . . . . . . .

2.7 R and data . . . . . . . . . . . . . . . . . . .

3

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

14

14

14

15

17

17

17

18

19

.

.

.

.

.

.

.

.

.

.

.

.

.

.

20

20

21

21

21

22

22

23

25

25

25

28

30

31

33

2.7.1 How to enter the data from within R

2.7.2 How to name your objects . . . . . .

2.7.3 How to load the text data . . . . . .

2.7.4 How to load data from Internet . . .

2.7.5 How to use read.table() . . . . . .

2.7.6 How to load binary data . . . . . . .

2.7.7 How to load data from clipboard . .

2.7.8 How to edit data in R . . . . . . . . .

2.7.9 How to save the results . . . . . . .

2.7.10 History and scripts . . . . . . . . . .

2.8 R graphics . . . . . . . . . . . . . . . . . . .

2.8.1 Graphical systems . . . . . . . . . .

2.8.2 Graphical devices . . . . . . . . . . .

2.8.3 Graphical options . . . . . . . . . .

2.8.4 Interactive graphics . . . . . . . . .

2.9 Answers to exercises . . . . . . . . . . . . .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3 Types of data

3.1 Degrees, hours and kilometers: measurement data

3.2 Grades and t-shirts: ranked data . . . . . . . . . .

3.3 Colors, names and sexes: nominal data . . . . . .

3.3.1 Character vectors . . . . . . . . . . . . . . .

3.3.2 Factors . . . . . . . . . . . . . . . . . . . .

3.3.3 Logical vectors and binary data . . . . . . .

3.4 Fractions, counts and ranks: secondary data . . . .

3.5 Missing data . . . . . . . . . . . . . . . . . . . . .

3.6 Outliers, and how to ?nd them . . . . . . . . . . .

3.7 Changing data: basics of transformations . . . . .

3.7.1 How to tell the kind of data . . . . . . . . .

3.8 Inside R . . . . . . . . . . . . . . . . . . . . . . . .

3.8.1 Matrices . . . . . . . . . . . . . . . . . . . .

3.8.2 Lists . . . . . . . . . . . . . . . . . . . . . .

3.8.3 Data frames . . . . . . . . . . . . . . . . . .

3.8.4 Overview of data types and modes . . . . .

3.9 Answers to exercises . . . . . . . . . . . . . . . . .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

62

. 62

. 68

. 70

. 70

. 71

. 76

. 79

. 84

. 86

. 87

. 89

. 89

. 89

. 93

. 96

. 103

. 106

4 One-dimensional data

4.1 How to estimate general tendencies

4.1.1 Median is the best . . . . . .

4.1.2 Quartiles and quantiles . . .

4.1.3 Variation . . . . . . . . . . .

4.2 1-dimensional plots . . . . . . . . .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

4

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

33

34

35

38

38

40

41

42

42

44

45

45

52

54

55

56

110

110

110

112

114

117

4.3

4.4

4.5

4.6

4.7

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

123

127

129

131

134

5 Two-dimensional data: differences

5.1 What is a statistical test? . . . . . . . . . . .

5.1.1 Statistical hypotheses . . . . . . . . .

5.1.2 Statistical errors . . . . . . . . . . . .

5.2 Is there a difference? Comparing two samples

5.2.1 Two sample tests . . . . . . . . . . . .

5.2.2 Effect sizes . . . . . . . . . . . . . . .

5.3 If there are more than two samples: ANOVA .

5.3.1 One way . . . . . . . . . . . . . . . . .

5.3.2 More then one way . . . . . . . . . . .

5.4 Is there an association? Analysis of tables . .

5.4.1 Contingency tables . . . . . . . . . . .

5.4.2 Table tests . . . . . . . . . . . . . . .

5.5 Answers to exercises . . . . . . . . . . . . . .

5.5.1 Two sample tests, effect sizes . . . . .

5.5.2 ANOVA . . . . . . . . . . . . . . . . .

5.5.3 Contingency tables . . . . . . . . . . .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

147

147

148

148

150

150

165

168

168

181

183

183

188

199

199

206

210

6 Two-dimensional data: models

6.1 Analysis of correlation . . . . . . . . . . . . .

6.1.1 Plot it ?rst . . . . . . . . . . . . . . .

6.1.2 Correlation . . . . . . . . . . . . . . .

6.2 Analysis of regression . . . . . . . . . . . . .

6.2.1 Single line . . . . . . . . . . . . . . .

6.2.2 Many lines . . . . . . . . . . . . . . .

6.2.3 More then one way, again . . . . . . .

6.3 Probability of the success: logistic regression

6.4 Answers to exercises . . . . . . . . . . . . . .

6.4.1 Correlation and linear models . . . . .

6.4.2 Logistic regression . . . . . . . . . . .

6.5 How to choose the right method . . . . . . .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

220

220

221

223

229

229

241

247

249

253

253

265

271

II

Con?dence intervals . . . . . . . .

Normality . . . . . . . . . . . . . .

How to create your own functions

How good is the proportion? . . .

Answers to exercises . . . . . . . .

Many dimensions

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

273

7 Draw

274

5

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download