| Title: | Pattern Estimation and Identification for Dyadic Sequences Using Transition Matrices in R |
|---|---|
| Description: | Provides methods for analyzing categorical dyadic sequences using transition matrices within the Longitudinal Actor-Partner Interdependence Model and Markov-chain framework. The package supports empirical transition counts, maximum likelihood estimation of transition probabilities, and identification of univariate and bivariate patterns of interaction in dyadic sequences. |
| Authors: | Mattia Böllenrücher [aut, cre, cph] (ORCID: <https://orcid.org/0009-0004-4149-4745>), Mégane Bollenrücher [aut] (ORCID: <https://orcid.org/0000-0002-9035-8799>), Jean-Philippe Antonietti [aut] (ORCID: <https://orcid.org/0000-0003-0117-4769>) |
| Maintainer: | Mattia Böllenrücher <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.3.9000 |
| Built: | 2026-09-21 12:55:25 UTC |
| Source: | https://github.com/BoellenruecherM/dyadicMarkov-public |
Identifies the bivariate case as "trivial", "univariate",
"partial", or "complete" using two chi-squared tests
against constrained binary bivariate structures.
bivariateCase(empirical, alpha = 0.05)bivariateCase(empirical, alpha = 0.05)
empirical |
A numeric matrix with 16 rows and 2 columns containing
finite non-negative counts, as returned by
|
alpha |
A single number in (0, 1) giving the significance level. Default is 0.05. |
The returned case corresponds to the global approach of the
binary bivariate method. The scientific method treats the global
comparisons as nested-model comparisons within a likelihood-ratio test
(LRT) framework. bivariateCase() implements the two chi-squared
tests for the A1 and B1 comparisons. dyadicMarkov evaluates these tests
using Pearson's chi-squared statistic,
where and are the empirical and theoretical transition
counts. A global comparison is treated as rejected when
. The result determines whether the sequence analyzed is
treated as trivial, univariate, partial bivariate, or complete bivariate before the
separate local AIC-based identification of the pattern of interaction.
A list with class c("dyadic_case", "list") containing
components testUnivariate, testPartial, case, and
metadata fields alpha and call. It remains usable as an
ordinary list. When empirical was created by
countEmpBivariate(), its stored sequence metadata is propagated so
that plot() can display the four observed state strips.
chainFM_V1 <- c(1L, 2L, 1L, 2L, 2L, 1L) chainSM_V1 <- c(2L, 1L, 2L, 1L, 1L, 2L) chainFM_V2 <- c(1L, 1L, 2L, 2L, 1L, 2L) chainSM_V2 <- c(2L, 2L, 1L, 1L, 2L, 1L) emp <- countEmpBivariate( chainFM_V1, chainSM_V1, chainFM_V2, chainSM_V2, states = 2L ) bivariateCase(emp, alpha = 0.05)chainFM_V1 <- c(1L, 2L, 1L, 2L, 2L, 1L) chainSM_V1 <- c(2L, 1L, 2L, 1L, 1L, 2L) chainFM_V2 <- c(1L, 1L, 2L, 2L, 1L, 2L) chainSM_V2 <- c(2L, 2L, 1L, 1L, 2L, 1L) emp <- countEmpBivariate( chainFM_V1, chainSM_V1, chainFM_V2, chainSM_V2, states = 2L ) bivariateCase(emp, alpha = 0.05)
Compares the complete bivariate patterns C, D1–D4, and E1–E4 using AIC and returns the selected pattern.
completePattern(empirical)completePattern(empirical)
empirical |
A numeric matrix with 16 rows and 2 columns containing
finite non-negative counts, as returned by
|
Conditional on the complete bivariate case, the G-squared deviance is computed for each C, D1–D4, and E1–E4 candidate before calculating
where
The candidate with the smallest AIC is selected. If candidates have exactly equal AIC values, the first candidate in the documented comparison order is selected.
A list with class c("dyadic_pattern", "list") containing
components aic (a data frame with columns pattern,
matrix, and aic), pattern (the selected pattern
label), and call. It remains usable as an ordinary list. When
empirical was created by countEmpBivariate(), its stored
sequence metadata is propagated so that plot() can display the four
observed state strips.
chainFM_V1 <- c(1L, 2L, 1L, 2L, 2L, 1L) chainSM_V1 <- c(2L, 1L, 2L, 1L, 1L, 2L) chainFM_V2 <- c(1L, 1L, 2L, 2L, 1L, 2L) chainSM_V2 <- c(2L, 2L, 1L, 1L, 2L, 1L) emp <- countEmpBivariate( chainFM_V1, chainSM_V1, chainFM_V2, chainSM_V2, states = 2L ) completePattern(emp)chainFM_V1 <- c(1L, 2L, 1L, 2L, 2L, 1L) chainSM_V1 <- c(2L, 1L, 2L, 1L, 1L, 2L) chainFM_V2 <- c(1L, 1L, 2L, 2L, 1L, 2L) chainSM_V2 <- c(2L, 2L, 1L, 1L, 2L, 1L) emp <- countEmpBivariate( chainFM_V1, chainSM_V1, chainFM_V2, chainSM_V2, states = 2L ) completePattern(emp)
Computes empirical transition counts for the sequences of the first and second member. Rows correspond to dyadic states of the two members, and columns correspond to the state of the first member at the next time point.
countEmp(chainFM, chainSM, states)countEmp(chainFM, chainSM, states)
chainFM |
Numeric vector of integer-valued observed states for the first
member (FM). Must have the same length as |
chainSM |
Numeric vector of integer-valued observed states for the second
member (SM). Must have the same length as |
states |
A single positive integer greater than or equal to 2 giving the number of states. |
Rows correspond to current dyadic states .
For general states, the row index is computed as
1 + states * (FM_t - 1) + (SM_t - 1). Columns correspond to the
state of the first member at the next time point, .
An integer matrix with class
c("dyadic_counts", "matrix", "array"),
with rows and states columns. It remains usable as an
ordinary matrix. print(), summary(), and utils::toLatex() methods are
available for this result.
chainFM <- c(1L, 2L, 1L, 2L, 2L, 1L) chainSM <- c(2L, 1L, 2L, 1L, 1L, 2L) countEmp(chainFM, chainSM, states = 2L)chainFM <- c(1L, 2L, 1L, 2L, 2L, 1L) chainSM <- c(2L, 1L, 2L, 1L, 1L, 2L) countEmp(chainFM, chainSM, states = 2L)
Computes empirical transition counts for bivariate categorical dyadic
sequences with two variables. This function currently supports
states = 2 only.
countEmpBivariate(chainFM_V1, chainSM_V1, chainFM_V2, chainSM_V2, states = 2L)countEmpBivariate(chainFM_V1, chainSM_V1, chainFM_V2, chainSM_V2, states = 2L)
chainFM_V1 |
Numeric vector of observed states for variable 1 for the first member. Values must be either 1 or 2, and the vector must have the same length as the other three chain vectors. |
chainSM_V1 |
Numeric vector of observed states for variable 1 for the second member. Values must be either 1 or 2, and the vector must have the same length as the other three chain vectors. |
chainFM_V2 |
Numeric vector of observed states for variable 2 for the first member. Values must be either 1 or 2, and the vector must have the same length as the other three chain vectors. |
chainSM_V2 |
Numeric vector of observed states for variable 2 for the second member. Values must be either 1 or 2, and the vector must have the same length as the other three chain vectors. |
states |
A single integer equal to 2. Other state counts are not currently supported. Default is 2. |
The bivariate counter currently supports states = 2 only.
Rows represent the previous dyadic states of variable 1 and variable 2.
Writing for the number of states, the row index at time is
Columns correspond to
the state of the first member on variable 1 at the next time point,
.
An integer matrix with class
c("dyadic_counts", "matrix", "array") with 16 rows and 2 columns
when states = 2. It remains usable as an ordinary matrix. The four
validated input sequences and the binary state count are retained in the
"dyadic_sequences" attribute so that downstream bivariate results
can display the observed state strips with plot().
chainFM_V1 <- c(1L, 2L, 1L, 2L, 2L, 1L) chainSM_V1 <- c(2L, 1L, 2L, 1L, 1L, 2L) chainFM_V2 <- c(1L, 1L, 2L, 2L, 1L, 2L) chainSM_V2 <- c(2L, 2L, 1L, 1L, 2L, 1L) emp <- countEmpBivariate( chainFM_V1, chainSM_V1, chainFM_V2, chainSM_V2, states = 2L ) dim(emp)chainFM_V1 <- c(1L, 2L, 1L, 2L, 2L, 1L) chainSM_V1 <- c(2L, 1L, 2L, 1L, 1L, 2L) chainFM_V2 <- c(1L, 1L, 2L, 2L, 1L, 2L) chainSM_V2 <- c(2L, 2L, 1L, 1L, 2L, 1L) emp <- countEmpBivariate( chainFM_V1, chainSM_V1, chainFM_V2, chainSM_V2, states = 2L ) dim(emp)
A synthetic bivariate dyadic sequence with 90 observations, designed for package workflow examples.
dyadic_bivariate_exampledyadic_bivariate_example
A data frame with 90 rows and 5 columns:
Index of the measurement occasion.
Integer variable 1 state for the first member, taking values 1 or 2.
Integer variable 1 state for the second member, taking values 1 or 2.
Integer variable 2 state for the first member, taking values 1 or 2.
Integer variable 2 state for the second member, taking values 1 or 2.
The bivariate workflow classifies this example as complete
using bivariateCase with alpha = 0.05. The complete
bivariate pattern selected by completePattern is D2.
A synthetic dyadic sequence with 90 observations, designed for package workflow examples.
dyadic_univariate_exampledyadic_univariate_example
A data frame with 90 rows and 3 columns:
Index of the measurement occasion.
Integer state for the first member, taking values 1 or 2.
Integer state for the second member, taking values 1 or 2.
The package workflow classifies this example as PM (A3)
using univariatePattern with states = 2.
Estimates transition probabilities by maximum likelihood from an empirical
count matrix returned by countEmp or
countEmpBivariate.
mleEstimation(empirical)mleEstimation(empirical)
empirical |
An empirical count matrix. |
Each row of empirical is normalized independently. Rows with
zero total count are assigned a uniform probability vector, so each row of
the returned matrix sums to one.
A numeric matrix with class
c("dyadic_mle", "matrix", "array")
containing estimated transition probabilities with the same dimensions as
empirical. It remains usable as an ordinary matrix.
print(), summary(), and utils::toLatex() methods are available for
this result.
chainFM <- c(1L, 2L, 1L, 2L, 2L, 1L) chainSM <- c(2L, 1L, 2L, 1L, 1L, 2L) emp <- countEmp(chainFM, chainSM, states = 2L) mleEstimation(emp)chainFM <- c(1L, 2L, 1L, 2L, 2L, 1L) chainSM <- c(2L, 1L, 2L, 1L, 1L, 2L) emp <- countEmp(chainFM, chainSM, states = 2L) mleEstimation(emp)
Compares the partial bivariate patterns B1, B2, and B3 using AIC and returns the selected pattern.
partialPattern(empirical)partialPattern(empirical)
empirical |
A numeric matrix with 16 rows and 2 columns containing
finite non-negative counts, as returned by
|
Conditional on the partial bivariate case, the G-squared deviance is computed for each B1, B2, and B3 candidate before calculating
where
The candidate with the smallest AIC is selected. If candidates have exactly equal AIC values, the first candidate in the documented comparison order is selected.
A list with class c("dyadic_pattern", "list") containing
components aic (a data frame with candidate patterns and AIC
values), pattern (the selected pattern label), and call. It
remains usable as an ordinary list. When empirical was created by
countEmpBivariate(), its stored sequence metadata is propagated so
that plot() can display the four observed state strips.
chainFM_V1 <- c(1L, 2L, 1L, 2L, 2L, 1L) chainSM_V1 <- c(2L, 1L, 2L, 1L, 1L, 2L) chainFM_V2 <- c(1L, 1L, 2L, 2L, 1L, 2L) chainSM_V2 <- c(2L, 2L, 1L, 1L, 2L, 1L) emp <- countEmpBivariate( chainFM_V1, chainSM_V1, chainFM_V2, chainSM_V2, states = 2L ) partialPattern(emp)chainFM_V1 <- c(1L, 2L, 1L, 2L, 2L, 1L) chainSM_V1 <- c(2L, 1L, 2L, 1L, 1L, 2L) chainFM_V2 <- c(1L, 1L, 2L, 2L, 1L, 2L) chainSM_V2 <- c(2L, 2L, 1L, 1L, 2L, 1L) emp <- countEmpBivariate( chainFM_V1, chainSM_V1, chainFM_V2, chainSM_V2, states = 2L ) partialPattern(emp)
Displays each categorical sequence retained by a dyadicMarkov result as a horizontal state strip. A strip consists of adjacent coloured intervals: each interval represents one measurement occasion, and its colour identifies the observed state. Consecutive occasions in the same state therefore form a continuous run. Vertical position identifies the member and, for bivariate results, the variable.
## S3 method for class 'dyadic_pattern' plot(x, col = NULL, main = NULL, cex = NULL, ...) ## S3 method for class 'dyadic_case' plot(x, col = NULL, main = NULL, cex = NULL, ...)## S3 method for class 'dyadic_pattern' plot(x, col = NULL, main = NULL, cex = NULL, ...) ## S3 method for class 'dyadic_case' plot(x, col = NULL, main = NULL, cex = NULL, ...)
x |
A |
col |
Character vector containing exactly one distinct,
non-fully-transparent colour per state, or |
main |
Optional main title. If |
cex |
Optional positive text scaling factor. If |
... |
Additional arguments are not currently supported. |
Univariate results contain two strips, one for each member, and support any
integer . Bivariate results contain four strips for
the two members on the main and second variables; the currently developed bivariate
method supports states = 2 only. The plot displays observed sequences, not
fitted probabilities or inferred dependency structures. Statistical
identification results remain available through print() and summary().
Invisibly returns the validated plotting specification used to draw the state strips.
Tueller, S. J., Van Dorn, R. A., and Bobashev, G. V. (2016). Visualization of categorical longitudinal and time series data. Methods Report RTI Press, 2016. doi:10.3768/rtipress.2016.mr.0033.1602.
chainFM <- c(1L, 2L, 1L, 2L, 2L, 1L) chainSM <- c(2L, 1L, 2L, 1L, 1L, 2L) univariate <- univariatePattern( chainFM, chainSM, states = 2L ) plot(univariate) chainFM_V2 <- c(1L, 1L, 2L, 2L, 1L, 2L) chainSM_V2 <- c(2L, 2L, 1L, 1L, 2L, 1L) empirical <- countEmpBivariate( chainFM, chainSM, chainFM_V2, chainSM_V2, states = 2L ) bivariate <- bivariateCase(empirical) plot(bivariate)chainFM <- c(1L, 2L, 1L, 2L, 2L, 1L) chainSM <- c(2L, 1L, 2L, 1L, 1L, 2L) univariate <- univariatePattern( chainFM, chainSM, states = 2L ) plot(univariate) chainFM_V2 <- c(1L, 1L, 2L, 2L, 1L, 2L) chainSM_V2 <- c(2L, 2L, 1L, 1L, 2L, 1L) empirical <- countEmpBivariate( chainFM, chainSM, chainFM_V2, chainSM_V2, states = 2L ) bivariate <- bivariateCase(empirical) plot(bivariate)
Fixed archived simulation datasets used in the sensitivity-analysis vignette for sequence lengths 30, 60, 90, 180, and 720. The datasets contain binary bivariate dyadic sequences and are re-analysed by the current package; they are not re-simulated during package use or testing.
Each object is a data frame with 4,000 rows, representing 1,000 dyads
observed for two members and two variables. The columns TM1, ...,
TMn contain the simulated binary states for the corresponding
sequence length. The remaining columns are members, variable,
caseSimulated, dyad, and local. The five datasets were
simulated separately for sequence lengths 30, 60, 90, 180, and 720 and are
therefore not nested prefixes of one another. The caseSimulated
column records the interaction pattern used to simulate each member-variable
sequence, whereas local records the archived classification produced
by the historical analysis. Historical terminology is retained in these
fixed simulation datasets; current package output uses the current
scientific nomenclature.
Computes empirical transition counts, estimates transition probabilities by maximum likelihood, and performs likelihood-ratio tests against the actor-only and partner-only constrained models to identify the univariate pattern of interaction.
univariatePattern(chainFM, chainSM, states, alpha = 0.05)univariatePattern(chainFM, chainSM, states, alpha = 0.05)
chainFM |
Numeric vector of observed states for the first member (FM).
Values must be integers. Must have the same length as |
chainSM |
Numeric vector of observed states for the second member (SM).
Values must be integers. Must have the same length as |
states |
A single positive integer greater than or equal to 2 giving the number of states. |
alpha |
A single number in (0, 1) giving the significance level. Default is 0.05. |
The nested full/restricted comparisons form the univariate likelihood-ratio test (LRT) procedure. dyadicMarkov evaluates each LRT comparison using Pearson's chi-squared statistic,
where and are the empirical and theoretical transition
counts. A comparison is treated as rejected when .
Pattern labels summarize which structure is retained by the tests:
IM (A0) denotes an independence pattern, APM (A1) an
actor-partner pattern, AM (A2) an actor-only pattern, and
PM (A3) a partner-only pattern.
A list with class c("dyadic_pattern", "list") containing two
htest objects (TEST.AM, TEST.PM), the retained input
sequences chainFM and chainSM, a string pattern, and
metadata fields alpha, states, and call. It remains
usable as an ordinary list.
chainFM <- c(1L, 2L, 1L, 2L, 2L, 1L) chainSM <- c(2L, 1L, 2L, 1L, 1L, 2L) univariatePattern(chainFM, chainSM, states = 2L, alpha = 0.05)chainFM <- c(1L, 2L, 1L, 2L, 2L, 1L) chainSM <- c(2L, 1L, 2L, 1L, 1L, 2L) univariatePattern(chainFM, chainSM, states = 2L, alpha = 0.05)