Example of using a definition variable in a RAM model
Posted on

Forums
Hi,
Are there any example scripts for how to add a definition variable to a RAM model, and how to then use that in an algebra on a path?
Are there any example scripts for how to add a definition variable to a RAM model, and how to then use that in an algebra on a path?
Here's one adding a definition variable for means, but not including its value in an algebra, and then using that algebra to se the value for another path.
[https://openmx.ssri.psu.edu/docs/OpenMx/2.5.1/DefinitionMeans_Path.html](https://openmx.ssri.psu.edu/docs/OpenMx/2.5.1/DefinitionMeans_Path.html)
like this?
Log in or register to post comments
In reply to like this? by jpritikin
Example rather than test (and creating a moderated path in RAM)
Wanting an example to point people to with comments on most lines explaining how the script works. Also one just showing "Here is how to create a moderated path in RAM" rather than more complex example for learning.
Reading through univACErSEM.R now: The definition variables are used on paths directly, rather than being used to moderate a path (i.e., compute the path based on the definition variable. e.g.
mxMatrix(name= "beta1", 1,1)
mxAlgebra(name= "BMIalg", latentBMI + beta1 * data.BMI_SNP)
Log in or register to post comments
moderation example: can it be extended?
But can it be extended to the typical case of
x-->y;
def--> y;
x*def-->y
?
i.e., to include the def on the diagram as a manifest, and use it as a definition variable?
# make up some data
require(umx); library(MASS)
N = 500 # sample size, per group
Sigma = matrix(c(1,.5,.5,1),2,2)
group1 = mvrnorm(N, c(1,2), Sigma) # Use mvrnorm from MASS package
group2 = mvrnorm(N, c(0,0), Sigma)
# Put the two groups together, create a definition variable,
# and make a list of which variables are to be analyzed (selVars)
xy = rbind(group1,group2) # Bind groups together by rows
dimnames(xy)[2] = list(c("x","y")) # Add names
def = rep(c(1,0),each=N); # Add def var [2n] for group status
selVars = c("x","y") # Make selection variables object
df = data.frame(xy,def)
#############################################
# Make a model with moderation using a definition variable #
#############################################
m1 = mxModel("def_test", type="RAM", manifestVars= c("x", "y"), latentVars= "dummy", mxData(df, type= "raw"),
mxPath(c("x", "y"), arrows= 2, free= TRUE),
mxPath("one", to = c("x","y"), arrows= 1, free= TRUE),
mxPath("dummy", value= 0, arrows= 2, free= FALSE),
mxPath("one", to = "dummy", value= 0, free= FALSE),
mxPath("x", to = "y"),
mxPath("x", to = "dummy", values=0, free=FALSE, label = "data.def"),
mxPath("dummy", to = "y")
)
m1 = mxRun(m1)
Log in or register to post comments
Update?
I am interested in estimating a GxE biometric twin model using the RAM notation. However, I am not sure how to implement the moderation with the path notation. Could you give me a hint if it is possible and if so how one can code it within OpenMx?
Log in or register to post comments
In reply to Update? by Benny
Yes, it's possible to do that
If the model you want to fit is fairly basic, you can probably do it pretty easily in the umx package, with one of its `umxGxE*` functions.
Log in or register to post comments
In reply to Update? by Benny
Onyx is cool
Mostly, the moderation trick is to draw two paths, e.g., from A to P, one goes direct and is the unmoderated bit, and the other goes first to a latent variable that has no double-headed arrow or other variance to itself, and then from that latent variable to P. Put moderation parameter on one path, and the definition variable for the moderator on the other, and the two together operate as if the algebra (a + b * Mod) had been directly specified as a formula on a path.
Log in or register to post comments
Thank you
Log in or register to post comments