Include parameter estimates on .Dot plots from omxGraphviz()

4 replies [Last post]
dadrivr's picture
Offline
Joined: 01/19/2010

After using omxGraphviz() to output a .Dot plot from my OpenMx model, I get a diagram of the model, but no parameter estimates are overlaid on the diagram. Is there a way to do this? Thanks in advance.

tbates's picture
Offline
Joined: 07/31/2009
good suggestion

This seems like a really reasonable and basic request.

In terms of SEM competition under R, both lavaan[sp] and sem 2.0 have nice reporting of graphical output with parameters, as well as comprehensive fit indices (inc. for example saturated fit for RAM models)

We have most of this now, and worth going extra metre or two to complete it.

getting omxGraphviz to include values on the path diagram is pretty straight forward.

An initial requirement given the current implementation is to modify
OpenMx:::matrixToPaths() and meansToPaths to include values

something like this would work

matrixToPaths <- function (mxMatrix, arrows = c(1, 2)) {
values <- mxMatrix@values
free <- mxMatrix@free
labels <- mxMatrix@labels
if (arrows == 2) {
values[upper.tri(values)] <- 0
free[upper.tri(free)] <- FALSE
labels[upper.tri(labels)] <- as.character(NA)
}
select <- (values != 0) | (free) | (!is.na(labels))
if (length(select) > 0) {
rowFactors <- row(values, as.factor = TRUE)
colFactors <- col(values, as.factor = TRUE)
fromNames <- as.character(colFactors[select])
toNames <- as.character(rowFactors[select])
pathValues <- values[select]

# return(pathValues)
if (length(fromNames) > 0 && length(toNames) > 0) {
return(mxPath(from = fromNames, to = toNames, arrows = arrows, values= pathValues))
}
}
return(list())
}

meansToPaths <- function (mxMatrix) {
if (is.null(mxMatrix))
return(list())
values <- mxMatrix@values
free <- mxMatrix@free
labels <- mxMatrix@labels
select <- (values != 0) | (free) | (!is.na(labels))
if (length(select) > 0) {
colFactors <- col(values, as.factor = TRUE)
toNames <- as.character(colFactors[select])
pathValues <- values[select]

if (length(toNames) > 0) {
return(mxPath(from = "one", to = toNames, arrows = 1, values=))
}
}
return(list())
}

Then modifying writeDotFile() to include "label = $value" in the paths as it creates them

happy to help code this

t

mdewey's picture
Offline
Joined: 01/21/2011
Good suggestion seconded

This would really enhance the facility to produce graphs. Hand editing the dot file is a pain and of course you have to redo it every time you change the model.

dadrivr's picture
Offline
Joined: 01/19/2010
I agree

This would be a fantastic addition that would aid in visualizing one's model and would save considerable time. Please consider incorporating this, as it seems it's almost ready. Thanks guys for your willingness to listen to the user community!

tbates's picture
Offline
Joined: 07/31/2009
while we're there...

We could also expose some customization options, ala sem::pathDiagram

## S3 method for class 'sem'
pathDiagram(model, file, min.rank=NULL, max.rank=NULL,
same.rank=NULL, variables=model$var.names, parameters=rownames(model$ram),
ignore.double=TRUE, edge.labels=c("names", "values", "both"),
size=c(8, 8), node.font=c("Helvetica", 14),
edge.font=c("Helvetica", 10), rank.direction=c("LR", "TB"),
digits=2, standardize=FALSE, output.type=c("graphics", "dot"),
graphics.fmt="pdf", dot.options=NULL, ...)