Debian Codegraph @

stat/manual_statistics.cpp

raw
1 /* manual_statistics.cpp
2 *
3 * Copyright (C) 1992-2007,2009-2011,2013-2017,2021,2023,2025 Paul Boersma
4 *
5 * This code is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
9 *
10 * This code is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this work. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "ManPagesM.h"
20
21 void manual_statistics_init (ManPages me);
22 void manual_statistics_init (ManPages me) {
23
24 MAN_PAGES_BEGIN
25 R"~~~(
26 ################################################################################
27 "Statistics"
28 © Paul Boersma 20060506
29
30 This is the tutorial about basic statistical techniques in Praat, which work
31 with the @Table object or even directly from the @Goodies menu. It assumes that you are familiar with the @Intro.
32
33 (Under construction..................)
34
35 Goodies menu:
36 • @@Difference of two proportions
37
38 For a selected Table:
39 • @@Logistic regression
40
41 For more sophisticated techniques, see:
42 • @@Principal component analysis
43 • @@Multidimensional scaling
44 • @@Discriminant analysis
45
46 ################################################################################
47 "Create Corpus..."
48 © Paul Boersma 2023
49
50 A command in the @@New menu@, to create a #Corpus object.
51
52 ################################################################################
53 "Create TableOfReal"
54 © Paul Boersma 2023
55
56 A command in the #Tables submenu of the @@New menu@, to create a @TableOfReal object
57 with the given number of rows and columns.
58
59 ################################################################################
60 "Create iris data set"
61 © Paul Boersma 2023
62
63 A command in the ##Datasets from the literature# submenu of the #Tables submenu of the @@New menu@,
64 to create a @TableOfReal object with data from the @@iris data set@.
65
66 ################################################################################
67 "Table"
68 © Paul Boersma 2003,2023
69
70 One of the @@types of objects@ in Praat. See the @Statistics tutorial.
71
72 In the @@New menu@:
73 • @@Create Table with column names...
74 • @@Create Table without column names...
75 • @@Create H1H2 table (Keating & Esposito 2006)
76 • @@Create Table (Ganong 1980)
77
78 In the @@Open menu@:
79 • @@Read Table from tab-separated file...
80 • @@Read Table from comma-separated file...
81 • @@Read Table from semicolon-separated file...
82 • @@Read Table from whitespace-separated file...
83 • @@Read TableOfReal from headerless spreadsheet file...
84
85 In the @@Save menu@ when you select a Table:
86 • @@Table: Save as tab-separated file...
87 • @@Table: Save as comma-separated file...
88 • @@Table: Save as semicolon-separated file...
89
90 In the @@Draw menu@ when you select one or more Tables:
91 • @@Table: Scatter plot...
92
93 In the Query menu when you select a Table:
94 • @@Table: Get quantile...
95 • @@Table: Get minimum...
96 • @@Table: Get maximum...
97 • @@Table: Get sum...
98 • @@Table: Get mean...
99 • @@Table: Get group mean...
100 • @@Table: Get standard deviation...
101 • @@Table: Get median absolute deviation...
102 • @@Table: Report mean (Student t)...
103 • @@Table: Report group mean (Student t)...
104
105 In the Modify menu when you select one or more Tables:
106 • @@Table: Formula...
107 • @@Table: Formula (column range)...
108 • @@Table: Sort rows...
109
110 In the Extract menu when you select one or more Tables:
111 • @@Table: Extract rows where column (number)...
112 • @@Table: Extract rows where column (text)...
113 • @@Table: Extract rows where...
114 • @@Table: Collapse rows...
115 • @@Table: Rows to columns...
116
117 ################################################################################
118 "Create Table with column names..."
119 © Paul Boersma 2023
120
121 A command in the #Tables submenu of the @@New menu@,
122 to create an empty Table with the given names for the columns.
123
124 ################################################################################
125 "Create Table without column names..."
126 © Paul Boersma 2023
127
128 A command in the #Tables submenu of the @@New menu@,
129 to create an empty Table.
130
131 ################################################################################
132 "Create H1H2 table (Keating & Esposito 2006)"
133 © Paul Boersma 2023
134
135 A command in the ##Datasets from the literature# submenu of the #Tables submenu of the @@New menu@,
136 to create a Table from @@Keating & Esposito (2006)@.
137
138 ################################################################################
139 "Create Table (Ganong 1980)"
140 © Paul Boersma 2023
141
142 A command in the ##Datasets from the literature# submenu of the #Tables submenu of the @@New menu@,
143 to create a Table from @@Ganong (1980)@.
144
145 ################################################################################
146 "Read Table from tab-separated file..."
147 © Paul Boersma 2023
148
149 A command in the @@Open menu@,
150 to read a Table from disk.
151
152 ################################################################################
153 "Read Table from comma-separated file..."
154 © Paul Boersma 2023
155
156 A command in the @@Open menu@,
157 to read a Table from disk.
158
159 ################################################################################
160 "Read Table from semicolon-separated file..."
161 © Paul Boersma 2023
162
163 A command in the @@Open menu@,
164 to read a Table from disk.
165
166 ################################################################################
167 "Read TableOfReal from headerless spreadsheet file..."
168 © Paul Boersma 2023
169
170 A command in the @@Open menu@,
171 to read a TableOfReal from disk.
172
173 ################################################################################
174 "Read Table from whitespace-separated file..."
175 © Paul Boersma 2023
176
177 A command in the @@Open menu@,
178 to read a Table from disk.
179
180 Each contiguous stretch of horizontal whitespace (e.g. spaces and tab)
181 is considered a single separator. This entails, for instance, that you
182 cannot read cells from such a file that contain spaces.
183
184 ################################################################################
185 "Table: Collapse rows..."
186 © Paul Boersma 2006,2007,2023
187
188 A command that becomes available in the Extract submenu when you select one or more @Table objects.
189
190 ################################################################################
191 "Table: Extract rows where column (number)..."
192 © Paul Boersma 2006,2023
193
194 A command that becomes available in the Extract submenu when you select one or more @Table objects.
195
196 ################################################################################
197 "Table: Extract rows where column (text)..."
198 © Paul Boersma 2006,2023
199
200 A command that becomes available in the Extract submenu when you select one or more @Table objects.
201
202 ################################################################################
203 "Table: Extract rows where..."
204 © Paul Boersma 2006,2023
205
206 A command that becomes available in the Extract submenu when you select one or more @Table objects.
207
208 ################################################################################
209 "Table: Formula..."
210 © Paul Boersma 2006,2023
211
212 A command that becomes available in the Modify submenu when you select one or more @Table objects.
213
214 ################################################################################
215 "Table: Formula (column range)..."
216 © Paul Boersma 2007,2023
217
218 A command that becomes available in the Modify submenu when you select one or more @Table objects.
219
220 ################################################################################
221 "Table: Get group mean..."
222 © Paul Boersma 2023
223
224 A command that becomes available in the Query submenu when you select a @Table object,
225 to get information about the mean of the values in the specified column,
226 for the specified group.
227
228 ################################################################################
229 "Table: Get maximum..."
230 © Paul Boersma 2023
231
232 A command that becomes available in the Query submenu when you select a @Table object,
233 to get information about the maximum of the values in the specified column.
234
235 ################################################################################
236 "Table: Get mean..."
237 © Paul Boersma 2006,2023
238
239 A command that becomes available in the Query submenu when you select a @Table object,
240 to get information about the mean of the values in the specified column.
241
242 ################################################################################
243 "Table: Get median absolute deviation..."
244 © Paul Boersma 2023
245
246 A command that becomes available in the Query submenu when you select a @Table object,
247 to get information about the median absolute deviation of the values in the specified column.
248
249 ################################################################################
250 "Table: Get minimum..."
251 © Paul Boersma 2023
252
253 A command that becomes available in the Query submenu when you select a @Table object,
254 to get information about the minimum of the values in the specified column.
255
256 ################################################################################
257 "Table: Get quantile..."
258 © Paul Boersma 2006,2023
259
260 A command that becomes available in the Query submenu when you select a @Table object,
261 to get information about the specified quantile of the values in the specified column.
262
263 For details, see the @@quantile algorithm@.
264
265 ################################################################################
266 "Table: Get standard deviation..."
267 © Paul Boersma 2006,2023
268
269 A command that becomes available in the Query submenu when you select a @Table object,
270 to get information about the standard deviation of the values in the specified column.
271
272 ################################################################################
273 "Table: Get sum..."
274 © Paul Boersma 2023
275
276 A command that becomes available in the Query submenu when you select a @Table object,
277 to get information about the sum of the values in the specified column.
278
279 ################################################################################
280 "Table: Report mean (Student t)..."
281 © Paul Boersma 2023
282
283 A command that becomes available in the Query submenu when you select a @Table object,
284 to get information about the statistical significance of a column mean.
285
286 ################################################################################
287 "Table: Report group mean (Student t)..."
288 © Paul Boersma 2007,2023
289
290 A command that becomes available in the Query submenu when you select a @Table object,
291 to get information about the statistical significance of a column mean,
292 for the specified group.
293
294 ################################################################################
295 "Table: Rows to columns..."
296 © Paul Boersma 2007,2023
297
298 A command that becomes available in the Extract submenu when you select one or more @Table objects.
299
300 ################################################################################
301 "Table: Save as comma-separated file..."
302 © Paul Boersma 2023
303
304 A command in the @@Save menu@,
305 to write a Table to disk.
306
307 ################################################################################
308 "Table: Save as semicolon-separated file..."
309 © Paul Boersma 2023
310
311 A command in the @@Save menu@,
312 to write a Table to disk.
313
314 ################################################################################
315 "Table: Save as tab-separated file..."
316 © Paul Boersma 2023
317
318 A command in the @@Save menu@,
319 to write a Table to disk.
320
321 ################################################################################
322 "Table: Scatter plot..."
323 © Paul Boersma 2023
324
325 A command that becomes available in the Draw submenu when you select one or more @Table objects.
326
327 ################################################################################
328 "Table: Sort rows..."
329 © Paul Boersma 2006,2023
330
331 A command that becomes available in the Modify submenu when you select one or more @Table objects.
332
333 ################################################################################
334 )~~~"
335 MAN_PAGES_END
336
337 MAN_BEGIN (U"TableOfReal", U"ppgb", 20030316) //2023
338 INTRO (U"One of the @@types of objects@ in Praat.")
339 NORMAL (U"A TableOfReal object contains a number of %cells. Each cell belongs to a %row and a %column. "
340 "For instance, a TableOfReal with 10 rows and 3 columns has 30 cells.")
341 NORMAL (U"Each row and each column may be labeled with a %title.")
342 ENTRY (U"Creating a TableOfReal from data in a text file")
343 NORMAL (U"Suppose you have F1 and F2 data for vowels. "
344 "You can create a simple text file like the following:")
345 CODE (U"\"ooTextFile\" ! The line by which Praat can recognize your file")
346 CODE (U"\"TableOfReal\" ! The line that tells Praat about the contents")
347 CODE (U"2 \"F1\" \"F2\" ! Number of columns, and column labels")
348 CODE (U"3 ! Number of rows")
349 CODE (U"\"a\" 800 1100 ! Row label (vowel), F1 value, F2 value")
350 CODE (U"\"i\" 280 2800 ! Row label (vowel), F1 value, F2 value")
351 CODE (U"\"u\" 260 560 ! Row label (vowel), F1 value, F2 value")
352 NORMAL (U"Praat is rather forgiving about the use of spaces, tabs, and newlines. "
353 "See @@Save as text file...@ for general information.")
354 NORMAL (U"You will often have your data in a file with a self-describing format, "
355 "i.e. in which the number of values on a line equals the number of columns "
356 "of the table:")
357 CODE (U"800 1100")
358 CODE (U"280 2800")
359 CODE (U"260 560")
360 NORMAL (U"Such a file can be read with @@Read Matrix from raw text file...@. "
361 "This creates a Matrix object, which can be cast to a TableOfReal object "
362 "by @@Matrix: To TableOfReal@. The resulting TableOfReal does not have "
363 "any row or column labels yet. You could add column labels with:")
364 CODE (U"Set column label (index): 1, “F1”")
365 CODE (U"Set column label (index): 2, “F2”")
366 NORMAL (U"Of course, if the row labels contain crucial information, "
367 "and the number of rows is large, this is not a feasible method.")
368 MAN_END
369
370 MAN_BEGIN (U"TableOfReal: Set value...", U"ppgb", 19980105)
371 INTRO (U"A command to change the value of one table cell in each selected @TableOfReal object.")
372 ENTRY (U"Settings")
373 TERM (U"##Row number")
374 DEFINITION (U"the number of the row of the cell whose value you want to change.")
375 TERM (U"##Column number")
376 DEFINITION (U"the number of the column of the cell whose value you want to change.")
377 TERM (U"##New value")
378 DEFINITION (U"the value that you want the specified cell to have.")
379 MAN_END
380
381 MAN_BEGIN (U"Difference of two proportions", U"ppgb", 20090717)
382 INTRO (U"This page explains how you compute the significance of a difference between two proportions "
383 "with a %\\ci^2 (chi-square) test.")
384 ENTRY (U"1. Example of normal use")
385 NORMAL (U"Suppose that you are interested in proving that for a certain experimental participant Task B is easier than Task A."
386 "You let the participant perform Task A 110 times, and she turns out to perform this task correctly 71 times. "
387 "You also let her perform Task B 120 times, and she performs this task correctly 93 times. "
388 "The following table summarizes the results of your experiment:")
389 CODE1 (U"\t\tCorrect\tIncorrect")
390 CODE1 (U"\tTask A\t71\t39")
391 CODE1 (U"\tTask B\t93\t27")
392 NORMAL (U"The null hypothesis is that both tasks are equally difficult for the participant "
393 "and that the probability that she performs Task A correctly is equal to "
394 "the probability that she performs Task B correctly.")
395 NORMAL (U"To compute the probability that the observed proportions are at least as different as 93/120 and 71/110 "
396 "if the null hypothesis is true, go to ##Report difference of two proportions# in the @Goodies menu "
397 "and fill in the four values 71, 39, 93, and 27. The resulting two-tailed %p is 0.04300, suggesting "
398 "that the null hypothesis can be rejected and the two tasks are not equally difficult for the participant "
399 "(if the possibility that Task A is easier for her than Task B can be ruled out a priori, "
400 "then the resulting one-tailed %p is 0.02150).")
401 ENTRY (U"2. Example of incorrect use: areal features")
402 NORMAL (U"An anonymous linguist once proposed that there was a causal relation between blood groups and the incidence "
403 "of dental fricatives. He noticed that dental fricatives occurred mainly in languages whose speakers "
404 "predominantly had blood group O. To prove his point, he tabulated 100 languages:")
405 CODE1 (U"\t\t\tHas /θ/ or /ð/\t\tNo dental fricatives")
406 CODE1 (U"\tGroup O\t\t24\t\t11")
407 CODE1 (U"\tGroup A or B\t\t29\t\t36")
408 NORMAL (U"Since %p < 0.05, the linguist regarded his hypothesis as being supported by the facts. "
409 "However, this %χ^2 test assumes that the 100 languages are independent, but they are not. "
410 "Two adjacent languages tend to correlate in their probability of having dental fricatives, "
411 "and their speakers tend to correlate in their blood groups. Both are %%areal features%, "
412 "which undermine the independence assumed by the %χ^2 test. The actual null hypothesis "
413 "that the test rejected was the combined hypothesis that dental fricatives correlate with blood group "
414 "%and that the 100 languages are independent.")
415 NORMAL (U"Another anonymous linguist proposed that those Limburgian dialects that had lost their tone contrast "
416 "compensated this by having larger vowel inventories. He drew up a table of the dialects of 100 villages:")
417 CODE1 (U"\t\t\tHas tone\t\tHas no tone")
418 CODE1 (U"\tHas over 25 vowels\t\t10\t\t7")
419 CODE1 (U"\tHas under 25 vowels\t\t80\t\t3")
420 NORMAL (U"This result is very significant (%p < 10^^-4^), but only shows that %either there is a relation between "
421 "tone and the number of vowels %or that the dialects are not independent. And since adjacent dialects are "
422 "arguably dependent both with respect to tone and the number of vowels, the statistical significance does "
423 "not allow us to draw any conclusion about the relationship between tone and the number of vowels.")
424 ENTRY (U"3. Example of problematic use: pooling participants")
425 NORMAL (U"An anonymous student decided to do the Task A versus Task B experiment described above, "
426 "but did not let one participant perform all the 230 tasks. Instead, she let 5 participants perform 46 tasks each "
427 "(22 times task A, 24 times Task B). The pooled data were:")
428 CODE1 (U"\t\tCorrect\tIncorrect")
429 CODE1 (U"\tTask A\t71\t39")
430 CODE1 (U"\tTask B\t104\t16")
431 NORMAL (U"The resulting %p is 0.00016. So what is the conclusion, if the measurements can clearly be dependent? "
432 "Well, if the null hypothesis is that all five participants are equally good at Task A as at Task B, "
433 "then this hypothesis can be rejected. The conclusion must be that %%these five participants% have on average "
434 "more trouble with Task A than with Task B. The student incorrectly concluded, however, that Task A was "
435 "more difficult for the average population than Task B. In order to be able to draw such a conclusion, "
436 "however, a different test would be required, namely one that takes into account that the five participants "
437 "form a random sample from the total population. The simplest such test would be a sign test over "
438 "the participants: count those participants who score better on Task A than on Task B and see whether this number "
439 "is reliably less than 50 percent of all participants. For five participants, such a sign test "
440 "would %never reach significance at a two-tailed 5 percent level (2·0.5^5 = 0.0625).")
441 ENTRY (U"4. Example of problematic use: pooling participants")
442 NORMAL (U"Our purpose was to disprove the null hypothesis that listeners' perception does not depend on the language "
443 "they think they hear. However, certain vowel tokens acoustically in between the Dutch /ɑ/ and the Dutch /ɔ/ "
444 "were perceived 50 percent of the time as /ɑ/ and 50 percent of the time as /ɔ/ when Dutch learners of Spanish thought "
445 "they were hearing Dutch, but 60 percent of the time as /ɔ/ when they thought they were hearing Spanish. "
446 "The responses of 40 listeners, all of whom underwent both language modes, is combined in the following table:")
447 CODE1 (U"\t\t/ɑ/\t/ɔ/")
448 CODE1 (U"\tDutch mode\t200\t200")
449 CODE1 (U"\tSpanish mode\t160\t240")
450 NORMAL (U"The result was %p = 0.0056, which reliably showed that these 40 listeners on average shifted their category "
451 "boundary toward /ɑ/ when they thought that the language they were listening to was Spanish. "
452 "The conclusion is that not all listeners were indifferent to the language mode, "
453 "so that mode-dependent perception must exist. The explanation in this case was that the Spanish /a/ "
454 "(which Dutch learners of Spanish identify with their /ɑ/) is more auditorily front than Dutch /ɑ/; "
455 "in order to reject the null hypothesis that language modes exist but that their direction is random for each "
456 "learner, i.e. the population average of the shift is zero, a separate test was required to show that the observed "
457 "shift is representative of the population of Dutch learners of Spanish "
458 "(this is easier to accomplish for 40 participants than for 5).")
459 MAN_END
460
461 MAN_BEGIN (U"Logistic regression", U"ppgb", 20141001)
462 INTRO (U"This page explains how you do logistic regression with Praat. "
463 "You start by saving a table in a text file (if it contains non-ASCII symbols such as æ or ɛ, "
464 "use the UTF-8 or UTF-16 format). "
465 "The following example contains natural stimuli (female speaker) with measured F1 and duration values, "
466 "and the responses of a certain listener who is presented each stimulus 10 times.")
467 CODE1 (U" F1 Dur /æ/ /ɛ/")
468 CODE1 (U" 764 87 2 8")
469 CODE1 (U" 674 104 3 7")
470 CODE1 (U" 574 126 0 10")
471 CODE1 (U" 566 93 1 9")
472 CODE1 (U" 618 118 1 9")
473 CODE1 (U"1025 147 10 0")
474 CODE1 (U" 722 117 7 3")
475 CODE1 (U" 696 169 9 1")
476 CODE1 (U"1024 124 10 0")
477 CODE1 (U" 752 92 6 4")
478 NORMAL (U"In this table we see 10 different stimuli, each characterized by a certain combination "
479 "of the factors (independent variables) %F1 (first formant in Hertz) and %Dur (duration in milliseconds). "
480 "The first row of the table means that there was a stimulus with an F1 of 764 Hz and a duration of 87 ms, "
481 "and that the listener responded to this stimulus 2 times with the response category /æ/, "
482 "and the remaining 8 times with the category /ɛ/.")
483 NORMAL (U"A table as above can be typed into a text file. The columns can be separated with spaces and/or tab stops. "
484 "The file can be read into Praat with ##Read Table from table file...#. "
485 "The command ##To logistic regression...# will become available in the #Statistics menu.")
486 ENTRY (U"What does it do?")
487 /*SCRIPT (4.5, 4,
488 "Axes... 60 180 900 500\n"
489 "Marks bottom every... 1 30 yes yes no\n"
490 "Marks left every... 1 50 yes yes no\n"
491 "Text bottom... yes Duration (ms)\n"
492 "Text left... yes F1 (Hz)\n"
493 "mdur_ae = 135\n"
494 "mdur_ep = 95\n"
495 "sdur = 25\n"
496 "mf1_ae = 780\n"
497 "mf1_ep = 620\n"
498 "sf1 = 60\n"
499 "Draw ellipse... mdur_ae-sdur mdur_ae+sdur mf1_ae-sf1 mf1_ae+sf1\n"
500 "Text... mdur_ae Centre mf1_ae Half /æ/\n"
501 "Draw ellipse... mdur_ep-sdur mdur_ep+sdur mf1_ep-sf1 mf1_ep+sf1\n"
502 "Text... mdur_ep Centre mf1_ep Half /ɛ/\n"
503 "Draw inner box\n"
504 )*/
505 NORMAL (U"The logistic regression method will find values %α, %%β__F1_% and %%β__dur_% "
506 "that optimize")
507 EQUATION (U"%α + %β__%F1_ %F1_%k + %β__%dur_ %Dur_%k = ln (%p_%k(/ɛ/)/%p_%k(/æ/))")
508 NORMAL (U"where %k runs from 1 to 10, and %p_%k(/æ/) + %p_%k(/ɛ/) = 1.")
509 NORMAL (U"The optimization criterion is %%maximum likelihood%, i.e. those %α, %β__%F1_ and %β__%dur_ "
510 "will be chosen that lead to values for %p_%k(/æ/) and %p_%k(/ɛ/) that make the observations in the table "
511 "most likely.")
512 NORMAL (U"Praat will create an object of type #LogisticRegression in the list. "
513 "When you then click the #Info button, Praat will write the values of %α (the %intercept), "
514 "%β__%F1_ and %β__%dur_ into the Info window (as well as much other information).")
515 NORMAL (U"The number of factors does not have to be 2; it can be 1 or more. "
516 "The number of dependent categories is always 2.")
517 MAN_END
518
519 }
520
521 /* End of file manual_statistics.cpp */