[R] identify non-recursive models
murdoch.duncan at gmail.com
Tue Jan 29 17:21:15 CET 2013
On 29/01/2013 11:12 AM, Dustin Fife wrote:
> I'm working on a project that will generate RAM matrices at random. What I
> want to do is to be able to automatically identify if the model is
> non-recursive. For example, the following RAM matrix has a non-recursive
> loop (going from A to B to C to A):
I'm not familiar with your terms, but your description sounds like you
want a test for a simple graph. I believe the igraph package has that
in the "is.simple" function (and a lot of other tests of graph
properties in case that's not the one you want).
> n.recursive <- data.frame(matrix(c("A", "B", 1,
> "B", "C", 1,
> "C", "A", 1,
> "B", "D", 1), nrow=4, byrow=TRUE))
> names(n.recursive) <- c("From", "To", "Arrows")
> What I want to be able to do is have a function that automatically checks
> whether there is a non-recursive path. Here's what I've thought of so far:
> 1. Find all variables that both send and receive an arrow. (in this case, A
> and B both fit that criteria).
> vars <- LETTERS[1:5]
> double.arrow.vars <- vars[which(vars %in% n.recursive$From & vars %in%
> 2. For all variables found in #1, follow all paths exiting that variable to
> other variables, then follow all paths exiting that next variable variable,
> etc. and continue tracing the path.
> ##### insert complicated code here
> 3. If a variable is repeated, identify it as non-recursive.
> The problem with #2 is that, for large models, the number of paths to be
> traced could be really large. (Also, I'm having trouble thinking of how to
> code it so it's not really awkward).
> So, my question is this: is there a better way to approach the problem? Is
> there a more efficient way?
> I know that I could probably identify which models are non-recursive after
> estimation (via convergence failures or negative parameter estimates). But
> I want to be able to identify them before estimation. Any help would be
More information about the R-help