tpattern 0.1.13__tar.gz → 0.1.14__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. {tpattern-0.1.13/tpattern.egg-info → tpattern-0.1.14}/PKG-INFO +105 -25
  2. {tpattern-0.1.13 → tpattern-0.1.14}/README.md +104 -24
  3. {tpattern-0.1.13 → tpattern-0.1.14}/pyproject.toml +1 -1
  4. {tpattern-0.1.13 → tpattern-0.1.14}/tpattern/__init__.py +1 -1
  5. {tpattern-0.1.13 → tpattern-0.1.14/tpattern.egg-info}/PKG-INFO +105 -25
  6. {tpattern-0.1.13 → tpattern-0.1.14}/LICENSE +0 -0
  7. {tpattern-0.1.13 → tpattern-0.1.14}/setup.cfg +0 -0
  8. {tpattern-0.1.13 → tpattern-0.1.14}/tests/test_calibrated_pins.py +0 -0
  9. {tpattern-0.1.13 → tpattern-0.1.14}/tests/test_contrast.py +0 -0
  10. {tpattern-0.1.13 → tpattern-0.1.14}/tests/test_dedup.py +0 -0
  11. {tpattern-0.1.13 → tpattern-0.1.14}/tests/test_guided.py +0 -0
  12. {tpattern-0.1.13 → tpattern-0.1.14}/tests/test_null_compare.py +0 -0
  13. {tpattern-0.1.13 → tpattern-0.1.14}/tests/test_outputs.py +0 -0
  14. {tpattern-0.1.13 → tpattern-0.1.14}/tests/test_read_table_validation.py +0 -0
  15. {tpattern-0.1.13 → tpattern-0.1.14}/tests/test_reference.py +0 -0
  16. {tpattern-0.1.13 → tpattern-0.1.14}/tests/test_report_dendrogram.py +0 -0
  17. {tpattern-0.1.13 → tpattern-0.1.14}/tests/test_reproduction.py +0 -0
  18. {tpattern-0.1.13 → tpattern-0.1.14}/tests/test_sofcoder.py +0 -0
  19. {tpattern-0.1.13 → tpattern-0.1.14}/tests/test_starter.py +0 -0
  20. {tpattern-0.1.13 → tpattern-0.1.14}/tests/test_support_reporting.py +0 -0
  21. {tpattern-0.1.13 → tpattern-0.1.14}/tests/test_synthetic.py +0 -0
  22. {tpattern-0.1.13 → tpattern-0.1.14}/tpattern/advisor.py +0 -0
  23. {tpattern-0.1.13 → tpattern-0.1.14}/tpattern/ci.py +0 -0
  24. {tpattern-0.1.13 → tpattern-0.1.14}/tpattern/contrast.py +0 -0
  25. {tpattern-0.1.13 → tpattern-0.1.14}/tpattern/detect.py +0 -0
  26. {tpattern-0.1.13 → tpattern-0.1.14}/tpattern/diagnostics.py +0 -0
  27. {tpattern-0.1.13 → tpattern-0.1.14}/tpattern/guided.py +0 -0
  28. {tpattern-0.1.13 → tpattern-0.1.14}/tpattern/io.py +0 -0
  29. {tpattern-0.1.13 → tpattern-0.1.14}/tpattern/methods.py +0 -0
  30. {tpattern-0.1.13 → tpattern-0.1.14}/tpattern/pattern.py +0 -0
  31. {tpattern-0.1.13 → tpattern-0.1.14}/tpattern/randomise.py +0 -0
  32. {tpattern-0.1.13 → tpattern-0.1.14}/tpattern/reference.py +0 -0
  33. {tpattern-0.1.13 → tpattern-0.1.14}/tpattern/report.py +0 -0
  34. {tpattern-0.1.13 → tpattern-0.1.14}/tpattern/significance.py +0 -0
  35. {tpattern-0.1.13 → tpattern-0.1.14}/tpattern/starter.py +0 -0
  36. {tpattern-0.1.13 → tpattern-0.1.14}/tpattern/synthetic.py +0 -0
  37. {tpattern-0.1.13 → tpattern-0.1.14}/tpattern/viz.py +0 -0
  38. {tpattern-0.1.13 → tpattern-0.1.14}/tpattern.egg-info/SOURCES.txt +0 -0
  39. {tpattern-0.1.13 → tpattern-0.1.14}/tpattern.egg-info/dependency_links.txt +0 -0
  40. {tpattern-0.1.13 → tpattern-0.1.14}/tpattern.egg-info/requires.txt +0 -0
  41. {tpattern-0.1.13 → tpattern-0.1.14}/tpattern.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tpattern
3
- Version: 0.1.13
3
+ Version: 0.1.14
4
4
  Summary: Open, auditable temporal & sequential pattern analysis (T-patterns) for sport and behaviour
5
5
  Author-email: Andrew Callaway <acallaway@bournemouth.ac.uk>
6
6
  License-Expression: MIT
