Skip to contents

htna-named alias of Nestimate::markov_order_test(). Tests whether a first-order Markov model is adequate for the observed sequences, or whether a higher order is required, by comparing the empirical transition structure against orders 1..max_order via permutation.

Usage

markov_order_test_htna(
  data,
  max_order = 3L,
  n_perm = 500L,
  alpha = 0.05,
  parallel = FALSE,
  n_cores = 2L,
  seed = NULL
)

Arguments

data

A data.frame (wide format, one sequence per row) or list of character vectors (one per trajectory). NAs are treated as end of sequence.

max_order

Integer. Highest Markov order to test. Default 3.

n_perm

Integer. Number of within-\(w\) permutations per order. Default 500.

alpha

Numeric. Significance level for order selection. Default 0.05.

parallel

Logical. Use parallel::mclapply for permutations. Default FALSE (set TRUE only on Unix-like systems).

n_cores

Integer. Cores for parallel execution. Default 2.

seed

Optional integer seed for reproducibility.

Value

An object of class markov_order_test with components test_table, optimal_order, and the inputs. See Nestimate::markov_order_test() for full details and the corresponding plot() method.

Details

Operates on raw sequence data (a list of character vectors or a wide-format data frame), not on an htna network object. Use alongside reliability_htna() and casedrop_reliability_htna() when assessing whether a Markov-1 transition network is appropriate before trusting downstream htna analyses.

Suffixed _htna to avoid clashing with Nestimate::markov_order_test() when both packages are loaded.

Examples

# \donttest{
data(human_ai)
net <- build_htna(human_ai, actor_type = "actor_type")
#> Warning: A network with one long sequence is not recommended and can't be validated using bootstrap and other confirmatory testings.
#> Metadata aggregated per session: ties resolved by first occurrence in 'session_date' (1 sessions), 'cluster' (42 sessions), 'actor_type' (24 sessions)
markov_order_test_htna(net$data, max_order = 2, n_perm = 50, seed = 1)
#> Markov Order Test  [within-w permutation, n_perm = 50, alpha = 0.050]
#>   428 sequences / 19346 observations / 12 states
#> 
#>   Selected order  BIC: 1   AIC: 2   permutation-LRT: 2
#> 
#>  order    loglik      AIC      BIC   df       g2 p_permutation p_asymptotic
#>      0 -43741.91 87505.83 87592.40   NA       NA            NA           NA
#>      1 -37315.96 74899.92 75954.53  121 12815.99    0.01960784            0
#>      2 -33812.56 69739.12 78057.97 1272  6481.76    0.01960784            0
#>  significant
#>           NA
#>         TRUE
#>         TRUE
# }