Include parameter estimates on .Dot plots from omxGraphviz()
Posted on

Forums
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.
good suggestion
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
Log in or register to post comments
In reply to good suggestion by tbates
while we're there...
## 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, ...)
Log in or register to post comments
In reply to good suggestion by tbates
Good suggestion seconded
Log in or register to post comments
In reply to Good suggestion seconded by mdewey
I agree
Log in or register to post comments