-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.Rmd
More file actions
646 lines (445 loc) Β· 17.1 KB
/
index.Rmd
File metadata and controls
646 lines (445 loc) Β· 17.1 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
---
title: "Psy 6136: Categorical Data Analysis"
author: "Michael Friendly"
date: "Winter, 2026"
output:
html_document:
toc: true
toc_depth: 2
toc_float: yes
css: assets/styles.css
includes:
after_body: footer.html
in_header: header.html
---
<center>
<img src="icons/psy6136-highres.png" width="120px" style="margin-right: 2em;">
<img src="icons/psy6136-qr.png" width="120px" style="margin-left: 2em;"/>
</center>
```{r setup, echo=FALSE}
source("assets/div_heading.R")
```
## Course Description
This course is designed as a broad, applied introduction to the statistical analysis of categorical (or discrete) data, such as counts, proportions, nominal variables, ordinal variables, discrete variables with few values, continuous variables grouped into a small number of categories, etc.
* The course begins with methods designed for cross-classified table of counts, (i.e., contingency tables), using simple chi square-based methods.
* It progresses to generalized linear models, for which log-linear models provide a natural extension of simple chi square-based methods.
* This framework is then extended to comprise logit and logistic regression models for binary responses and generalizations of these models for polytomous (multicategory) outcomes.
Throughout, there is a strong emphasis on associated **graphical methods** for visualizing categorical data, checking model assumptions, etc. Lab sessions will familiarize the student with software using R for carrying out these analyses.
Course and lecture topics are listed below, in a visual overview.
* See the [Course schedule](schedule.html) for details of readings, lecture notes, R scripts, etc.
* For students, see [Assignments](about.html#assign) and [Evaluation](about.html#evaluation)
<img src="icons/construction.png" height=20> These web pages will be revised as the course proceeds. If you find a link that doesn't work, or could be replaced by something better or more recent,
[please let me know by filing an issue](https://github.com/friendly/psy6136/issues).
<img src="icons/construction.png" height=20>
## Overview & Introduction {#overview}
Let's get started! I'll talk about the organization of the course, what is expected, and resouces for
learning. Then, provide an overview of methods and models for catgegorical data and the role
of graphical methods in understanding and communicating results.

<!--
```{r topics1, results='asis', echo=FALSE}
div_heading("topics")
```
-->
<!-- #### <img src="icons/list.png" height=20> Topics: -->
#### π Topics:
- Course outline, books, R
- What is categorical data?
- Categorical data analysis: methods & models
- Graphical methods
<!--
```{r lecture1, results='asis', echo=FALSE}
div_heading("lecture")
```
-->
#### <img src="icons/PDF_icon.png" height=20> Lecture notes
- [1up PDF](lectures/01-Overview.pdf) || [4up PDF](lectures/01-Overview-2x2.pdf) || [PPT](lectures/01-Overview.pptx)
<!-- #### Readings: `r icon::fa("book-reader", color="blue")` -->
<!--
```{r readings1, results='asis', echo=FALSE}
div_heading("readings")
```
-->
#### <img src="icons/book.png" height=20> Readings:
**Bold face** items are considered essential. When there are assignments,
some supplementary readings are also mentioned there.
- **DDAR**: [Ch 1](VCDR/chapter01.pdf); [Ch 2](VCDR/chapter02.pdf)
- **Agresti**, Ch 1
- See [Supplementary resources](resources.html#week1) for this week.
<!-- #### Assignment: `r icon::fa("building", color="brown")` -->
```{r asn1, results='asis', echo=FALSE}
div_heading("assign")
```
- [Assignment 1](assign/assign1.pdf)
## Discrete Distributions {#discrete}
Discrete distributions are the gateway drug for categorical data analysis. Meet some
--- binomial, Poisson, Negative Binomial, and others --- who will
become your friends as you learn to analyze discrete data.
More importantly, learn some nifty graphical methods for fitting these distributions
and understanding why a given one might not fit well.

<!--
```{r topics2, results='asis', echo=FALSE}
div_heading("topics")
```
-->
<!-- #### <img src="icons/list.png" height=20> Topics: -->
#### π Topics:
- Discrete distributions: Basic ideas
- Fitting discrete distributions
- Graphical methods: Rootograms, Ord plots
- Robust distribution plots
- Looking ahead
<!-- #### Lecture notes `r icon::fa("file-pdf", color="red")`
```{r lecture2, results='asis', echo=FALSE}
div_heading("lecture")
```
-->
#### <img src="icons/PDF_icon.png" height=20> Lecture notes
- [1up PDF](lectures/02-Discrete.pdf) || [4up PDF](lectures/02-Discrete-2x2.pdf)
<!-- #### Readings: `r icon::fa("book-reader", color="blue")` -->
#### <img src="icons/book.png" height=20> Readings:
- **DDAR**: [Ch 3](VCDR/chapter03.pdf)
- See [Supplementary resources](resources.html#week2) for this week.
```{r asn2, results='asis', echo=FALSE}
div_heading("assign")
```
- [Assignment 2](assign/assign2.pdf)
```{r quiz2, results='asis', echo=FALSE}
div_heading("quiz")
```
- [Quiz 2 - Discrete distributions](quiz/02-discrete.html)
## Two-way Tables {#twoway}
How can we test for independence and measure the strength of association in two way tables?
Get acquainted with some standard tests and statistics: Pearson $\chi^2$, Odds ratio,
Cramer's $V$, Cohen's $\kappa$ and even Bangdiwal's $W$.
More importantly, how can we _visualize_ association? We'll meet fourfold plots, sieve diagrams,
spine plots. Much of this is prep for understanding how to formulate, test and visualize
models for categorical data.

<!--
```{r topics3, results='asis', echo=FALSE}
div_heading("topics")
```
-->
#### π Topics:
- Overview: $2 \times 2$, $r \times c$, ordered tables
- Independence
- Visualizing association
- Ordinal factors
- Square tables: Observer agreement
- Looking ahead: models
<!-- #### Lecture notes `r icon::fa("file-pdf", color="red")`
```{r lecture3, results='asis', echo=FALSE}
div_heading("lecture")
```
-->
#### <img src="icons/PDF_icon.png" height=20> Lecture notes
- [1up PDF](lectures/03-Twoway1.pdf) || [4up PDF](lectures/03-Twoway1-2x2.pdf)
- [Tutorial on two way tables](tutorials/twoway.pdf)
<!-- #### Readings: `r icon::fa("book-reader", color="blue")` -->
<!--
<div style="display:flex">
<i class="fas fa-book-reader" style="color:blue; font-size: 1.25em;"></i>
<h4>Readings</h4>
</div>
-->
#### <img src="icons/book.png" height=20> Readings:
- **DDAR**: [Ch 4](VCDR/chapter04.pdf)
- **Agresti, Ch 2**
- See [Supplementary resources](resources.html#week3) for this week.
```{r quiz3, results='asis', echo=FALSE}
div_heading("quiz")
```
```{r asn3, results='asis', echo=FALSE}
div_heading("assign")
```
- [Assignment 3](assign/assign3.pdf)
- [Quiz 3 - Two-way tables](quiz/03-twoway.html)
## Loglinear models & mosaic displays {#loglin}
```
ΰΌΛΒ°.πΰΏ*:ο½₯
Some people think nothing is prettier
Than algebra of models log-linear.
But I've got the hots
For my mosaic plots
With all those squares in the interior.
--- by Michael Greenacre (see his [Statistical Songs](https://www.youtube.com/StatisticalSongs))
```

<!--
```{r topics4, results='asis', echo=FALSE}
div_heading("topics")
```
-->
#### π Topics:
- Mosaic displays: Basic ideas
- Loglinear models
- Model-based methods: Fitting & graphing
- Mosaic displays: Visual fitting
- survival on the _Titanic_
- Sequential plots & models
<!-- #### Lecture notes `r icon::fa("file-pdf", color="red")`
```{r lecture4, results='asis', echo=FALSE}
div_heading("lecture")
```
-->
#### <img src="icons/PDF_icon.png" height=20> Lecture notes
- [1up PDF](lectures/04-Loglin.pdf) || [4up PDF](lectures/04-Loglin-2x2.pdf)
<!--
```{r readings4, results='asis', echo=FALSE}
div_heading("readings")
```
-->
#### <img src="icons/book.png" height=20> Readings:
- **DDAR**: [Ch 5](VCDR/chapter05.pdf)
- **Agresti, 2.7; Ch 7**
- See [Supplementary resources](resources.html#week4) for this week.
```{r asn4, results='asis', echo=FALSE}
div_heading("assign")
```
- [Assignment 4](assign/assign4.pdf)
```{r quiz4, results='asis', echo=FALSE}
div_heading("quiz")
```
- [Quiz 4 - Loglinear models](quiz/04-loglin.html)
## Correspondence Analysis {#corresp}
```
ΰΌΛΒ°.πΰΏ*:ο½₯
BenzΓ©cri brought data mystique
With his elegant SVD technique.
So I've got the hots
For correspondence plots
Where profiles show what the rows seek.
```
Correspondence analysis (CA) is one of the first things I think of when I meet a new frequency table and
want to get a quick look at the relations among the row and column categories.
Very much like PCA for quantitative data, think of CA as a **multivariate juicer** that takes a
high-dimensional data set and squeezes it into a 2D (or 3D) space that best accounts for the
associations (Pearson $\chi^2$) between the row and column categories.
The category scores on the dimensions are in fact the best numerical values that can be defined.
They can be used to permute the categories in mosaic displays to make the pattern of associations
as clear as possible.

<!--
```{r topics5, results='asis', echo=FALSE}
div_heading("topics")
```
-->
#### π Topics:
- CA: Basic ideas
- Singular value decomposition (SVD)
- Optimal category scores
- Multiway tables: MCA
<!-- #### Lecture notes `r icon::fa("file-pdf", color="red")`
```{r lecture5, results='asis', echo=FALSE}
div_heading("lecture")
```
-->
#### <img src="icons/PDF_icon.png" height=20> Lecture notes
- [1up PDF](lectures/05-Corresp.pdf) || [4up PDF](lectures/05-Corresp-2x2.pdf)
<!--
```{r readings5, results='asis', echo=FALSE}
div_heading("readings")
```
-->
#### <img src="icons/book.png" height=20> Readings:
- **DDAR**: [Ch 6](VCDR/chapter06.pdf)
- See [Supplementary resources](resources.html#week5) for this week.
```{r quiz5, results='asis', echo=FALSE}
div_heading("quiz")
```
- [Quiz 5 - Correspondence analysis](quiz/05-corresp.html)
## Logistic regression
```
ΰΌΛΒ°.πΰΏ*:ο½₯
For responses that come just in two,
Linear models just will not do.
With glm() and a smile
In binomial style,
The S-curve reveals what is true.
```
Logistic regression provides an entry to model-based methods for categorical data
analysis. These provide estimates and tests for predictor variables of a
binary outcome, but more importantly, allow graphs of a fitted outcome together
with confidence bands representing uncertainty,

<!--
```{r topics6, results='asis', echo=FALSE}
div_heading("topics")
```
-->
#### π Topics:
- Model-based methods: Overview
- Logistic regression: one predictor, multiple predictors, fitting
- Visualizing logistic regression
- Effect plots
- Case study: Racial profiling
- Model diagnostics
<!-- #### Lecture notes `r icon::fa("file-pdf", color="red")`
```{r lecture6, results='asis', echo=FALSE}
div_heading("lecture")
```
-->
#### <img src="icons/PDF_icon.png" height=20> Lecture notes
- [1up PDF](lectures/06-Logistic.pdf) || [4up PDF](lectures/06-Logistic-2x2.pdf)
#### <img src="icons/book.png" height=20> Readings:
- **DDAR**: [Ch 7](VCDR/chapter07.pdf)
- See [Supplementary resources](resources.html#week6) for this week.
```{r quiz6, results='asis', echo=FALSE}
div_heading("quiz")
```
- [Quiz 6 - Logistic regression](quiz/06-logistic.html)
## Logistic regression: Extensions
The ideas behind logistic regression can be extended in a variety of ways.
The effects of predictors on a binary response can incorporate non-linear terms
and interactions. When the outcome is **polytomous** (more than two categories),
and the response categories are ordered,
the _proportional odds model_ provides a simple framework.
Other methods for polytomous outcomes include _nested dichotomies_ and
the general _multinomial_ logistic regression model.

<!--
```{r topics7, results='asis', echo=FALSE}
div_heading("topics")
```
-->
<!-- #### <img src="icons/list.png" height=20> Topics: -->
#### π Topics:
- Case study: Survival in the Donner party
- Polytomous response models
+ Proportional odds model
+ Nested dichotomies
+ Multinomial models
<!-- #### Lecture notes `r icon::fa("file-pdf", color="red")`
```{r lecture7, results='asis', echo=FALSE}
div_heading("lecture")
```
-->
#### <img src="icons/PDF_icon.png" height=20> Lecture notes
- [1up PDF](lectures/07-Logistic2.pdf) || [4up PDF](lectures/07-Logistic2-2x2.pdf)
- Bonus lecture: [Deep Questions of Data Visualization](lectures/DeepQuestions.pdf)
#### <img src="icons/book.png" height=20> Readings:
- **DDAR**: [Ch 8](VCDR/chapter08.pdf)
- See [Supplementary resources](resources.html#week7) for this week.
```{r quiz7, results='asis', echo=FALSE}
div_heading("quiz")
```
- [Quiz 7 - Logistic regression: Extensions](quiz/07-logistic2.html)
## Extending loglinear models
Here we return to loglinear models to consider extensions to the `glm()` framework.
Models for ordinal factors have greater power when associations reflect their ordered nature.
The `gnm` package extends these to generalized _non-linear_ models.
For **square tables**, we can fit a variety of specialized models, including
_quasi-independence_, _symmetry_ and _quasi-symmetry_.

<!--
```{r topics8, results='asis', echo=FALSE}
div_heading("topics")
```
-->
<!-- #### <img src="icons/list.png" height=20> Topics: -->
#### π Topics:
- Logit models for response variables
- Models for ordinal factors
- RC models, estimating row/col scores
- Models for square tables
- More complex models
<!-- #### Lecture notes `r icon::fa("file-pdf", color="red")`
```{r lecture8, results='asis', echo=FALSE}
div_heading("lecture")
```
-->
#### <img src="icons/PDF_icon.png" height=20> Lecture notes
- [1up PDF](lectures/08-Loglin2.pdf) || [4up PDF](lectures/08-Loglin2-2x2.pdf)
#### <img src="icons/book.png" height=20> Readings:
- **DDAR**: [Ch 10](VCDR/chapter10.pdf)
```{r quiz8, results='asis', echo=FALSE}
div_heading("quiz")
```
- [Quiz 8 - Extending Loglinear Models](quiz/08-loglin2.html)
## GLMs for count data
Here we consider generalized linear models more broadly, with emphasis on those for
a count or frequency response variable in the Poisson family.
Some extensions allow for **overdispersion**, including the _quasi-poisson_
and _negative binomial_ model. When the data exhibits a greater frequency of
0 counts, **zero-inflated** versions of these models come to the rescue.

<!--
```{r topics9, results='asis', echo=FALSE}
div_heading("topics")
```
-->
#### π Topics:
- Generalized linear models: Families & links
- GLMs for count data
- Model diagnostics
- Overdispersion
- Excess zeros
<!-- #### Lecture notes `r icon::fa("file-pdf", color="red")` -->
<!--
```{r lecture9, results='asis', echo=FALSE}
div_heading("lecture")
```
-->
#### <img src="icons/PDF_icon.png" height=20> Lecture notes
- [1up PDF](lectures/09-CountData.pdf) || [4up PDF](lectures/09-CountData-2x2.pdf)
- See [Supplementary resources](resources.html#week9) for this week.
- [Notes on Negative Binomial: Interpreting the overdispersion parameter](notes/09-negbin.html)
#### <img src="icons/book.png" height=20> Readings:
- **DDAR**: [Ch 11](VCDR/chapter11.pdf)
```{r quiz9, results='asis', echo=FALSE}
div_heading("quiz")
```
- [Quiz 9 - GLMs for Count Data](quiz/09-countdata.html)
## Models and graphs for log odds and log odds ratios
Logit models for a binary response simplify the specification and interpretation
of loglinear models. In the same way, a model for a
polytomous response can be simplified by considering a set of log odds
defined for the set of adjacent categories.
Similarly, when there are two response variables, models for their log odds
ratios provide a new way to look at their associations in a structured way.

<!--
```{r topics10, results='asis', echo=FALSE}
div_heading("topics")
```
-->
#### π Topics:
- Logit models -> log odds models
- Generalized log odds ratios
- Models for bivariate responses
<!-- #### Lecture notes `r icon::fa("file-pdf", color="red")` -->
<!--
```{r lecture10, results='asis', echo=FALSE}
div_heading("lecture")
```
-->
#### <img src="icons/PDF_icon.png" height=20> Lecture notes
- [1up PDF](lectures/10-Log-Odds.pdf) || [4up PDF](lectures/10-Log-Odds-2x2.pdf)
```{r readings10, results='asis', echo=FALSE}
div_heading("readings")
```
- Friendly & Meyer (2015), [General Models and Graphs for Log Odds and Log
Odds Ratios](https://www.datavis.ca/papers/CARME2015-2x2.pdf)
## Wrapup & summary: The Last Waltz
A brief summary of the course.

<!--
```{r topics99, results='asis', echo=FALSE}
div_heading("topics")
```
-->
#### π Topics:
- Course goals
- What have I tried to teach?
- Whirlwind course summary
- Your turn: what did you like/dislike about the course?
<!-- #### Lecture notes `r icon::fa("file-pdf", color="red")` -->
<!--
```{r lecture99, results='asis', echo=FALSE}
div_heading("lecture")
```
-->
#### <img src="icons/PDF_icon.png" height=20> Lecture notes
- [1up PDF](lectures/99-Summary.pdf) || [4up PDF](lectures/99-Summary-2x2.pdf)