Learn R Programming

stablespec (version 0.2.3)

repairCyclicModel: Repairing a SEM model that is cyclic.

Description

Repairing a SEM model that is cyclic.

Usage

repairCyclicModel(stringModel = NULL, numVar = NULL, longitudinal = NULL)

Arguments

stringModel
binary vector with length n^2+(n(n-1)) if longitudinal = TRUE, or n(n-1) if FALSE, where n is the number of variables (numVar).
numVar
number of variables.
longitudinal
TRUE for longitudinal data, and FALSE for cross-sectional data.

Value

a binary vector with the same length of input, representing a repaired model (acyclic).

Details

The main idea of this function is to seek cyclic(s) with any possible length from a given model, and then to cut the cyclic, so as to make the model acyclic. Moreover, this function is used in stableSpec to ensure no cyclic model in the computation.

Examples

Run this code

num_vars <- 6
longi_a <- FALSE
longi_b <- TRUE

# Assume that the generated model below is cyclic
# a cross-sectional model
model_a <- round(runif(num_vars * num_vars))
# a longitudinal model
model_b <- c(round(runif(num_vars * num_vars)),
round(runif(num_vars * (num_vars-1))))

repaired_model_a <- repairCyclicModel(stringModel=model_a, numVar=num_vars,
longitudinal=longi_a)

repaired_model_b <- repairCyclicModel(stringModel=model_b, numVar=num_vars,
longitudinal=longi_b)

repaired_model_a
repaired_model_b

Run the code above in your browser using DataLab