[R] path.diagram in SEM--display covariances without variances

Dustin Fife fife.dustin at gmail.com
Thu Nov 10 01:03:01 CET 2011


For those who have the same question later....after following John's
steps of extracting the function, I just replaced the line of code
that says:

if ((!ignore.double) || (heads[par] == 1))

with

 if (((!ignore.double) || (heads[par] == 1)) & variables[from[par]] !=
variables[to[par]])

That seems to do just what I want. Thanks again John!

On Wed, Nov 9, 2011 at 5:40 PM, Dustin Fife <fife.dustin at gmail.com> wrote:
> Perfect! Thanks for the help.
>
> On Wed, Nov 9, 2011 at 4:27 PM, John Fox <jfox at mcmaster.ca> wrote:
>> Dear Dustin,
>>
>>> -----Original Message-----
>>> From: Dustin Fife [mailto:fife.dustin at gmail.com]
>>> Sent: November-09-11 2:12 PM
>>> To: John Fox
>>> Cc: r-help at r-project.org
>>> Subject: Re: [R] path.diagram in SEM--display covariances without
>>> variances
>>>
>>> Thanks for the quick response...I've never edited someone else's
>>> package before. How do I go about doing that?
>>
>> I wouldn't change the sem package, but rather create your own version of
>> pathDiagram(). You could examine the package sources, but, more simply, to
>> see the code for the function, type its name at the command prompt:
>>
>>> library(sem)
>> Loading required package: MASS
>> Loading required package: matrixcalc
>>> pathDiagram
>> function (model, ...)
>> {
>>    UseMethod("pathDiagram")
>> }
>> <bytecode: 0000000006E1CEA8>
>> <environment: namespace:sem>
>>
>> So pathDiagram() is a generic function. What methods are available?
>>
>>> methods(pathDiagram)
>> [1] pathDiagram.sem*
>>
>>   Non-visible functions are asterisked
>>
>> There is, therefore just one method, for objects of class "sem", hidden in
>> the sem namespace. To see it (most lines elided):
>>
>>> sem:::pathDiagram.sem
>> function (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, ...)
>> {
>> . . .
>>    cat(file = handle, "}\n")
>>    if (output.type == "graphics" && !missing(file)) {
>>        cmd <- paste("dot -T", graphics.fmt, " -o ", graph.file,
>>            " ", dot.options, " ", dot.file, sep = "")
>>        cat("Running ", cmd, "\n")
>>        result <- try(system(cmd))
>>    }
>>    invisible(NULL)
>> }
>> <bytecode: 00000000071B9568>
>> <environment: namespace:sem>
>>
>> Just copy the functions into an editor and make whatever changes you want.
>>
>> Best,
>>  John
>>
>>>
>>> On Wed, Nov 9, 2011 at 12:47 PM, John Fox <jfox at mcmaster.ca> wrote:
>>> > Dear Dustin,
>>> >
>>> >> -----Original Message-----
>>> >> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
>>> >> project.org] On Behalf Of Dustin Fife
>>> >> Sent: November-09-11 10:57 AM
>>> >> To: r-help at r-project.org
>>> >> Subject: [R] path.diagram in SEM--display covariances without
>>> >> variances
>>> >>
>>> >> Forgive me if I'm posting to the wrong place....It's my first time
>>> >> posting.
>>> >>
>>> >> Here's the situation: I'm using the sem package and making path
>>> >> diagrams using path.diagrams. Suppose I have the following code:
>>> >>
>>> > . . .
>>> >
>>> >> The diagram is produces is hard to read because of the many
>>> variances
>>> >> that are shown. The covariance estimates are important for my
>>> >> diagram, but the variances are not. Is there a way to suppress the
>>> >> variance arrows without suppressing the covariance arrows?
>>> >
>>> > No, but (1) pathDiagram() (the name of the function in the current
>>> > version of the sem package) produces an editable text file, from
>>> which
>>> > you could remove the arrows that you don't want to see; and (2) you
>>> > could modify
>>> > pathDiagram() -- the code for the function is, after all, available
>>> to
>>> > you
>>> > -- so that it does what you want.
>>> >
>>> > I hope this helps,
>>> >  John
>>> >
>>> > --------------------------------
>>> > John Fox
>>> > Senator William McMaster
>>> >  Professor of Social Statistics
>>> > Department of Sociology
>>> > McMaster University
>>> > Hamilton, Ontario, Canada
>>> > http://socserv.mcmaster.ca/jfox
>>> >
>>> >
>>> >
>>> >>
>>> >> --
>>> >> Dustin Fife
>>> >> Graduate Student, Quantitative Psychology University of Oklahoma
>>> >>
>>> >> ______________________________________________
>>> >> R-help at r-project.org mailing list
>>> >> https://stat.ethz.ch/mailman/listinfo/r-help
>>> >> PLEASE do read the posting guide http://www.R-project.org/posting-
>>> >> guide.html and provide commented, minimal, self-contained,
>>> >> reproducible code.
>>> >
>>> >
>>>
>>>
>>>
>>> --



More information about the R-help mailing list