# Function to add up paths (path tracing rules function)

7 posts / 0 new Offline
Joined: 07/31/2009 - 14:25
Function to add up paths (path tracing rules function)

Anyone know of a function to take a RAM model and an entry and exit point and output a total effect?

i.e., given A model m1 = A<->B; B->C; A->C

pathEffect(m1, from="A", to= "C")

Would output the product of paths

(a-c) + (a-b * b-c)

If not, it might be a handy addition, and encourage people to report the expected effects in their model rather than just fit. i.e., "All things being equal, this model of our theory suggests that an increase of 50 kg/day of saccharin would decrease lifespan by 1-second, via the following pathways..." Offline
Joined: 02/11/2013 - 14:21
Interesting. I can' think of

Interesting. I can' think of anything offhand, but I like the idea! You could even go one step further and compute confidence intervals for this total effect (using a Monte Carlo confidence interval). The monteCarloMed function in semTools implements this currently, but it forces you to explicitly specify the paths of interest.

Alex Offline
Joined: 07/31/2009 - 15:10
Conditional Mean/Covariance

Let me propose a slightly more general formulation of this idea that should still address your concern.

Suppose we wrote a helper function that would allow you to specify a value for a subset of variables in the model and find the conditional mean implied by the model for the rest of the variables.

So what you'd then actually be saying is that a person exactly at the mean saccharine intake would have a predicted lifespan of X seconds, someone with mean+50 mg intake would have a predicted lifespan of X-1 seconds.

So consider:

partialDataRow <- list(age=25, mgSaccharin=mxEval(meanSac, model) + 50, sex=mxFactor("M", levels=c("F", "M")))
conditionalMean <- omxImputeConditionalMean(partialDataRow, model)
conditionalMean # list(lifespanSeconds=2421334079, lifeSatisfaction=6, age=25, ...)

A similar function could be constructed for the conditional covariance matrix, which might be useful for multiple imputation and maybe some simulation studies. If we work from the covariance matrices, this could work for normal but non-path models as well (although you might not be able to predict latent variables in that case).

Would that do what you want it to do? Offline
Joined: 07/31/2009 - 14:25
concrete example

So the goal would be that from a crazy image like this, we could readout: "Achieving a one SD increase in Reading is implied to raise income for a person on average earnings by £5000/yr"

so I'd write a wrapper that did this:

unexplainedCausalNexus = function(IV_from, delta, DV_to, model) {
partialDataRow = means(model)
oldDV_to = partialDataRow[DVto]
partialDataRow[IV_from] = partialDataRow[IV_from] + delta
newDV_to = omxImputeConditionalMean(partialDataRow, model)[DV_to]
return(newDV_to - oldDV_to)
}  Offline
Joined: 07/31/2009 - 15:10
compute conditionals

Okay.

This is a hacked-together version (the actual meat of it is like three lines, but I do a lot of error-checking for it) that computes the conditional mean and (if requested) conditional covariance for each row passed to the data. It's been quickly tested, and seems to be correct in the few cases I've run for it.

For the conditional mean, that means you'll get back all the data are given with anything missing filled in.

If you give it a RAM model, it will also estimate regression-based scores for each of the latent variables, and tack those columns onto the model. It actually differs from Mike Hunter's method listed in a previous thread (see http://openmx.psyc.virginia.edu/thread/1294#comment-3791 ) only in that it also takes means into account, and imputes any missing value, rather than just the latents.

It doesn't handle definition variables yet--if you want that feature, let me know and I'll get to it when I have a chance.

For your problem, what you probably want is a wrapper like:

unexplainedCausalNexus = function(IV_from, delta, DV_to, model) {
partialDataRow <- matrix(0, 1, length(manifests))  # add dimnames to support string varnames
partialDataRow[1, IV_from] <- delta                       # delta is in raw IV_from units
partialDataRow[1, DV_to] <- NA
completedRow <- conditionalsFromModel(model, partialDataRow, meanOffsets=TRUE)
# by default, meanOffsets = FALSE, and the results take expected means into account
return(completedRow[1, DV_to])

For anyone else needing this function, it's good for quick computation of factor scores or prediction of missing values. It'll also compute conditional covariance matrices if you want to do multiple imputation or anything like that. Offline
Joined: 07/31/2009 - 14:25
wow!

Thanks tim! - perfect for what we wanted, but with a lot more power!

I added it to the umx library...
https://github.com/tbates/umx

Definition variables would be useful – and I guess those are just the cases where it's harder to manually derive predicted effects, esp with covariance between the definition vars and some of the outcomes.

I think this is a real selling point for OpenMx. Couple of examples using this for imputation or factor scores would be great. Sounds like with imputation, this would give RAM models a similar functionality to Mplus's Bayesian posterior approach. Another selling point.

A distinct function that would also be useful would be a function to take a data-less model (i.e., just a stack of mxPaths, as one might see in a paper, for instance) and both work out the implied relations via path tracing, but also return an equivalent dataset.

One could then use this to generate test case datasets.

Anyhow, just to say: great stuff! And thank you
t Offline
Joined: 07/31/2009 - 14:25
wow!

Thanks tim! - perfect for what we wanted, but with a lot more power!

I added it to the umx library...
https://github.com/tbates/umx

Definition variables would be useful – and I guess those are just the cases where it's harder to manually derive predicted effects, esp with covariance between the definition vars and some of the outcomes.

I think this is a real selling point for OpenMx. Couple of examples using this for imputation or factor scores would be great. Sounds like with imputation, this would give RAM models a similar functionality to Mplus's Bayesian posterior approach. Another selling point.

A distinct function that would also be useful would be a function to take a data-less model (i.e., just a stack of mxPaths, as one might see in a paper, for instance) and both work out the implied relations via path tracing, but also return an equivalent dataset.

One could then use this to generate test case datasets.

Anyhow, just to say: great stuff! And thank you
t