-
Notifications
You must be signed in to change notification settings - Fork 0
/
pca.html
447 lines (406 loc) · 41.5 KB
/
pca.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
<!DOCTYPE html>
<html lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Chapter 4 Principal Component Analysis | Multivariate Statistical Analysis Cookbook with R</title>
<meta name="description" content="This is a final cookbook of Multivariate Statistical Analysis" />
<meta name="generator" content="bookdown 0.21 and GitBook 2.6.7" />
<meta property="og:title" content="Chapter 4 Principal Component Analysis | Multivariate Statistical Analysis Cookbook with R" />
<meta property="og:type" content="book" />
<meta property="og:description" content="This is a final cookbook of Multivariate Statistical Analysis" />
<meta name="github-repo" content="rstudio/bookdown-demo" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="Chapter 4 Principal Component Analysis | Multivariate Statistical Analysis Cookbook with R" />
<meta name="twitter:description" content="This is a final cookbook of Multivariate Statistical Analysis" />
<meta name="author" content="Yile Wang" />
<meta name="date" content="2020-12-10" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="prev" href="Data-Intro.html"/>
<link rel="next" href="ca.html"/>
<script src="libs/jquery-2.2.3/jquery.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-table.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-clipboard.css" rel="stylesheet" />
<script src="libs/accessible-code-block-0.0.1/empty-anchor.js"></script>
<link href="libs/anchor-sections-1.0/anchor-sections.css" rel="stylesheet" />
<script src="libs/anchor-sections-1.0/anchor-sections.js"></script>
<style type="text/css">
code.sourceCode > span { display: inline-block; line-height: 1.25; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode { white-space: pre; position: relative; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
code.sourceCode { white-space: pre-wrap; }
code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">
<div class="book-summary">
<nav role="navigation">
<ul class="summary">
<li><a href="./">MSA</a></li>
<li class="divider"></li>
<li class="chapter" data-level="1" data-path="intro.html"><a href="intro.html"><i class="fa fa-check"></i><b>1</b> Introduction</a><ul>
<li class="chapter" data-level="1.1" data-path="intro.html"><a href="intro.html#main-packages"><i class="fa fa-check"></i><b>1.1</b> Main Packages</a></li>
<li class="chapter" data-level="1.2" data-path="intro.html"><a href="intro.html#msa-introduction"><i class="fa fa-check"></i><b>1.2</b> MSA Introduction</a></li>
<li class="chapter" data-level="1.3" data-path="intro.html"><a href="intro.html#msadata"><i class="fa fa-check"></i><b>1.3</b> MSA data set</a></li>
<li class="chapter" data-level="1.4" data-path="intro.html"><a href="intro.html#whoo-hoo"><i class="fa fa-check"></i><b>1.4</b> Whoo-hoo!</a></li>
</ul></li>
<li class="chapter" data-level="2" data-path="Functions.html"><a href="Functions.html"><i class="fa fa-check"></i><b>2</b> Functions Introduction</a><ul>
<li class="chapter" data-level="2.1" data-path="Functions.html"><a href="Functions.html#Scree"><i class="fa fa-check"></i><b>2.1</b> Plotting Scree plot</a></li>
<li class="chapter" data-level="2.2" data-path="Functions.html"><a href="Functions.html#Permutation"><i class="fa fa-check"></i><b>2.2</b> Plotting Permutation test results</a></li>
<li class="chapter" data-level="2.3" data-path="Functions.html"><a href="Functions.html#Heatmap"><i class="fa fa-check"></i><b>2.3</b> Plotting Heatmap</a></li>
<li class="chapter" data-level="2.4" data-path="Functions.html"><a href="Functions.html#FactorScores"><i class="fa fa-check"></i><b>2.4</b> Plotting Row Factor Scores</a></li>
<li class="chapter" data-level="2.5" data-path="Functions.html"><a href="Functions.html#CFactorScore"><i class="fa fa-check"></i><b>2.5</b> Plotting Column Plot</a></li>
<li class="chapter" data-level="2.6" data-path="Functions.html"><a href="Functions.html#Loading"><i class="fa fa-check"></i><b>2.6</b> Plotting Loading Plot</a></li>
<li class="chapter" data-level="2.7" data-path="Functions.html"><a href="Functions.html#Contribution"><i class="fa fa-check"></i><b>2.7</b> Plotting Contribution Barplot</a></li>
<li class="chapter" data-level="2.8" data-path="Functions.html"><a href="Functions.html#binshelper"><i class="fa fa-check"></i><b>2.8</b> Bins Helper Functions</a></li>
<li class="chapter" data-level="2.9" data-path="Functions.html"><a href="Functions.html#plotting-latent-variable-plot"><i class="fa fa-check"></i><b>2.9</b> Plotting Latent Variable Plot</a></li>
<li class="chapter" data-level="2.10" data-path="Functions.html"><a href="Functions.html#plotting-partial-factor-scores"><i class="fa fa-check"></i><b>2.10</b> Plotting Partial Factor Scores</a></li>
</ul></li>
<li class="chapter" data-level="3" data-path="Data-Intro.html"><a href="Data-Intro.html"><i class="fa fa-check"></i><b>3</b> Data Introduction</a><ul>
<li class="chapter" data-level="3.1" data-path="Data-Intro.html"><a href="Data-Intro.html#collect"><i class="fa fa-check"></i><b>3.1</b> Main data set: Collective Action Data Set</a></li>
<li class="chapter" data-level="3.2" data-path="Data-Intro.html"><a href="Data-Intro.html#sausage"><i class="fa fa-check"></i><b>3.2</b> Low Income Sausage</a></li>
<li class="chapter" data-level="3.3" data-path="Data-Intro.html"><a href="Data-Intro.html#wines"><i class="fa fa-check"></i><b>3.3</b> Wines</a></li>
</ul></li>
<li class="chapter" data-level="4" data-path="pca.html"><a href="pca.html"><i class="fa fa-check"></i><b>4</b> Principal Component Analysis</a><ul>
<li class="chapter" data-level="4.1" data-path="pca.html"><a href="pca.html#introduction-of-pca"><i class="fa fa-check"></i><b>4.1</b> Introduction of PCA</a></li>
<li class="chapter" data-level="4.2" data-path="pca.html"><a href="pca.html#computing"><i class="fa fa-check"></i><b>4.2</b> Computing</a></li>
<li class="chapter" data-level="4.3" data-path="pca.html"><a href="pca.html#heatmap"><i class="fa fa-check"></i><b>4.3</b> Heatmap</a></li>
<li class="chapter" data-level="4.4" data-path="pca.html"><a href="pca.html#pcaScree"><i class="fa fa-check"></i><b>4.4</b> Scree Plot</a></li>
<li class="chapter" data-level="4.5" data-path="pca.html"><a href="pca.html#factor-scores"><i class="fa fa-check"></i><b>4.5</b> Factor Scores</a></li>
<li class="chapter" data-level="4.6" data-path="pca.html"><a href="pca.html#loading"><i class="fa fa-check"></i><b>4.6</b> Loading</a></li>
<li class="chapter" data-level="4.7" data-path="pca.html"><a href="pca.html#contriution-and-bootstrap-ratio-barplots"><i class="fa fa-check"></i><b>4.7</b> Contriution and Bootstrap Ratio Barplots</a></li>
<li class="chapter" data-level="4.8" data-path="pca.html"><a href="pca.html#conclusion"><i class="fa fa-check"></i><b>4.8</b> Conclusion</a></li>
</ul></li>
<li class="chapter" data-level="5" data-path="ca.html"><a href="ca.html"><i class="fa fa-check"></i><b>5</b> Correspondence Analysis</a><ul>
<li class="chapter" data-level="5.1" data-path="ca.html"><a href="ca.html#introduction-of-ca"><i class="fa fa-check"></i><b>5.1</b> Introduction of CA</a></li>
<li class="chapter" data-level="5.2" data-path="ca.html"><a href="ca.html#computation"><i class="fa fa-check"></i><b>5.2</b> Computation</a></li>
<li class="chapter" data-level="5.3" data-path="ca.html"><a href="ca.html#heatmap-1"><i class="fa fa-check"></i><b>5.3</b> Heatmap</a></li>
<li class="chapter" data-level="5.4" data-path="ca.html"><a href="ca.html#computation-1"><i class="fa fa-check"></i><b>5.4</b> Computation</a></li>
<li class="chapter" data-level="5.5" data-path="ca.html"><a href="ca.html#scree-plot"><i class="fa fa-check"></i><b>5.5</b> Scree Plot</a></li>
<li class="chapter" data-level="5.6" data-path="ca.html"><a href="ca.html#symmetric-asymmetric-plots"><i class="fa fa-check"></i><b>5.6</b> Symmetric & Asymmetric Plots</a></li>
<li class="chapter" data-level="5.7" data-path="ca.html"><a href="ca.html#contribution-and-bootstrap-ratio-barplot"><i class="fa fa-check"></i><b>5.7</b> Contribution and Bootstrap Ratio Barplot</a></li>
</ul></li>
<li class="chapter" data-level="6" data-path="dica.html"><a href="dica.html"><i class="fa fa-check"></i><b>6</b> Discriminant Correspondence Analysis</a><ul>
<li class="chapter" data-level="6.1" data-path="dica.html"><a href="dica.html#introdcution-of-dica"><i class="fa fa-check"></i><b>6.1</b> Introdcution of DiCA</a></li>
<li class="chapter" data-level="6.2" data-path="dica.html"><a href="dica.html#histgram-of-binning-variables"><i class="fa fa-check"></i><b>6.2</b> Histgram of Binning Variables</a></li>
<li class="chapter" data-level="6.3" data-path="dica.html"><a href="dica.html#heatmap-2"><i class="fa fa-check"></i><b>6.3</b> Heatmap</a></li>
<li class="chapter" data-level="6.4" data-path="dica.html"><a href="dica.html#scree-plot-1"><i class="fa fa-check"></i><b>6.4</b> Scree Plot</a></li>
<li class="chapter" data-level="6.5" data-path="dica.html"><a href="dica.html#factor-scores-1"><i class="fa fa-check"></i><b>6.5</b> Factor Scores</a></li>
<li class="chapter" data-level="6.6" data-path="dica.html"><a href="dica.html#confusion-matrix"><i class="fa fa-check"></i><b>6.6</b> Confusion Matrix</a></li>
<li class="chapter" data-level="6.7" data-path="dica.html"><a href="dica.html#contribution-and-bootstrap-ratio-barplots"><i class="fa fa-check"></i><b>6.7</b> Contribution and Bootstrap Ratio Barplots</a></li>
</ul></li>
<li class="chapter" data-level="7" data-path="bada.html"><a href="bada.html"><i class="fa fa-check"></i><b>7</b> Barycentric Discriminant Analysis</a><ul>
<li class="chapter" data-level="7.1" data-path="bada.html"><a href="bada.html#introduction-of-bada"><i class="fa fa-check"></i><b>7.1</b> Introduction of BADA</a></li>
<li class="chapter" data-level="7.2" data-path="bada.html"><a href="bada.html#computation-2"><i class="fa fa-check"></i><b>7.2</b> Computation</a></li>
<li class="chapter" data-level="7.3" data-path="bada.html"><a href="bada.html#heatmap-3"><i class="fa fa-check"></i><b>7.3</b> Heatmap</a></li>
<li class="chapter" data-level="7.4" data-path="bada.html"><a href="bada.html#scree"><i class="fa fa-check"></i><b>7.4</b> Scree</a></li>
<li class="chapter" data-level="7.5" data-path="bada.html"><a href="bada.html#factor-scores-2"><i class="fa fa-check"></i><b>7.5</b> Factor Scores</a></li>
<li class="chapter" data-level="7.6" data-path="bada.html"><a href="bada.html#loading-1"><i class="fa fa-check"></i><b>7.6</b> Loading</a></li>
<li class="chapter" data-level="7.7" data-path="bada.html"><a href="bada.html#confusion-matrix-1"><i class="fa fa-check"></i><b>7.7</b> Confusion Matrix</a></li>
<li class="chapter" data-level="7.8" data-path="bada.html"><a href="bada.html#contribution-and-bootstrap-ratio-barplot-1"><i class="fa fa-check"></i><b>7.8</b> Contribution and Bootstrap Ratio Barplot</a></li>
</ul></li>
<li class="chapter" data-level="8" data-path="mca.html"><a href="mca.html"><i class="fa fa-check"></i><b>8</b> Multiple Corresponding Analysis</a><ul>
<li class="chapter" data-level="8.1" data-path="mca.html"><a href="mca.html#introduction-of-mca"><i class="fa fa-check"></i><b>8.1</b> Introduction of MCA</a></li>
<li class="chapter" data-level="8.2" data-path="mca.html"><a href="mca.html#histgram-of-binning-variables-1"><i class="fa fa-check"></i><b>8.2</b> Histgram of Binning Variables</a></li>
<li class="chapter" data-level="8.3" data-path="mca.html"><a href="mca.html#computation-3"><i class="fa fa-check"></i><b>8.3</b> Computation</a></li>
<li class="chapter" data-level="8.4" data-path="mca.html"><a href="mca.html#heatmap-4"><i class="fa fa-check"></i><b>8.4</b> Heatmap</a></li>
<li class="chapter" data-level="8.5" data-path="mca.html"><a href="mca.html#scree-plot-2"><i class="fa fa-check"></i><b>8.5</b> Scree Plot</a></li>
<li class="chapter" data-level="8.6" data-path="mca.html"><a href="mca.html#row-factor-scores"><i class="fa fa-check"></i><b>8.6</b> Row Factor Scores</a></li>
<li class="chapter" data-level="8.7" data-path="mca.html"><a href="mca.html#important-variables-line-plots"><i class="fa fa-check"></i><b>8.7</b> Important Variables Line Plots</a></li>
<li class="chapter" data-level="8.8" data-path="mca.html"><a href="mca.html#contribution-and-bootstrap-ratio-barplots-1"><i class="fa fa-check"></i><b>8.8</b> Contribution and Bootstrap Ratio Barplots</a></li>
</ul></li>
<li class="chapter" data-level="9" data-path="pls.html"><a href="pls.html"><i class="fa fa-check"></i><b>9</b> Partial Least Square</a><ul>
<li class="chapter" data-level="9.1" data-path="pls.html"><a href="pls.html#introduction-of-pls-c"><i class="fa fa-check"></i><b>9.1</b> Introduction of PLS-C</a></li>
<li class="chapter" data-level="9.2" data-path="pls.html"><a href="pls.html#computation-4"><i class="fa fa-check"></i><b>9.2</b> Computation</a></li>
<li class="chapter" data-level="9.3" data-path="pls.html"><a href="pls.html#heatmap-5"><i class="fa fa-check"></i><b>9.3</b> Heatmap</a></li>
<li class="chapter" data-level="9.4" data-path="pls.html"><a href="pls.html#scree-plot-3"><i class="fa fa-check"></i><b>9.4</b> Scree Plot</a></li>
<li class="chapter" data-level="9.5" data-path="pls.html"><a href="pls.html#latent-variables"><i class="fa fa-check"></i><b>9.5</b> Latent Variables</a></li>
<li class="chapter" data-level="9.6" data-path="pls.html"><a href="pls.html#salience"><i class="fa fa-check"></i><b>9.6</b> Salience</a></li>
<li class="chapter" data-level="9.7" data-path="pls.html"><a href="pls.html#bootstrap-ratio-barplot"><i class="fa fa-check"></i><b>9.7</b> Bootstrap Ratio Barplot</a></li>
</ul></li>
<li class="chapter" data-level="10" data-path="distatis.html"><a href="distatis.html"><i class="fa fa-check"></i><b>10</b> DiSTATIS</a><ul>
<li class="chapter" data-level="10.1" data-path="distatis.html"><a href="distatis.html#introduction-of-distatis"><i class="fa fa-check"></i><b>10.1</b> Introduction of DiSTATIS</a></li>
<li class="chapter" data-level="10.2" data-path="distatis.html"><a href="distatis.html#computation-5"><i class="fa fa-check"></i><b>10.2</b> Computation</a></li>
<li class="chapter" data-level="10.3" data-path="distatis.html"><a href="distatis.html#heatmap-6"><i class="fa fa-check"></i><b>10.3</b> HeatMap</a></li>
<li class="chapter" data-level="10.4" data-path="distatis.html"><a href="distatis.html#scree-plot-4"><i class="fa fa-check"></i><b>10.4</b> Scree Plot</a></li>
<li class="chapter" data-level="10.5" data-path="distatis.html"><a href="distatis.html#global-factor-scores"><i class="fa fa-check"></i><b>10.5</b> Global Factor Scores</a></li>
<li class="chapter" data-level="10.6" data-path="distatis.html"><a href="distatis.html#partial-factor-scores"><i class="fa fa-check"></i><b>10.6</b> Partial Factor Scores</a></li>
<li class="chapter" data-level="10.7" data-path="distatis.html"><a href="distatis.html#vocabulary-graphs"><i class="fa fa-check"></i><b>10.7</b> Vocabulary graphs</a></li>
<li class="chapter" data-level="10.8" data-path="distatis.html"><a href="distatis.html#contribution-barplots"><i class="fa fa-check"></i><b>10.8</b> Contribution Barplots</a></li>
</ul></li>
<li class="chapter" data-level="11" data-path="mfa.html"><a href="mfa.html"><i class="fa fa-check"></i><b>11</b> Multiple Factor Analysis</a><ul>
<li class="chapter" data-level="11.1" data-path="mfa.html"><a href="mfa.html#introduction-of-mfa"><i class="fa fa-check"></i><b>11.1</b> Introduction of MFA</a></li>
<li class="chapter" data-level="11.2" data-path="mfa.html"><a href="mfa.html#computation-6"><i class="fa fa-check"></i><b>11.2</b> Computation</a></li>
<li class="chapter" data-level="11.3" data-path="mfa.html"><a href="mfa.html#heatmap-7"><i class="fa fa-check"></i><b>11.3</b> Heatmap</a></li>
<li class="chapter" data-level="11.4" data-path="mfa.html"><a href="mfa.html#scree-plot-5"><i class="fa fa-check"></i><b>11.4</b> Scree Plot</a></li>
<li class="chapter" data-level="11.5" data-path="mfa.html"><a href="mfa.html#global-factor-scores-1"><i class="fa fa-check"></i><b>11.5</b> Global Factor Scores</a></li>
<li class="chapter" data-level="11.6" data-path="mfa.html"><a href="mfa.html#partial-factor-scores-1"><i class="fa fa-check"></i><b>11.6</b> Partial Factor Scores</a></li>
<li class="chapter" data-level="11.7" data-path="mfa.html"><a href="mfa.html#contribution-barplots-1"><i class="fa fa-check"></i><b>11.7</b> Contribution Barplots</a></li>
</ul></li>
<li class="chapter" data-level="12" data-path="end.html"><a href="end.html"><i class="fa fa-check"></i><b>12</b> The End</a><ul>
<li class="chapter" data-level="12.1" data-path="end.html"><a href="end.html#final-conclusion"><i class="fa fa-check"></i><b>12.1</b> Final Conclusion</a></li>
<li class="chapter" data-level="12.2" data-path="end.html"><a href="end.html#appreciation"><i class="fa fa-check"></i><b>12.2</b> Appreciation</a></li>
</ul></li>
<li class="divider"></li>
<li><a href="https://github.com/rstudio/bookdown/_book" target="blank">Published with bookdown</a></li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i><a href="./">Multivariate Statistical Analysis Cookbook with R</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal" id="section-">
<div id="pca" class="section level1">
<h1><span class="header-section-number">Chapter 4</span> Principal Component Analysis</h1>
<div id="introduction-of-pca" class="section level2">
<h2><span class="header-section-number">4.1</span> Introduction of PCA</h2>
<p>In the first statistical method, I will start from <strong>Principal Component Analysis</strong> (PCA).PCA is a common analysis I used for data exploration and dimensionality reduction. I aim to use PCA to <strong>extract important information</strong> , and <strong>find the similarity</strong> from sets of variables I have. Since the origin of PCA can be traced to concepts of Correlation and Linear Analysis, I can see large overlap between PCA and other linear methods. However, the uniqueness of the PCA relies on its calculation process: <strong>its goal is to convert the original data table (information) into new orthogonal variables.</strong> These new orthogonal variables will have same numbers with the original data table but generally the first few variables will explain most of the total variance for the whole data table, which I called them <em>principal components</em> in our analysis. Generating these new <em>principal components</em> will be beneficial for us to know the what’s dominant features in our data set and get rid of these noisy ones. Let’s me give an example: In questionnaire study, sometimes I will ask questions with high similarity:</p>
<blockquote>
<p><em>1. Do you like pet?<br />
2. Do you enjoying playing with your pet in your spare time?</em></p>
</blockquote>
<p>If I am a dog person, I will definitely answer “yes” at the first question and “My pleasure” at the second one. Reversely, If I am allergic to dog’s hair and was bitten by a dog during my childhood, I may answer “No” and “Absolutely No” at the two questions. I bet 99% people will have consistent answers for the two questions.</p>
<p>Except questionnaire study, there are many other place I might need to reduce the similarity and extract the most important information from our data set. In neuroimaging study, sometimes I will need to find out which brain regions will have similar activation; In real life research, after collecting hundreds of participants’ data, I want to know if male/female, or young/aged will have significant separation on some biological characteristics. PCA will be a good fit to reduce these kinds of redundancy. By looking into the <code>Scree Plot</code><sup><a href="Functions.html#Scree">2.1</a></sup>, I can know how many variables explain much more variance than others. By looking into the <code>Loading</code><sup><a href="Functions.html#Loading">2.6</a></sup>, I can know the relationship among different column variables. By looking into the <code>Factor Scores</code><sup><a href="Functions.html#FactorScores">2.4</a></sup> and <code>Contribution Barplot</code><sup><a href="Functions.html#Contribution">2.7</a></sup>, I can know which component are more closely associated with the separation of different groups. I will introduce these concepts in details in the following content.</p>
<p>Overall, PCA is a powerful statistical tool which is designed to help us find out the connections between variables and observation, and connection among multiple variables in <span style="background-color:yellow;">single numeric data table</span> (In the following chapter, I will mention more about the multiple data tables).</p>
</div>
<div id="computing" class="section level2">
<h2><span class="header-section-number">4.2</span> Computing</h2>
<p>The first step I need to do is to run PCA analysis. In this part, I will use some trick to make my computational life easier. All important matrix will be stored as a short character for convenience.</p>
<ul>
<li>fs: factor scores</li>
<li>eigs: eigenvalue</li>
<li>tau: represents how many varience explained by the factor</li>
<li>p.vals: the p value for the scree plot, which can tell us that what’s the significant components in our results.</li>
<li>boot.ratios: it is bootstrap ratio matrix helps us to generate bootstrap barplot in the end.</li>
<li>cj: contribution ratio for the column variables</li>
<li>fj: factor scores of column variables</li>
</ul>
<div class="sourceCode" id="cb24"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb24-1"><a href="pca.html#cb24-1"></a>res.PCA <-<span class="st"> </span><span class="kw">epPCA</span>(<span class="dt">DATA =</span> exp.neg[<span class="dv">7</span><span class="op">:</span><span class="dv">35</span>], <span class="dt">center =</span> <span class="ot">TRUE</span>,</span>
<span id="cb24-2"><a href="pca.html#cb24-2"></a> <span class="dt">scale =</span> <span class="st">'SS1'</span>,</span>
<span id="cb24-3"><a href="pca.html#cb24-3"></a> <span class="dt">DESIGN =</span> exp.neg<span class="op">$</span>group, <span class="dt">graphs =</span> <span class="ot">FALSE</span>)</span>
<span id="cb24-4"><a href="pca.html#cb24-4"></a>res.PCA.inference <-<span class="st"> </span><span class="kw">epPCA.inference.battery</span>(<span class="dt">DATA =</span> exp.neg[<span class="dv">7</span><span class="op">:</span><span class="dv">35</span>], </span>
<span id="cb24-5"><a href="pca.html#cb24-5"></a> <span class="dt">center =</span> <span class="ot">TRUE</span>,</span>
<span id="cb24-6"><a href="pca.html#cb24-6"></a> <span class="dt">scale =</span> <span class="st">'SS1'</span>,</span>
<span id="cb24-7"><a href="pca.html#cb24-7"></a> <span class="dt">DESIGN =</span> exp.neg<span class="op">$</span>group, </span>
<span id="cb24-8"><a href="pca.html#cb24-8"></a> <span class="dt">graphs =</span> <span class="ot">FALSE</span>)</span>
<span id="cb24-9"><a href="pca.html#cb24-9"></a>fs <-<span class="st"> </span>res.PCA<span class="op">$</span>ExPosition.Data<span class="op">$</span>fi</span>
<span id="cb24-10"><a href="pca.html#cb24-10"></a>eigs <-<span class="st"> </span>res.PCA<span class="op">$</span>ExPosition.Data<span class="op">$</span>eigs</span>
<span id="cb24-11"><a href="pca.html#cb24-11"></a>tau <-<span class="st"> </span>res.PCA<span class="op">$</span>ExPosition.Data<span class="op">$</span>t</span>
<span id="cb24-12"><a href="pca.html#cb24-12"></a>p.eigs <-<span class="st"> </span>res.PCA.inference<span class="op">$</span>Inference.Data<span class="op">$</span>components<span class="op">$</span>p.vals</span>
<span id="cb24-13"><a href="pca.html#cb24-13"></a>eigs.permu <-<span class="st"> </span>res.PCA.inference<span class="op">$</span>Inference.Data<span class="op">$</span>components<span class="op">$</span>eigs.perm</span>
<span id="cb24-14"><a href="pca.html#cb24-14"></a>boot.ratios <-<span class="st"> </span>res.PCA.inference<span class="op">$</span>Inference.Data<span class="op">$</span>fj.boots<span class="op">$</span>tests<span class="op">$</span>boot.ratios</span>
<span id="cb24-15"><a href="pca.html#cb24-15"></a>cj <-<span class="st"> </span>res.PCA<span class="op">$</span>ExPosition.Data<span class="op">$</span>cj</span>
<span id="cb24-16"><a href="pca.html#cb24-16"></a>fj <-<span class="st"> </span>res.PCA<span class="op">$</span>ExPosition.Data<span class="op">$</span>fj</span></code></pre></div>
</div>
<div id="heatmap" class="section level2">
<h2><span class="header-section-number">4.3</span> Heatmap</h2>
<p>In the heatmap part, the input data is X<sup>T</sup>X, which represent the co-variance Matrix or the correlation matrix in PCA. From the heatmap, I can know that some variables are closely correlated with each other, such as game performance, time usage, personality trait and attitude toward global environment. The heatmap can give us a hint about the following PCA results.</p>
<div class="sourceCode" id="cb25"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb25-1"><a href="pca.html#cb25-1"></a><span class="co"># plot</span></span>
<span id="cb25-2"><a href="pca.html#cb25-2"></a>pca.xtx <-<span class="st"> </span><span class="kw">as.matrix</span>(<span class="kw">t</span>(<span class="kw">scale</span>(exp.neg[,<span class="dv">7</span><span class="op">:</span><span class="dv">35</span>],</span>
<span id="cb25-3"><a href="pca.html#cb25-3"></a> <span class="dt">center =</span> <span class="ot">TRUE</span>, </span>
<span id="cb25-4"><a href="pca.html#cb25-4"></a> <span class="dt">scale =</span> <span class="ot">TRUE</span>)) <span class="op">%*%</span><span class="st"> </span><span class="kw">scale</span>(exp.neg[,<span class="dv">7</span><span class="op">:</span><span class="dv">35</span>], </span>
<span id="cb25-5"><a href="pca.html#cb25-5"></a> <span class="dt">center =</span> <span class="ot">TRUE</span>, </span>
<span id="cb25-6"><a href="pca.html#cb25-6"></a> <span class="dt">scale =</span> <span class="ot">TRUE</span>))</span>
<span id="cb25-7"><a href="pca.html#cb25-7"></a><span class="kw">plot.heatmap</span>(<span class="dt">DATA =</span> pca.xtx,</span>
<span id="cb25-8"><a href="pca.html#cb25-8"></a> <span class="dt">xcol =</span> m.color.design, </span>
<span id="cb25-9"><a href="pca.html#cb25-9"></a> <span class="dt">ycol =</span> m.color.design, </span>
<span id="cb25-10"><a href="pca.html#cb25-10"></a> <span class="dt">textsize =</span> <span class="dv">3</span>)</span></code></pre></div>
<p><img src="MSA_files/figure-html/pcaHeatmap-1.png" width="672" style="display: block; margin: auto;" /></p>
<div class="sourceCode" id="cb26"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb26-1"><a href="pca.html#cb26-1"></a><span class="kw">pheatmap</span>(<span class="dt">mat=</span>pca.xtx, <span class="dt">cluster_rows =</span> <span class="ot">FALSE</span>, </span>
<span id="cb26-2"><a href="pca.html#cb26-2"></a> <span class="dt">cluster_cols =</span> <span class="ot">FALSE</span> )</span></code></pre></div>
<p><img src="MSA_files/figure-html/pcaHeatmap-2.png" width="672" style="display: block; margin: auto;" /></p>
</div>
<div id="pcaScree" class="section level2">
<h2><span class="header-section-number">4.4</span> Scree Plot</h2>
<p>For the scree plot and permutation test, I can know how many components are statistically significant in our study, and whether the results is stable. Permutation test is designed for a <em>NS</em> test, to test the null hypothesis. By repeatedly sampling from data (putting it back, compared to bootstrap ratio), it will generate a new frequency distribution about the overall probability of outcome I observed. By comparing the value in the distribution range, I can know how confident I are to reject the null hypothesis and how much probability I have to make the typeI error. From the results below, I conclude that</p>
<div class="sourceCode" id="cb27"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb27-1"><a href="pca.html#cb27-1"></a><span class="kw">plot.scree</span>(eigs, p.eigs)</span></code></pre></div>
<p><img src="MSA_files/figure-html/pcaScreePlot-1.png" width="672" style="display: block; margin: auto;" /></p>
<div class="sourceCode" id="cb28"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb28-1"><a href="pca.html#cb28-1"></a><span class="kw">plot.permutation</span>(<span class="dt">eigs.perm =</span> eigs.permu, </span>
<span id="cb28-2"><a href="pca.html#cb28-2"></a> <span class="dt">eigs =</span> eigs, <span class="dt">para1=</span><span class="dv">10</span>)</span></code></pre></div>
<p><img src="MSA_files/figure-html/pcaScreePlot-2.png" width="672" style="display: block; margin: auto;" /></p>
<div class="sourceCode" id="cb29"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb29-1"><a href="pca.html#cb29-1"></a><span class="kw">plot.permutation</span>(<span class="dt">eigs.perm =</span> eigs.permu, </span>
<span id="cb29-2"><a href="pca.html#cb29-2"></a> <span class="dt">eigs =</span> eigs, <span class="dt">para1 =</span> <span class="dv">7</span>, <span class="dt">Dim =</span> <span class="dv">2</span>)</span></code></pre></div>
<p><img src="MSA_files/figure-html/pcaScreePlot-3.png" width="672" style="display: block; margin: auto;" /></p>
</div>
<div id="factor-scores" class="section level2">
<h2><span class="header-section-number">4.5</span> Factor Scores</h2>
<p>The factor scores is the most important part in our PCA analysis. As you can see, with the help of the function, things become such easy to have our factor scores plot. In the two plot below, I can know that they are separated with each other in great extend. The dimension 2 perfectly distinguishes <strong>Hig</strong> social intelligence and <strong>High</strong> general intelligence participants with <strong>Low</strong> social intelligence and <strong>Low</strong> general intelligence ones. The interesting thing is that it looks like a gradient distribution: HIGH_HIGH at the top, LOW_LOW at the bottom, and HIGH_LOW in the middle. From the factor scores plot, I can also know that high social intelligence is closer to double high participants. However, the Dimension 1 and Dimension 3 are not much informative for us from the plots.</p>
<div class="sourceCode" id="cb30"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb30-1"><a href="pca.html#cb30-1"></a><span class="kw">plot.fs</span>(exp.neg<span class="op">$</span>group, </span>
<span id="cb30-2"><a href="pca.html#cb30-2"></a> <span class="dt">fs=</span>fs, </span>
<span id="cb30-3"><a href="pca.html#cb30-3"></a> <span class="dt">eigs=</span>eigs, </span>
<span id="cb30-4"><a href="pca.html#cb30-4"></a> <span class="dt">tau=</span>tau, </span>
<span id="cb30-5"><a href="pca.html#cb30-5"></a> <span class="dt">d =</span> <span class="dv">1</span>,</span>
<span id="cb30-6"><a href="pca.html#cb30-6"></a> <span class="dt">mode=</span><span class="st">"CI"</span>, </span>
<span id="cb30-7"><a href="pca.html#cb30-7"></a> <span class="dt">method =</span> <span class="st">"PCA"</span>)</span></code></pre></div>
<p><img src="MSA_files/figure-html/pcaFactorScores-1.png" width="672" style="display: block; margin: auto;" /></p>
<div class="sourceCode" id="cb31"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb31-1"><a href="pca.html#cb31-1"></a><span class="kw">plot.fs</span>(exp.neg<span class="op">$</span>group, </span>
<span id="cb31-2"><a href="pca.html#cb31-2"></a> <span class="dt">fs=</span>fs,</span>
<span id="cb31-3"><a href="pca.html#cb31-3"></a> <span class="dt">eigs=</span>eigs,</span>
<span id="cb31-4"><a href="pca.html#cb31-4"></a> <span class="dt">tau=</span>tau, </span>
<span id="cb31-5"><a href="pca.html#cb31-5"></a> <span class="dt">d =</span> <span class="dv">2</span>,</span>
<span id="cb31-6"><a href="pca.html#cb31-6"></a> <span class="dt">mode=</span><span class="st">"CI"</span>,</span>
<span id="cb31-7"><a href="pca.html#cb31-7"></a> <span class="dt">method =</span> <span class="st">"PCA"</span>)</span></code></pre></div>
<p><img src="MSA_files/figure-html/pcaFactorScores-2.png" width="672" style="display: block; margin: auto;" /></p>
</div>
<div id="loading" class="section level2">
<h2><span class="header-section-number">4.6</span> Loading</h2>
<p>From the loading plot, I can see that they are some determined factors associated more with dimension 2: The SAT results and empathy are related with dimension 2, which represents that the two aspects are important for the separation of the groups.</p>
<div class="sourceCode" id="cb32"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb32-1"><a href="pca.html#cb32-1"></a><span class="kw">plot.loading</span>(exp.neg[,<span class="dv">7</span><span class="op">:</span><span class="dv">35</span>],</span>
<span id="cb32-2"><a href="pca.html#cb32-2"></a> <span class="dt">col=</span>m.color.design, </span>
<span id="cb32-3"><a href="pca.html#cb32-3"></a> <span class="dt">fs=</span>fs, </span>
<span id="cb32-4"><a href="pca.html#cb32-4"></a> <span class="dt">eigs=</span>eigs, </span>
<span id="cb32-5"><a href="pca.html#cb32-5"></a> <span class="dt">tau=</span>tau, <span class="dt">d=</span><span class="dv">1</span>)</span></code></pre></div>
<p><img src="MSA_files/figure-html/pcaLoading-1.png" width="672" style="display: block; margin: auto;" /></p>
<div class="sourceCode" id="cb33"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb33-1"><a href="pca.html#cb33-1"></a><span class="kw">plot.loading</span>(exp.neg[,<span class="dv">7</span><span class="op">:</span><span class="dv">35</span>], </span>
<span id="cb33-2"><a href="pca.html#cb33-2"></a> <span class="dt">col=</span>m.color.design, </span>
<span id="cb33-3"><a href="pca.html#cb33-3"></a> <span class="dt">fs=</span>fs, </span>
<span id="cb33-4"><a href="pca.html#cb33-4"></a> <span class="dt">eigs=</span>eigs, </span>
<span id="cb33-5"><a href="pca.html#cb33-5"></a> <span class="dt">tau=</span>tau, <span class="dt">d=</span><span class="dv">2</span>)</span></code></pre></div>
<p><img src="MSA_files/figure-html/pcaLoading-2.png" width="672" style="display: block; margin: auto;" /></p>
</div>
<div id="contriution-and-bootstrap-ratio-barplots" class="section level2">
<h2><span class="header-section-number">4.7</span> Contriution and Bootstrap Ratio Barplots</h2>
<p>From the contribution and bootstrap ratio barplots, I can know that the first component is closely related with participants’ game performance. SAT results and empathy related ability are significantly contributing to component2, which aligns with the conclusion of the published article.</p>
<div class="sourceCode" id="cb34"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb34-1"><a href="pca.html#cb34-1"></a><span class="kw">plot.cb</span>(<span class="dt">cj=</span>cj, </span>
<span id="cb34-2"><a href="pca.html#cb34-2"></a> <span class="dt">fj=</span>fj,</span>
<span id="cb34-3"><a href="pca.html#cb34-3"></a> <span class="dt">col =</span> m.color.design,</span>
<span id="cb34-4"><a href="pca.html#cb34-4"></a> <span class="dt">boot.ratios =</span> boot.ratios, </span>
<span id="cb34-5"><a href="pca.html#cb34-5"></a> <span class="dt">signifOnly =</span> <span class="ot">TRUE</span>, </span>
<span id="cb34-6"><a href="pca.html#cb34-6"></a> <span class="dt">fig =</span> <span class="dv">3</span>, </span>
<span id="cb34-7"><a href="pca.html#cb34-7"></a> <span class="dt">horizontal =</span> <span class="ot">TRUE</span>, </span>
<span id="cb34-8"><a href="pca.html#cb34-8"></a> <span class="dt">colrow =</span> <span class="st">"col"</span>)</span></code></pre></div>
<p><img src="MSA_files/figure-html/unnamed-chunk-1-1.png" width="672" style="display: block; margin: auto;" /></p>
</div>
<div id="conclusion" class="section level2">
<h2><span class="header-section-number">4.8</span> Conclusion</h2>
<p>It is easy to observe that they are connection between the game performance results and some personality or attitude variables. However, it is worth to mention that currently the separation doesn’t represent that I have already had the evidence the collective action will be affected by social intelligence and general intelligence. Please remember our group variable is <strong>GPA</strong> and <strong>Emotion Processing Ability</strong>, the two variables are naturally correlated with the previous two aspects. I need more evidence on other variables to prove that I are right.</p>
</div>
</div>
</section>
</div>
</div>
</div>
<a href="Data-Intro.html" class="navigation navigation-prev " aria-label="Previous page"><i class="fa fa-angle-left"></i></a>
<a href="ca.html" class="navigation navigation-next " aria-label="Next page"><i class="fa fa-angle-right"></i></a>
</div>
</div>
<script src="libs/gitbook-2.6.7/js/app.min.js"></script>
<script src="libs/gitbook-2.6.7/js/lunr.js"></script>
<script src="libs/gitbook-2.6.7/js/clipboard.min.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-search.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-sharing.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-bookdown.js"></script>
<script src="libs/gitbook-2.6.7/js/jquery.highlight.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-clipboard.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
"sharing": {
"github": false,
"facebook": true,
"twitter": true,
"linkedin": false,
"weibo": false,
"instapaper": false,
"vk": false,
"all": ["facebook", "twitter", "linkedin", "weibo", "instapaper"]
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": "https://github.com/rstudio/bookdown/_book/edit/master/04-PCA.Rmd",
"text": "Edit"
},
"history": {
"link": null,
"text": null
},
"view": {
"link": null,
"text": null
},
"download": ["MSA.pdf", "MSA.epub"],
"toc": {
"collapse": "subsection"
}
});
});
</script>
</body>
</html>