Learn R Programming

tna (version 1.5.8)

compare_sequences: Compare Sequences Between Groups

Description

Performs comprehensive sequence comparison analysis between groups. All patterns of the sequences (subsequences of specific length) are extracted from all sequences in each group. The pattern frequencies are compared between the groups using a permutation test. The reported effect size is the difference between the observed test statistic (sum of squared differences between the observed and expected counts) and the mean value over the permutation samples divided by their standard deviation times square root of the number of observations.

Usage

compare_sequences(x, ...)

# S3 method for default compare_sequences( x, group, sub, min_freq = 5L, test = TRUE, iter = 1000L, adjust = "bonferroni", actor = NULL, ... )

# S3 method for group_tna compare_sequences( x, sub, min_freq = 5L, test = TRUE, iter = 1000L, adjust = "bonferroni", actor = NULL, ... )

Value

A tna_sequence_comparison object, which is a data.frame with one row per pattern that passes min_freq, and the columns pattern

(the states of the pattern joined by ->), freq_<group> (the count of the pattern in each group), prop_<group> (its proportion among the patterns of the same length in the group), and, when test = TRUE, effect_size and p_value (adjusted with adjust).

Arguments

x

A group_tna object or a data.frame containing sequence data in wide format. A group_tna object with scaled edge weights is not resampled (an error of class tna_error_scaling).

...

Not used. A misspelled or unknown argument is an error.

group

A vector indicating the group assignment of each row of the data/sequence. Must have the same length as the number of rows/sequences of x. Alternatively, a single character string giving the column name of the data that defines the group when x is a wide format data.frame or a tna_data object.

sub

An integer vector of pattern lengths to analyze. The default is 1:5 (patterns of length 1 are the states themselves), or up to the number of time points when the sequences are shorter.

min_freq

An integer giving the minimum number of times that a specific pattern has to be observed in each group to be included in the analysis. The default is 5.

test

A logical value indicating whether to test the differences of pattern counts between the groups using a permutation test. The default is TRUE.

iter

An integer giving the number of iterations for the permutation test. The default is 1000.

adjust

A character string naming the multiple comparison correction method (default: "bonferroni"). Supports all stats::p.adjust methods: "holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none". The adjustment is carried out within sequences of the same length.

actor

An optional actor identifier for sequences nested in actors: a character string naming a non-sequence column of the data, or a vector with one identifier per row/sequence of x (of the data the grouped model was built from, for a group_tna object). When given, the permutation test reassigns whole actors between the groups, and shuffles the sequences of actors present in several groups within the actor (Good, 2005). The default NULL permutes single sequences.

See Also

Model comparison functions compare(), compare.group_tna(), plot.tna_comparison(), plot.tna_sequence_comparison(), plot_compare(), plot_compare.group_tna(), print.tna_comparison(), print.tna_sequence_comparison()

Examples

Run this code
# A small subset (100 high and 100 low achievers) without the test
sequences <- rbind(head(group_regulation, 100), tail(group_regulation, 100))
group <- rep(c("High", "Low"), each = 100)
compare_sequences(sequences, group, test = FALSE)
# \donttest{
# With the permutation test (small number of iterations for CRAN)
sequences <- rbind(head(group_regulation, 500), tail(group_regulation, 500))
group <- rep(c("High", "Low"), each = 500)
compare_sequences(sequences, group, sub = 2:3, iter = 20)
# }

Run the code above in your browser using DataLab