build_model {tna} | R Documentation |
Build a Transition Network Analysis Model
Description
Construct a transition network analysis (TNA) model from sequence data.
The function takes a data set of sequence of events or states as input and
builds a TNA model. It extracts the edge weights and initial probabilities
from the data along with the state labels. THe function also accepts weight
matrices and initial state probabilities directly.
Usage
build_model(x, type = "relative", scaling = character(0L), ...)
## Default S3 method:
build_model(
x,
type = "relative",
scaling = character(0L),
inits,
params = list(),
...
)
## S3 method for class 'matrix'
build_model(x, type = "relative", scaling = character(0L), inits, ...)
## S3 method for class 'stslist'
build_model(
x,
type = "relative",
scaling = character(0L),
cols = seq(1, ncol(x)),
params = list(),
...
)
## S3 method for class 'data.frame'
build_model(
x,
type = "relative",
scaling = character(0L),
cols = seq(1, ncol(x)),
params = list(),
...
)
## S3 method for class 'tna_data'
build_model(x, type = "relative", scaling = character(0), params = list(), ...)
tna(x, ...)
ftna(x, ...)
ctna(x, ...)
atna(x, ...)
Arguments
x |
A stslist (from TraMineR ), data.frame , a matrix , or
a tna_data object (see prepare_data() ).
For stslist and data.frame objects x
should describe a sequence of events or states to be used for building the
Markov model. If x is a matrix, it is assumed that the element on row
i and column j is the weight of the edge representing the transition
from state i to state j . If x is a data.frame , then
it must be in wide format (see cols on how to define columns for the
time points).
|
type |
A character string describing the weight matrix type.
Currently supports the following types:
-
"relative" for relative frequencies (probabilities, the default)
-
"frequency" for frequencies.
-
"co-occurrence" for co-occurrences.
-
"n-gram" for n-gram transitions. Captures higher-order transitions by
considering sequences of n states, useful for identifying longer
patterns.
-
"gap" allows transitions between non-adjacent states, with
transitions weighted by the gap size.
-
"window" creates transitions between all states within a
sliding window, capturing local relationships
(several sequences together).
-
"reverse" considers the sequences in reverse order
(resulting in what is called a reply network in some contexts).
The resulting weight matrix is the transpose of the "frequency"
option.
-
"attention" aggregates all downstream pairs of states with an
exponential decay for the gap between states. The parameter lambda
can be used to control the decay rate (the default is 1)-
|
scaling |
A character vector describing how to scale the weights
defined by type . When a vector is provided, the scaling options are
applied in the respective order. For example, c("rank", "minmax") would
first compute the ranks, then scale them to the unit interval using
min-max normalization. An empty vector corresponds to no scaling.
Currently supports the following options:
-
"minmax" performs min-max normalization to scale the weights to the
unit interval. Note that if the smallest weight is positive, it
will be zero after scaling.
-
"max" Multiplies the weights by the reciprocal of the largest weight
to scale the weights to the unit interval. This options preserves
positive ranks, unlike "minmax" when all weights are positive.
-
"rank" Computes the ranks of the weights using base::rank() with
ties.method = "average" .
|
... |
Ignored. For the build_model aliases (e.g., tna ), this
argument matches the actual arguments to build_model beside x .
|
inits |
An optional numeric vector of initial state probabilities
for each state. Can be provided only if x is a matrix . The vector will
be scaled to unity.
|
params |
A list of additional arguments for models of specific
type . The potential elements of this list are:
-
n_gram : An integer for n-gram transitions specifying the number of
adjacent events. The default value is 2.
-
max_gap : An integer for the gap-allowed transitions specifying the
largest allowed gap size. The default is 1.
-
window_size : An integer for the sliding window transitions
specifying the window size. The default is 2.
-
weighted : A logical value. If TRUE , the transitions
are weighted by the inverse of the sequence length. Can be used for
frequency, co-occurrence and reverse model types. The default is
FALSE .
-
lambda : A numeric value for the decay rate. The default is 1.
|
cols |
An integer /character vector giving the indices/names of the
columns that should be considered as sequence data.
Defaults to all columns, i.e., seq(1, ncol(x)) . Column names not found
in x will be ignored without warning.
|
Value
An object of class tna
which is a list
containing the
following elements:
-
weights
: An adjacency matrix
of the model (weight matrix).
-
inits
: A numeric
vector of initial values for each state.
For matrix
type x
, this element will be NULL
if inits
is not
directly provided
-
labels
: A character
vector of the state labels, or NULL
if
there are no labels.
-
data
: The original sequence data that has been converted to an
internal format used by the package when x
is a stslist
or a
data.frame
object. Otherwise NULL
.
See Also
Basic functions
hist.group_tna()
,
hist.tna()
,
plot.group_tna()
,
plot.tna()
,
plot_frequencies()
,
plot_frequencies.group_tna()
,
plot_mosaic()
,
plot_mosaic.group_tna()
,
plot_mosaic.tna_data()
,
print.group_tna()
,
print.summary.group_tna()
,
print.summary.tna()
,
print.tna()
,
summary.group_tna()
,
summary.tna()
,
tna-package
Examples
model <- build_model(group_regulation)
print(model)
model <- tna(group_regulation)
model <- ftna(group_regulation)
model <- ctna(group_regulation)
model <- atna(group_regulation)
[Package
tna version 1.0.0
Index]