| ctgimme | R Documentation |
Fits continuous-time state-space models for multiple individuals and uses iterative modification-index searches to identify paths shared at the group, subgroup, and individual levels. When data-driven subgroup detection is enabled, the default method uses recurrent-evidence feature screening followed by partitioning around medoids (PAM).
ctgimme(
varnames = NULL,
dataframe = NULL,
id = NULL,
time = NULL,
cores = 1,
directory = NULL,
sig.thrsh = 0.55,
sub.sig.thrsh = 1,
Galpha = 0.05,
ben.hoch = TRUE,
S.Galpha = 0.05,
Ialpha = 0.01,
ME.var = 1e-08,
PE.var = NULL,
subgroup.model = FALSE,
time.intervals = c(1),
keep.intermediate = FALSE,
conduct = TRUE,
subgroup.method = c("pam", "legacy"),
max.subgroups = NULL,
scale.data = FALSE,
ME.free = FALSE,
PE.free = FALSE,
verbose = TRUE
)
varnames |
Nonempty character vector naming distinct process-variable
columns in |
dataframe |
Data frame in long format, with one row per measurement
occasion and columns named by |
id |
Character scalar naming the subject-identifier column in
|
time |
Character scalar naming the numeric observation-time column in
|
cores |
Positive integer giving the requested number of parallel PSOCK
workers. The default is |
directory |
Character scalar giving the output directory for model, modification-index, plot, membership, and diagnostic artifacts. It is created recursively when necessary. Existing files with package-defined names may be replaced or cleaned up, so a new or dedicated directory is recommended. This argument is required. |
sig.thrsh |
Numeric scalar in |
sub.sig.thrsh |
Numeric scalar in |
Galpha |
Numeric scalar between zero and one giving the base
significance level for modification-index evidence during group-level
path additions. The default is |
ben.hoch |
Logical scalar. If |
S.Galpha |
Numeric scalar between zero and one giving the base
significance level for modification-index evidence during subgroup-level
path additions. The default is |
Ialpha |
Numeric scalar between zero and one giving the base
significance level for individual-level path additions and the direct
significance cutoff for individual-level pruning. The default is |
ME.var |
Finite, nonnegative measurement-error variances, supplied as a
numeric scalar or a diagonal numeric matrix with one row and column per
process variable. A scalar is repeated down the diagonal. The default is
|
PE.var |
Finite, nonnegative process-noise (innovation) variances,
supplied as |
subgroup.model |
Logical scalar. If |
time.intervals |
Nonempty numeric vector of nonnegative elapsed-time
values in the same units as |
keep.intermediate |
Logical scalar controlling end-of-run cleanup. If
|
conduct |
Logical scalar used only when |
subgroup.method |
Character scalar selecting the data-driven subgroup
detector. The default, |
max.subgroups |
|
scale.data |
Logical scalar. If |
ME.free |
Logical scalar, vector with one entry per process variable,
or square logical matrix with one row and column per process variable,
selecting the diagonal measurement-error variances to estimate. A scalar
is repeated down the diagonal; a matrix must have |
PE.free |
Logical scalar, vector with one entry per process variable,
or square logical matrix with one row and column per process variable,
selecting the diagonal process-noise variances to estimate. A scalar is
repeated down the diagonal; a matrix must have |
verbose |
Logical scalar controlling informational progress output. If
|
Estimation is computationally intensive and writes intermediate and
final artifacts to directory. Every successfully completed run writes
GStruc.RDS, subgroup_detection.rds, subgroup_membership.csv, and
Subgroups Plot.png, as well as a subgroup structure file for each
membership group and a shared individual-model directory. When usable PAM
distances or legacy similarities are available, the PNG is a
two-dimensional subject-distance map: closer nodes have more similar
individual model evidence, nearest neighbors are connected, and colors
and enclosing hulls indicate membership. Subjects lacking a diagnostic
distance are noted but omitted from the map. A complete membership roster
is plotted when no usable pairwise distance is available.
With subgroup.model = TRUE, each subgroup directory
Models/Subgroup <g>/ additionally contains Subgroup <g> Params.png,
one Subgroup <g> Delta_t = <delta>.png transition plot for every value in
time.intervals, and Subgroup_<g>Model.RDS. The RDS contains one fitted
OpenMx model with shared subgroup parameters and one internal likelihood
block per person; those blocks are not separately estimated subject
models. The transition plots display exp(A * delta), the discrete-time
form of the fitted continuous-time drift at the requested elapsed time.
PAM subgrouping requires at least three usable subject model and
modification-index pairs plus at least one eligible off-diagonal,
non-group path that passes its fixed recurrence screen. It chooses among
candidate counts from two through max.subgroups, bounded above by the
number of usable subjects minus one, using average silhouette width.
Legacy subgrouping requires at least two usable subject model and
modification-index pairs. If these requirements are not met, all subjects
are assigned to membership group 1. When only some subjects have usable
artifacts, either detector assigns the remaining subjects to group 1 in
the complete membership output. The method-native memberships can cover
only the usable subjects: PAM's $clustering vector and the legacy
communities object omit unusable subjects, although returned PAM objects
also receive the complete $membership vector described above.
ME.free and PE.free affect diagonal variances only;
measurement-error and process-noise covariances remain fixed to zero.
Estimating both variance sets generally requires more within-person
information than estimating process noise while fixing measurement error.
Estimated values are stored in the R and Q matrices, respectively, of
saved OpenMx models. The verbose argument controls package progress and
main-process OpenMx reporting; the parallel backend does not forward raw
worker output. Internal fits do not use the interactive progress callback,
which avoids imxReportProgress lookup failures reported in some
RStudio/OpenMx installations.
If subgroup detection is disabled or falls back to one membership
group, an invisible list with elements message, G.DRIFT, membership,
directory, clustering, and subgroup.detection. Thus every successful
run returns an object from which the complete membership can be extracted.
With enabled subgroup detection, a successful PAM run returns a
cluster::pam object augmented with a complete, ID-aligned membership
element; a successful legacy run returns an igraph communities object.
Both successful clustering objects carry the complete ID-aligned vector
in the ctgimme.membership attribute and the output paths in the
ctgimme.membership.artifacts attribute. In every successfully completed
case, the complete membership is also written to subgroup_membership.csv
and saved in subgroup_detection.rds.
Park, J. J., Fisher, Z. F., Hunter, M. D., Shenk, C., Russell, M., Molenaar, P. C. M., & Chow, S.-M. (2025). Unsupervised model construction in continuous-time. Structural Equation Modeling: A Multidisciplinary Journal, 32(3), 377–399. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/10705511.2024.2429544")}
ctgimme_demo() for a fast, estimation-free demonstration of
the subgroup selection step.
quick <- ctgimme_demo()
table(quick$membership)
fit_membership <- local({
set.seed(123)
n_time <- 12L
observations <- data.frame(
id = rep(c("S1", "S2"), each = n_time),
time = rep(0:(n_time - 1L), 2L),
x = c(
stats::arima.sim(model = list(ar = 0.6), n = n_time),
stats::arima.sim(model = list(ar = 0.6), n = n_time)
)
)
example_output <- tempfile("ctgimme-example-")
on.exit(
unlink(example_output, recursive = TRUE, expand = FALSE),
add = TRUE
)
fit <- ctgimme(
varnames = "x",
dataframe = observations,
id = "id",
time = "time",
directory = example_output,
ME.var = 0.05,
PE.var = 1,
verbose = FALSE
)
fit$membership
})
fit_membership
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.