@@ -36,20 +36,40 @@ Dynamic: license-file
36
36
  # tpattern — open, auditable analysis of recurring patterns in event sequences
37
37
 
38
38
  [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/ajcallaway/TPattern/blob/main/colab/tpattern_guided_analysis.ipynb)
39
- [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.21397543.svg)](https://doi.org/10.5281/zenodo.21397543)
39
+ [![DOI](https://img.shields.io/badge/DOI-10.5281%2Fzenodo.21397543-1682D4.svg)](https://doi.org/10.5281/zenodo.21397543)
40
+ [![R interface](https://img.shields.io/badge/R-interface-276DC3?logo=r&logoColor=white)](#using-tpattern-from-r)
40
41
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
41
42
 
42
43
  `tpattern` detects recurring temporal patterns (T-patterns; Magnusson, 2000) in
43
44
  **any sequence of timed, labelled events** — behaviour, sport, clinical or
44
45
  physiological logs, interaction data — validates them properly against chance, and
45
46
  produces clean, publication-ready output (tables, figures, pattern dendrograms). It
46
- is a free, transparent, reproducible alternative to the THEME software, and the
47
- analysis companion to the [OpenTag.Studio](https://opentag.studio) tagging tool.
47
+ implements the published T-pattern detection algorithm (Magnusson, 2000) as free,
48
+ auditable code — the same critical-interval method the THEME software applies (see
49
+ [The method it implements](#the-method-it-implements)) — and is the analysis
50
+ companion to the [OpenTag.Studio](https://opentag.studio) tagging tool.
48
51
 
49
52
  ## Two ways to use it
50
53
 
51
- - 🚀 **Google Colab — no coding.** [**Open the guided notebook in Colab**](https://colab.research.google.com/github/ajcallaway/TPattern/blob/main/colab/tpattern_guided_analysis.ipynb): upload your events, follow the guided steps, download a report with a plain-English verdict for every pattern and a paste-ready Methods paragraph. See [`colab/`](colab/).
52
- - 🐍 **Python library.** `pip install` and script it — see [Quickstart](#quickstart) and [`examples/`](examples/).
54
+ ### 🚀 In your browser — Google Colab, no install, no coding
55
+
56
+ Open a guided notebook, upload your events CSV, and it walks you through four steps —
57
+ **upload → inspect → the recommended settings appear → run** — then hands back a full
58
+ report inline and as a downloadable zip: a colour-coded results table with a
59
+ plain-English verdict for every pattern (🟢 robust · 🟡 borderline · ⚪ likely chance),
60
+ the pattern dendrograms, the code to restyle them, and a paste-ready Methods paragraph.
61
+ No data of your own yet? Point it at [`data/worldcup_goals.csv`](data/worldcup_goals.csv)
62
+ (choose **ms** for the time unit).
63
+
64
+ Three notebooks (all in [`colab/`](colab/)):
65
+
66
+ - [**Guided analysis**](https://colab.research.google.com/github/ajcallaway/TPattern/blob/main/colab/tpattern_guided_analysis.ipynb) — **recommended.** Installs the latest `tpattern` and opens the guided panel. This is the one the badge above opens.
67
+ - **Guided analysis (offline)** — the package is bundled inside the notebook (a snapshot), so it runs where you can't install from GitHub. Open `colab/tpattern_guided_analysis_offline.ipynb` via **File → Upload notebook**.
68
+ - **Worked example** — the companion to the tutorial paper. Runs the load → inspect → recommend → calibrate → report walk-through on the shipped World Cup goal sequences, cell by cell, so you can follow the whole analysis and then swap in your own data (`colab/tpattern_worked_example.ipynb`).
69
+
70
+ ### 🐍 As a Python library
71
+
72
+ `pip install tpattern` and script it — see [Getting started](#getting-started-in-a-minute), [Quickstart](#quickstart) and [`examples/`](examples/).
53
73
 
54
74
  Bring your own data (one row per event — see [`SCHEMA.md`](SCHEMA.md)) or try the
55
75
  included [`data/`](data/) example.
@@ -108,24 +128,47 @@ print(explain("fdr_q")) # what an output column means
108
128
  - **Clean figures** — dendrograms, temporal signatures, forest plots — that share one
109
129
  customisable style (`tpattern.viz.STYLE`).
110
130
 
111
- ## Why it exists
112
-
113
- T-pattern analysis finds behaviourally meaningful structure that event counts and
114
- simple transition tables miss. It is most established through Magnusson's THEME
115
- software, the reference implementation. `tpattern` is an open, complementary
116
- implementation that reproduces THEME's detection and adds a reproducible chance
117
- model and clear reporting:
118
-
119
- - **reproduces** THEME's core detection (critical intervals, NX/T baseline,
120
- completeness competition) — validated to the pattern for published datasets;
121
- - **adds a chance model** — every pattern is tested against a surrogate null, with
122
- p-values **corrected for repeated testing** (false-discovery rate and
123
- family-wise);
124
- - **handles concurrency explicitly** — events sharing a timestamp are treated as
131
+ ## The method it implements
132
+
133
+ T-pattern analysis (Magnusson, 1996, 2000, 2019) finds behaviourally meaningful
134
+ structure that event counts and simple transition tables miss: event types that
135
+ recur in the same order, separated by statistically consistent time intervals, more
136
+ often than chance predicts. `tpattern` implements the algorithm exactly as published,
137
+ in auditable code:
138
+
139
+ - **Critical-interval detection.** For an ordered pair of event types (A, B) it
140
+ searches for the time window after A within which B follows more often than B's
141
+ overall rate would predict. Significance is the **upper-tail binomial** probability
142
+ of the observed number of A→B matches, evaluated against that baseline rate (B's
143
+ occurrences spread over the observation length — the *NX/T* baseline), thresholded
144
+ at α (default 0.005). This is the critical-interval test set out in Magnusson (2000)
145
+ and the THEME manual.
146
+ - **Free search, one-to-one matching, distinct tokens.** A free search selects the
147
+ largest significant interval; occurrences are matched one-to-one by the greedy
148
+ procedure the algorithm specifies; a pattern must be built from distinct event
149
+ tokens.
150
+ - **Bottom-up hierarchy with completeness competition.** Patterns are grown level by
151
+ level, longer patterns competing with their sub-patterns so that only the most
152
+ complete survive.
153
+
154
+ On top of the published detection, `tpattern` adds what the method has historically
155
+ lacked:
156
+
157
+ - **a proper chance model** — every detected pattern is tested against a surrogate
158
+ null, with p-values **corrected for repeated testing** (Benjamini–Hochberg FDR for
159
+ screening, Holm family-wise for confirmatory claims), stratified by level;
160
+ - **explicit concurrency handling** — events sharing a timestamp are reported as
125
161
  co-occurrence rather than sequence;
126
- - **reports clearly** — tidy tables, effect sizes with confidence intervals,
162
+ - **clear reporting** — tidy tables, effect sizes with confidence intervals,
127
163
  purposeful figures, and clean **dendrograms** of the detected patterns.
128
164
 
165
+ The reference software for this method is THEME (PatternVision Ltd), with **SOF-CODER**
166
+ (Jonsson et al., 2006) as its coding front end. `tpattern` reads that ecosystem
167
+ directly — `read_sofcoder` ingests SOF-CODER/THEME (`DATANAME, T, Events`) files — so
168
+ existing THEME datasets can be re-analysed with the surrogate calibration, and
169
+ [OpenTag.Studio](https://opentag.studio) can play, for `tpattern`, the role SOF-CODER
170
+ plays for THEME.
171
+
129
172
  ## Installation
130
173
 
131
174
  ```bash
@@ -191,6 +234,32 @@ Config()).detect()` returns them directly.
191
234
  the groups (Fisher's exact test, odds ratio + 95% CI) and feeds `forest_plot` — or run
192
235
  `new_analysis(template="two_groups")` for a ready-made script.
193
236
 
237
+ ## Using tpattern from R
238
+
239
+ R users (common in psychology and behavioural science) can drive the **same
240
+ engine** from R — the algorithm stays in Python, called through
241
+ [`reticulate`](https://rstudio.github.io/reticulate/), so results match this
242
+ package and the paper exactly. The R interface lives in [`r/`](r/):
243
+
244
+ ```r
245
+ # install.packages("remotes")
246
+ remotes::install_github("ajcallaway/TPattern", subdir = "r")
247
+
248
+ library(tpattern)
249
+ install_tpattern() # once: sets up a Python environment R can use
250
+
251
+ # the whole analysis in one call — prints what the advisor recommends,
252
+ # calibrates every pattern, writes a report, returns the table:
253
+ out <- tpattern_analysis("my_events.csv", time_unit = "ms")
254
+ out$table
255
+ ```
256
+
257
+ Or step by step: `read_events()` → `advise()` (the advisor, pulled through in
258
+ full) → `calibrate_patterns()` → `results_table()` / `tpattern_report()`, with
259
+ `explain()` for any setting and `new_analysis()` to write a commented starter
260
+ script. See [`r/README.md`](r/README.md). (CRAN release to follow, then
261
+ `install.packages("tpattern")`.)
262
+
194
263
  ## The workflow
195
264
 
196
265
  ```
@@ -252,9 +321,9 @@ pip install -e .[test]
252
321
  pytest -q
253
322
  ```
254
323
 
255
- Both the synthetic ground-truth tests and the THEME reproduction tests run
256
- everywhere — the latter check the detector still reproduces THEME's published
257
- occurrence counts to the exact N.
324
+ Both the synthetic ground-truth tests and the reproduction tests run everywhere —
325
+ the latter check the detector still reproduces the occurrence counts published for
326
+ the reference datasets to the exact N.
258
327
 
259
328
  ## Citation
260
329
 
@@ -268,12 +337,23 @@ https://doi.org/10.5281/zenodo.21397543
268
337
  This DOI is permanent and always resolves to the current release. To pin a specific
269
338
  version instead, use that release's own DOI, listed on the Zenodo record.
270
339
 
271
- And the method:
340
+ And the method it implements:
272
341
 
273
342
  Magnusson, M. S. (2000). Discovering hidden time patterns in behavior: T-patterns
274
343
  and their detection. *Behavior Research Methods, Instruments, & Computers*, 32(1),
275
344
  93–110. https://doi.org/10.3758/BF03200792
276
345
 
346
+ The reference software for the method, and its coding front end:
347
+
348
+ Magnusson, M. S. (2019). T-pattern detection and analysis (TPA) with THEME: A mixed
349
+ methods approach. *Frontiers in Psychology*, 10, 2663.
350
+ https://doi.org/10.3389/fpsyg.2019.02663
351
+
352
+ Jonsson, G. K., Anguera, M. T., Blanco-Villaseñor, Á., Losada, J. L.,
353
+ Hernández-Mendo, A., Ardá, T., Camerino, O., & Castellano, J. (2006). Hidden
354
+ patterns of play interaction in soccer using SOF-CODER. *Behavior Research Methods*,
355
+ 38(3), 372–381. https://doi.org/10.3758/BF03192790
356
+
277
357
  ## License
278
358
 
279
359
  MIT — see [`LICENSE`](LICENSE).
@@ -1,20 +1,40 @@
1
1
  # tpattern — open, auditable analysis of recurring patterns in event sequences
2
2
 
3
3
  [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/ajcallaway/TPattern/blob/main/colab/tpattern_guided_analysis.ipynb)
4
- [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.21397543.svg)](https://doi.org/10.5281/zenodo.21397543)
4
+ [![DOI](https://img.shields.io/badge/DOI-10.5281%2Fzenodo.21397543-1682D4.svg)](https://doi.org/10.5281/zenodo.21397543)
5
+ [![R interface](https://img.shields.io/badge/R-interface-276DC3?logo=r&logoColor=white)](#using-tpattern-from-r)
5
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
6
7
 
7
8
  `tpattern` detects recurring temporal patterns (T-patterns; Magnusson, 2000) in
8
9
  **any sequence of timed, labelled events** — behaviour, sport, clinical or
9
10
  physiological logs, interaction data — validates them properly against chance, and
10
11
  produces clean, publication-ready output (tables, figures, pattern dendrograms). It
11
- is a free, transparent, reproducible alternative to the THEME software, and the
12
- analysis companion to the [OpenTag.Studio](https://opentag.studio) tagging tool.
12
+ implements the published T-pattern detection algorithm (Magnusson, 2000) as free,
13
+ auditable code — the same critical-interval method the THEME software applies (see
14
+ [The method it implements](#the-method-it-implements)) — and is the analysis
15
+ companion to the [OpenTag.Studio](https://opentag.studio) tagging tool.
13
16
 
14
17
  ## Two ways to use it
15
18
 
16
- - 🚀 **Google Colab — no coding.** [**Open the guided notebook in Colab**](https://colab.research.google.com/github/ajcallaway/TPattern/blob/main/colab/tpattern_guided_analysis.ipynb): upload your events, follow the guided steps, download a report with a plain-English verdict for every pattern and a paste-ready Methods paragraph. See [`colab/`](colab/).
17
- - 🐍 **Python library.** `pip install` and script it — see [Quickstart](#quickstart) and [`examples/`](examples/).
19
+ ### 🚀 In your browser — Google Colab, no install, no coding
20
+
21
+ Open a guided notebook, upload your events CSV, and it walks you through four steps —
22
+ **upload → inspect → the recommended settings appear → run** — then hands back a full
23
+ report inline and as a downloadable zip: a colour-coded results table with a
24
+ plain-English verdict for every pattern (🟢 robust · 🟡 borderline · ⚪ likely chance),
25
+ the pattern dendrograms, the code to restyle them, and a paste-ready Methods paragraph.
26
+ No data of your own yet? Point it at [`data/worldcup_goals.csv`](data/worldcup_goals.csv)
27
+ (choose **ms** for the time unit).
28
+
29
+ Three notebooks (all in [`colab/`](colab/)):
30
+
31
+ - [**Guided analysis**](https://colab.research.google.com/github/ajcallaway/TPattern/blob/main/colab/tpattern_guided_analysis.ipynb) — **recommended.** Installs the latest `tpattern` and opens the guided panel. This is the one the badge above opens.
32
+ - **Guided analysis (offline)** — the package is bundled inside the notebook (a snapshot), so it runs where you can't install from GitHub. Open `colab/tpattern_guided_analysis_offline.ipynb` via **File → Upload notebook**.
33
+ - **Worked example** — the companion to the tutorial paper. Runs the load → inspect → recommend → calibrate → report walk-through on the shipped World Cup goal sequences, cell by cell, so you can follow the whole analysis and then swap in your own data (`colab/tpattern_worked_example.ipynb`).
34
+
35
+ ### 🐍 As a Python library
36
+
37
+ `pip install tpattern` and script it — see [Getting started](#getting-started-in-a-minute), [Quickstart](#quickstart) and [`examples/`](examples/).
18
38
 
19
39
  Bring your own data (one row per event — see [`SCHEMA.md`](SCHEMA.md)) or try the
20
40
  included [`data/`](data/) example.
@@ -73,24 +93,47 @@ print(explain("fdr_q")) # what an output column means
73
93
  - **Clean figures** — dendrograms, temporal signatures, forest plots — that share one
74
94
  customisable style (`tpattern.viz.STYLE`).
75
95
 
76
- ## Why it exists
77
-
78
- T-pattern analysis finds behaviourally meaningful structure that event counts and
79
- simple transition tables miss. It is most established through Magnusson's THEME
80
- software, the reference implementation. `tpattern` is an open, complementary
81
- implementation that reproduces THEME's detection and adds a reproducible chance
82
- model and clear reporting:
83
-
84
- - **reproduces** THEME's core detection (critical intervals, NX/T baseline,
85
- completeness competition) — validated to the pattern for published datasets;
86
- - **adds a chance model** — every pattern is tested against a surrogate null, with
87
- p-values **corrected for repeated testing** (false-discovery rate and
88
- family-wise);
89
- - **handles concurrency explicitly** — events sharing a timestamp are treated as
96
+ ## The method it implements
97
+
98
+ T-pattern analysis (Magnusson, 1996, 2000, 2019) finds behaviourally meaningful
99
+ structure that event counts and simple transition tables miss: event types that
100
+ recur in the same order, separated by statistically consistent time intervals, more
101
+ often than chance predicts. `tpattern` implements the algorithm exactly as published,
102
+ in auditable code:
103
+
104
+ - **Critical-interval detection.** For an ordered pair of event types (A, B) it
105
+ searches for the time window after A within which B follows more often than B's
106
+ overall rate would predict. Significance is the **upper-tail binomial** probability
107
+ of the observed number of A→B matches, evaluated against that baseline rate (B's
108
+ occurrences spread over the observation length — the *NX/T* baseline), thresholded
109
+ at α (default 0.005). This is the critical-interval test set out in Magnusson (2000)
110
+ and the THEME manual.
111
+ - **Free search, one-to-one matching, distinct tokens.** A free search selects the
112
+ largest significant interval; occurrences are matched one-to-one by the greedy
113
+ procedure the algorithm specifies; a pattern must be built from distinct event
114
+ tokens.
115
+ - **Bottom-up hierarchy with completeness competition.** Patterns are grown level by
116
+ level, longer patterns competing with their sub-patterns so that only the most
117
+ complete survive.
118
+
119
+ On top of the published detection, `tpattern` adds what the method has historically
120
+ lacked:
121
+
122
+ - **a proper chance model** — every detected pattern is tested against a surrogate
123
+ null, with p-values **corrected for repeated testing** (Benjamini–Hochberg FDR for
124
+ screening, Holm family-wise for confirmatory claims), stratified by level;
125
+ - **explicit concurrency handling** — events sharing a timestamp are reported as
90
126
  co-occurrence rather than sequence;
91
- - **reports clearly** — tidy tables, effect sizes with confidence intervals,
127
+ - **clear reporting** — tidy tables, effect sizes with confidence intervals,
92
128
  purposeful figures, and clean **dendrograms** of the detected patterns.
93
129
 
130
+ The reference software for this method is THEME (PatternVision Ltd), with **SOF-CODER**
131
+ (Jonsson et al., 2006) as its coding front end. `tpattern` reads that ecosystem
132
+ directly — `read_sofcoder` ingests SOF-CODER/THEME (`DATANAME, T, Events`) files — so
133
+ existing THEME datasets can be re-analysed with the surrogate calibration, and
134
+ [OpenTag.Studio](https://opentag.studio) can play, for `tpattern`, the role SOF-CODER
135
+ plays for THEME.
136
+
94
137
  ## Installation
95
138
 
96
139
  ```bash
@@ -156,6 +199,32 @@ Config()).detect()` returns them directly.
156
199
  the groups (Fisher's exact test, odds ratio + 95% CI) and feeds `forest_plot` — or run
157
200
  `new_analysis(template="two_groups")` for a ready-made script.
158
201
 
202
+ ## Using tpattern from R
203
+
204
+ R users (common in psychology and behavioural science) can drive the **same
205
+ engine** from R — the algorithm stays in Python, called through
206
+ [`reticulate`](https://rstudio.github.io/reticulate/), so results match this
207
+ package and the paper exactly. The R interface lives in [`r/`](r/):
208
+
209
+ ```r
210
+ # install.packages("remotes")
211
+ remotes::install_github("ajcallaway/TPattern", subdir = "r")
212
+
213
+ library(tpattern)
214
+ install_tpattern() # once: sets up a Python environment R can use
215
+
216
+ # the whole analysis in one call — prints what the advisor recommends,
217
+ # calibrates every pattern, writes a report, returns the table:
218
+ out <- tpattern_analysis("my_events.csv", time_unit = "ms")
219
+ out$table
220
+ ```
221
+
222
+ Or step by step: `read_events()` → `advise()` (the advisor, pulled through in
223
+ full) → `calibrate_patterns()` → `results_table()` / `tpattern_report()`, with
224
+ `explain()` for any setting and `new_analysis()` to write a commented starter
225
+ script. See [`r/README.md`](r/README.md). (CRAN release to follow, then
226
+ `install.packages("tpattern")`.)
227
+
159
228
  ## The workflow
160
229
 
161
230
  ```
@@ -217,9 +286,9 @@ pip install -e .[test]
217
286
  pytest -q
218
287
  ```
219
288
 
220
- Both the synthetic ground-truth tests and the THEME reproduction tests run
221
- everywhere — the latter check the detector still reproduces THEME's published
222
- occurrence counts to the exact N.
289
+ Both the synthetic ground-truth tests and the reproduction tests run everywhere —
290
+ the latter check the detector still reproduces the occurrence counts published for
291
+ the reference datasets to the exact N.
223
292
 
224
293
  ## Citation
225
294
 
@@ -233,12 +302,23 @@ https://doi.org/10.5281/zenodo.21397543
233
302
  This DOI is permanent and always resolves to the current release. To pin a specific
234
303
  version instead, use that release's own DOI, listed on the Zenodo record.
235
304
 
236
- And the method:
305
+ And the method it implements:
237
306
 
238
307
  Magnusson, M. S. (2000). Discovering hidden time patterns in behavior: T-patterns
239
308
  and their detection. *Behavior Research Methods, Instruments, & Computers*, 32(1),
240
309
  93–110. https://doi.org/10.3758/BF03200792
241
310
 
311
+ The reference software for the method, and its coding front end:
312
+
313
+ Magnusson, M. S. (2019). T-pattern detection and analysis (TPA) with THEME: A mixed
314
+ methods approach. *Frontiers in Psychology*, 10, 2663.
315
+ https://doi.org/10.3389/fpsyg.2019.02663
316
+
317
+ Jonsson, G. K., Anguera, M. T., Blanco-Villaseñor, Á., Losada, J. L.,
318
+ Hernández-Mendo, A., Ardá, T., Camerino, O., & Castellano, J. (2006). Hidden
319
+ patterns of play interaction in soccer using SOF-CODER. *Behavior Research Methods*,
320
+ 38(3), 372–381. https://doi.org/10.3758/BF03192790
321
+
242
322
  ## License
243
323
 
244
324
  MIT — see [`LICENSE`](LICENSE).
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "tpattern"
7
- version = "0.1.13"
7
+ version = "0.1.14"
8
8
  description = "Open, auditable temporal & sequential pattern analysis (T-patterns) for sport and behaviour"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -6,7 +6,7 @@ behavior: T-patterns and their detection. Behavior Research Methods,
6
6
  Instruments, & Computers, 32(1), 93-110.
7
7
  """
8
8
 
9
- __version__ = "0.1.13" # defined before submodule imports (methods.py reads it)
9
+ __version__ = "0.1.14" # defined before submodule imports (methods.py reads it)
10
10
 
11
11
  from .io import (Observation, read_observation, read_sample, read_table,
12
12
  read_sofcoder, DataFormatError, check_reference, CHECKS)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tpattern
3
- Version: 0.1.13
3
+ Version: 0.1.14
4
4
  Summary: Open, auditable temporal & sequential pattern analysis (T-patterns) for sport and behaviour
5
5
  Author-email: Andrew Callaway <acallaway@bournemouth.ac.uk>
6
6
  License-Expression: MIT
@@ -36,20 +36,40 @@ Dynamic: license-file
36
36
  # tpattern — open, auditable analysis of recurring patterns in event sequences
37
37
 
38
38
  [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/ajcallaway/TPattern/blob/main/colab/tpattern_guided_analysis.ipynb)
39
- [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.21397543.svg)](https://doi.org/10.5281/zenodo.21397543)
39
+ [![DOI](https://img.shields.io/badge/DOI-10.5281%2Fzenodo.21397543-1682D4.svg)](https://doi.org/10.5281/zenodo.21397543)
40
+ [![R interface](https://img.shields.io/badge/R-interface-276DC3?logo=r&logoColor=white)](#using-tpattern-from-r)
40
41
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
41
42
 
42
43
  `tpattern` detects recurring temporal patterns (T-patterns; Magnusson, 2000) in
43
44
  **any sequence of timed, labelled events** — behaviour, sport, clinical or
44
45
  physiological logs, interaction data — validates them properly against chance, and
45
46
  produces clean, publication-ready output (tables, figures, pattern dendrograms). It
46
- is a free, transparent, reproducible alternative to the THEME software, and the
47
- analysis companion to the [OpenTag.Studio](https://opentag.studio) tagging tool.
47
+ implements the published T-pattern detection algorithm (Magnusson, 2000) as free,
48
+ auditable code — the same critical-interval method the THEME software applies (see
49
+ [The method it implements](#the-method-it-implements)) — and is the analysis
50
+ companion to the [OpenTag.Studio](https://opentag.studio) tagging tool.
48
51
 
49
52
  ## Two ways to use it
50
53
 
51
- - 🚀 **Google Colab — no coding.** [**Open the guided notebook in Colab**](https://colab.research.google.com/github/ajcallaway/TPattern/blob/main/colab/tpattern_guided_analysis.ipynb): upload your events, follow the guided steps, download a report with a plain-English verdict for every pattern and a paste-ready Methods paragraph. See [`colab/`](colab/).
52
- - 🐍 **Python library.** `pip install` and script it — see [Quickstart](#quickstart) and [`examples/`](examples/).
54
+ ### 🚀 In your browser — Google Colab, no install, no coding
55
+
56
+ Open a guided notebook, upload your events CSV, and it walks you through four steps —
57
+ **upload → inspect → the recommended settings appear → run** — then hands back a full
58
+ report inline and as a downloadable zip: a colour-coded results table with a
59
+ plain-English verdict for every pattern (🟢 robust · 🟡 borderline · ⚪ likely chance),
60
+ the pattern dendrograms, the code to restyle them, and a paste-ready Methods paragraph.
61
+ No data of your own yet? Point it at [`data/worldcup_goals.csv`](data/worldcup_goals.csv)
62
+ (choose **ms** for the time unit).
63
+
64
+ Three notebooks (all in [`colab/`](colab/)):
65
+
66
+ - [**Guided analysis**](https://colab.research.google.com/github/ajcallaway/TPattern/blob/main/colab/tpattern_guided_analysis.ipynb) — **recommended.** Installs the latest `tpattern` and opens the guided panel. This is the one the badge above opens.
67
+ - **Guided analysis (offline)** — the package is bundled inside the notebook (a snapshot), so it runs where you can't install from GitHub. Open `colab/tpattern_guided_analysis_offline.ipynb` via **File → Upload notebook**.
68
+ - **Worked example** — the companion to the tutorial paper. Runs the load → inspect → recommend → calibrate → report walk-through on the shipped World Cup goal sequences, cell by cell, so you can follow the whole analysis and then swap in your own data (`colab/tpattern_worked_example.ipynb`).
69
+
70
+ ### 🐍 As a Python library
71
+
72
+ `pip install tpattern` and script it — see [Getting started](#getting-started-in-a-minute), [Quickstart](#quickstart) and [`examples/`](examples/).
53
73
 
54
74
  Bring your own data (one row per event — see [`SCHEMA.md`](SCHEMA.md)) or try the
55
75
  included [`data/`](data/) example.
@@ -108,24 +128,47 @@ print(explain("fdr_q")) # what an output column means
108
128
  - **Clean figures** — dendrograms, temporal signatures, forest plots — that share one
109
129
  customisable style (`tpattern.viz.STYLE`).
110
130
 
111
- ## Why it exists
112
-
113
- T-pattern analysis finds behaviourally meaningful structure that event counts and
114
- simple transition tables miss. It is most established through Magnusson's THEME
115
- software, the reference implementation. `tpattern` is an open, complementary
116
- implementation that reproduces THEME's detection and adds a reproducible chance
117
- model and clear reporting:
118
-
119
- - **reproduces** THEME's core detection (critical intervals, NX/T baseline,
120
- completeness competition) — validated to the pattern for published datasets;
121
- - **adds a chance model** — every pattern is tested against a surrogate null, with
122
- p-values **corrected for repeated testing** (false-discovery rate and
123
- family-wise);
124
- - **handles concurrency explicitly** — events sharing a timestamp are treated as
131
+ ## The method it implements
132
+
133
+ T-pattern analysis (Magnusson, 1996, 2000, 2019) finds behaviourally meaningful
134
+ structure that event counts and simple transition tables miss: event types that
135
+ recur in the same order, separated by statistically consistent time intervals, more
136
+ often than chance predicts. `tpattern` implements the algorithm exactly as published,
137
+ in auditable code:
138
+
139
+ - **Critical-interval detection.** For an ordered pair of event types (A, B) it
140
+ searches for the time window after A within which B follows more often than B's
141
+ overall rate would predict. Significance is the **upper-tail binomial** probability
142
+ of the observed number of A→B matches, evaluated against that baseline rate (B's
143
+ occurrences spread over the observation length — the *NX/T* baseline), thresholded
144
+ at α (default 0.005). This is the critical-interval test set out in Magnusson (2000)
145
+ and the THEME manual.
146
+ - **Free search, one-to-one matching, distinct tokens.** A free search selects the
147
+ largest significant interval; occurrences are matched one-to-one by the greedy
148
+ procedure the algorithm specifies; a pattern must be built from distinct event
149
+ tokens.
150
+ - **Bottom-up hierarchy with completeness competition.** Patterns are grown level by
151
+ level, longer patterns competing with their sub-patterns so that only the most
152
+ complete survive.
153
+
154
+ On top of the published detection, `tpattern` adds what the method has historically
155
+ lacked:
156
+
157
+ - **a proper chance model** — every detected pattern is tested against a surrogate
158
+ null, with p-values **corrected for repeated testing** (Benjamini–Hochberg FDR for
159
+ screening, Holm family-wise for confirmatory claims), stratified by level;
160
+ - **explicit concurrency handling** — events sharing a timestamp are reported as
125
161
  co-occurrence rather than sequence;
126
- - **reports clearly** — tidy tables, effect sizes with confidence intervals,
162
+ - **clear reporting** — tidy tables, effect sizes with confidence intervals,
127
163
  purposeful figures, and clean **dendrograms** of the detected patterns.
128
164
 
165
+ The reference software for this method is THEME (PatternVision Ltd), with **SOF-CODER**
166
+ (Jonsson et al., 2006) as its coding front end. `tpattern` reads that ecosystem
167
+ directly — `read_sofcoder` ingests SOF-CODER/THEME (`DATANAME, T, Events`) files — so
168
+ existing THEME datasets can be re-analysed with the surrogate calibration, and
169
+ [OpenTag.Studio](https://opentag.studio) can play, for `tpattern`, the role SOF-CODER
170
+ plays for THEME.
171
+
129
172
  ## Installation
130
173
 
131
174
  ```bash
@@ -191,6 +234,32 @@ Config()).detect()` returns them directly.
191
234
  the groups (Fisher's exact test, odds ratio + 95% CI) and feeds `forest_plot` — or run
192
235
  `new_analysis(template="two_groups")` for a ready-made script.
193
236
 
237
+ ## Using tpattern from R
238
+
239
+ R users (common in psychology and behavioural science) can drive the **same
240
+ engine** from R — the algorithm stays in Python, called through
241
+ [`reticulate`](https://rstudio.github.io/reticulate/), so results match this
242
+ package and the paper exactly. The R interface lives in [`r/`](r/):
243
+
244
+ ```r
245
+ # install.packages("remotes")
246
+ remotes::install_github("ajcallaway/TPattern", subdir = "r")
247
+
248
+ library(tpattern)
249
+ install_tpattern() # once: sets up a Python environment R can use
250
+
251
+ # the whole analysis in one call — prints what the advisor recommends,
252
+ # calibrates every pattern, writes a report, returns the table:
253
+ out <- tpattern_analysis("my_events.csv", time_unit = "ms")
254
+ out$table
255
+ ```
256
+
257
+ Or step by step: `read_events()` → `advise()` (the advisor, pulled through in
258
+ full) → `calibrate_patterns()` → `results_table()` / `tpattern_report()`, with
259
+ `explain()` for any setting and `new_analysis()` to write a commented starter
260
+ script. See [`r/README.md`](r/README.md). (CRAN release to follow, then
261
+ `install.packages("tpattern")`.)
262
+
194
263
  ## The workflow
195
264
 
196
265
  ```
@@ -252,9 +321,9 @@ pip install -e .[test]
252
321
  pytest -q
253
322
  ```
254
323
 
255
- Both the synthetic ground-truth tests and the THEME reproduction tests run
256
- everywhere — the latter check the detector still reproduces THEME's published
257
- occurrence counts to the exact N.
324
+ Both the synthetic ground-truth tests and the reproduction tests run everywhere —
325
+ the latter check the detector still reproduces the occurrence counts published for
326
+ the reference datasets to the exact N.
258
327
 
259
328
  ## Citation
260
329
 
@@ -268,12 +337,23 @@ https://doi.org/10.5281/zenodo.21397543
268
337
  This DOI is permanent and always resolves to the current release. To pin a specific
269
338
  version instead, use that release's own DOI, listed on the Zenodo record.
270
339
 
271
- And the method:
340
+ And the method it implements:
272
341
 
273
342
  Magnusson, M. S. (2000). Discovering hidden time patterns in behavior: T-patterns
274
343
  and their detection. *Behavior Research Methods, Instruments, & Computers*, 32(1),
275
344
  93–110. https://doi.org/10.3758/BF03200792
276
345
 
346
+ The reference software for the method, and its coding front end:
347
+
348
+ Magnusson, M. S. (2019). T-pattern detection and analysis (TPA) with THEME: A mixed
349
+ methods approach. *Frontiers in Psychology*, 10, 2663.
350
+ https://doi.org/10.3389/fpsyg.2019.02663
351
+
352
+ Jonsson, G. K., Anguera, M. T., Blanco-Villaseñor, Á., Losada, J. L.,
353
+ Hernández-Mendo, A., Ardá, T., Camerino, O., & Castellano, J. (2006). Hidden
354
+ patterns of play interaction in soccer using SOF-CODER. *Behavior Research Methods*,
355
+ 38(3), 372–381. https://doi.org/10.3758/BF03192790
356
+
277
357
  ## License
278
358
 
279
359
  MIT — see [`LICENSE`](LICENSE).
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes