[R] SEM - standardized path coefficients? - significant style

Steve Powell steve at promente.org
Thu Sep 20 09:39:38 CEST 2007


Dear John
Being an R user is like having Christmas every day and having a direct line
to Santa for present suggestions. 
How about if path.diagram.sem had the ability to print non-significant paths
in, for example dotted style? I had a go myself but couldn't see how to get
(summary(model)$coeff)$"Pr(>|z|)" into the loop.
Very best wishes
Steve Powell

 
proMENTE social research 
research | evaluation | training & consulting 
Kranjčevićeva 35, 71000 Sarajevo 
mobile: +387 61 215 997 | office: +387 33 556 865 | fax: +387 33 556 866
skype: stevepowell99 
www.promente.org  |  www.mojakarijera.com  |  www.psih.org  

-----Original Message-----
From: John Fox [mailto:jfox at mcmaster.ca] 
Sent: 19 September 2007 13:55
To: 'Steve Powell'
Cc: r-help at stat.math.ethz.ch
Subject: RE: [R] SEM - standardized path coefficients?

Dear Steve,

My intention was to provide this flexibility via the parameters argument to
path.diagram.sem(), but it isn't implemented. Here's a version that should
do what you want:

----------------- snip ----------------

path.diagram.sem <- function (model, out.file, min.rank = NULL, max.rank =
NULL, 
    same.rank = NULL, variables = model$var.names, parameters, 
    ignore.double = TRUE, edge.labels = c("names", "values"), 
    size = c(8, 8), node.font = c("Helvetica", 14), edge.font =
c("Helvetica", 
        10), rank.direction = c("LR", "TB"), digits = 2, ...) {
    if (!missing(out.file)) {
        handle <- file(out.file, "w")
        on.exit(close(handle))
    }
    else handle <- stdout()
    edge.labels <- match.arg(edge.labels)
    rank.direction <- match.arg(rank.direction)
    cat(file = handle, paste("digraph \"", deparse(substitute(model)), 
        "\" {\n", sep = ""))
    cat(file = handle, paste("  rankdir=", rank.direction, ";\n", 
        sep = ""))
    cat(file = handle, paste("  size=\"", size[1], ",", size[2], 
        "\";\n", sep = ""))
    cat(file = handle, paste("  node [fontname=\"", node.font[1], 
        "\" fontsize=", node.font[2], " shape=box];\n", sep = ""))
    cat(file = handle, paste("  edge [fontname=\"", edge.font[1], 
        "\" fontsize=", edge.font[2], "];\n", sep = ""))
    cat(file = handle, "  center=1;\n")
    if (!is.null(min.rank)) {
        min.rank <- paste("\"", min.rank, "\"", sep = "")
        min.rank <- gsub(",", "\" \"", gsub(" ", "", min.rank))
        cat(file = handle, paste("  {rank=min ", min.rank, "}\n", 
            sep = ""))
    }
    if (!is.null(max.rank)) {
        max.rank <- paste("\"", max.rank, "\"", sep = "")
        max.rank <- gsub(",", "\" \"", gsub(" ", "", max.rank))
        cat(file = handle, paste("  {rank=max ", max.rank, "}\n", 
            sep = ""))
    }
    if (!is.null(same.rank)) {
        for (s in 1:length(same.rank)) {
            same <- paste("\"", same.rank[s], "\"", sep = "")
            same <- gsub(",", "\" \"", gsub(" ", "", same))
            cat(file = handle, paste("  {rank=same ", same, "}\n", 
                sep = ""))
        }
    }
    latent <- variables[-(1:model$n)]
    for (lat in latent) {
        cat(file = handle, paste("  \"", lat, "\" [shape=ellipse]\n", 
            sep = ""))
    }
    ram <- model$ram
    ram[names(model$coeff), 5] <- model$coeff
    rownames(ram)[model$fixed] <- ram[model$fixed, 5]
    names <- rownames(ram)
    values <- round(ram[, 5], digits)
    heads <- ram[, 1]
    to <- ram[, 2]
    from <- ram[, 3]
    labels <- if (!missing(parameters)){ 
            if (is.numeric(parameters)) round(parameters, digits) 
                else parameters
            }
        else if (edge.labels == "names") names
        else values
    direction <- ifelse((heads == 2), " dir=both", "")
    for (par in 1:nrow(ram)) {
        if ((!ignore.double) || (heads[par] == 1)) 
            cat(file = handle, paste("  \"", variables[from[par]], 
                "\" -> \"", variables[to[par]], "\" [label=\"", 
                labels[par], "\"", direction[par], "];\n", sep = ""))
    }
    cat(file = handle, "}\n")
}

----------------- snip ----------------

E.g., continuing the example in ?path.diagram,

path.diagram(sem.dhp, min.rank='RIQ, RSES, RParAsp, FParAsp, FSES, FIQ', 
    max.rank='ROccAsp, REdAsp, FEdAsp, FOccAsp', 
    parameters=standardized.coefficients(sem.dhp)$"Std. Estimate")

I'll put the updated path.diagram.sem() in the sem package when I have a
chance.

I hope this helps,
 John

--------------------------------
John Fox, Professor
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox
-------------------------------- 

> -----Original Message-----
> From: Steve Powell [mailto:steve at promente.org]
> Sent: Wednesday, September 19, 2007 3:33 AM
> To: r-help at stat.math.ethz.ch
> Cc: jfox at mcmaster.ca
> Subject: Re: [R] SEM - standardized path coefficients?
> 
> Dear list members,
> In sem, std.coef() will give me standardized coefficients from a sem 
> model.
> But is there a trick so that path.diagram can use these coefficients 
> rather than unstandardized ones?
> Thanks
> Steve Powell
> 
> 
> From: John Fox <jfox_at_mcmaster.ca>
> Date: Wed 28 Feb 2007 - 14:37:22 GMT
> 
> 
> Dear Tim,
> 
> See ?standardized.coefficients (after loading the sem package).
> 
> Regards,
>  John
> 
> John Fox
> Department of Sociology
> McMaster University
> Hamilton, Ontario
> Canada L8S 4M4
> 905-525-9140x23604
> http://socserv.mcmaster.ca/jfox
> 
> > -----Original Message-----
> > From: r-help-bounces at stat.math.ethz.ch 
> > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Tim Holland
> > Sent: Wednesday, February 28, 2007 12:35 AM
> > To: r-help at stat.math.ethz.ch
> > Subject: [R] SEM - standardized path coefficients?
> >
> > Hello -
> >
> > Does anybody know how to get the SEM package in R to return 
> > standardized path coefficients instead of unstandardized ones? Does 
> > this involve changing the covariance matrix, or is there an
> argument
> > in the SEM itself that can be changed?
> >
> > Thank you,
> > Tim
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch 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. 
> 
> Steve Powell
> 
>  
> proMENTE social research
> research | evaluation | training & consulting Kranjčevićeva 35, 71000 
> Sarajevo
> mobile: +387 61 215 997 | office: +387 33 556 865 | fax: +387
> 33 556 866
> skype: stevepowell99
> www.promente.org  |  www.mojakarijera.com  |  www.psih.org
> 
> No virus found in this outgoing message.
> Checked by AVG Free Edition. 
> Version: 7.5.487 / Virus Database: 269.13.22/1015 - Release
> Date: 18.09.2007
> 11:53
>  
> 
> 


No virus found in this incoming message.
Checked by AVG Free Edition. 

18.09.2007
11:53



Checked by AVG Free Edition. 

19.09.2007
15:59



More information about the R-help mailing list