Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude Node in semPaths {semPlot}

I'm trying to plot a sem-path with R.

Im using an OUT file provinent from Mplus with semPaths {semPLot}.

Apparently it seems to work, but i want to remove some latent variables and i don't know how.

I am using the following syntax :

Out from Mplus : https://www.dropbox.com/s/vo3oa5fqp7wydlg/questedMOD2.out?dl=0

outfile1 <- "questedMOD.out"
```

semPaths(outfile1,what="est", intercepts=FALSE, rotation=4,  edge.color="black", sizeMan=5, esize=TRUE, structural="TRUE",  layout="tree2", nCharNodes=0, intStyle="multi" )   
like image 799
Ariadna Angulo Avatar asked Feb 12 '26 15:02

Ariadna Angulo


1 Answers

There may be an easier way to do this (and ignoring if it is sensible to do it) - one way you can do this is by removing nodes from the object prior to plotting.

Using the Mplus example from your question Rotate Edges in semPaths/qgraph

library(qgraph)
library(semPlot)
library(MplusAutomation)

# This downloads an output file from Mplus examples
download.file("http://www.statmodel.com/usersguide/chap5/ex5.8.out", 
                                        outfile <- tempfile(fileext = ".out"))

# Unadjusted plot
s <- semPaths(outfile, intercepts = FALSE)

enter image description here

In the above call to semPaths, outfile is of class character, so the line (near the start of code for semPaths)

 if (!"semPlotModel" %in% class(object)) 
                    object <- do.call(semPlotModel, c(list(object), modelOpts))  

returns the object from semPlot:::semPlotModel.mplus.model(outfile). This is of class "semPlotModel".

So the idea is to create this object first, amend it and then pass this object to semPaths.

# Call semPlotModel on your Mplus file
obj <- semPlot:::semPlotModel.mplus.model(outfile)
# obj <- do.call(semPlotModel, list(outfile)) # this is more general / not just for Mplus

# Remove one factor (F1) from object@Pars - need to check lhs and rhs columns
idx <- apply(obj@Pars[c("lhs", "rhs")], 1, function(i) any(grepl("F1", i)))
obj@Pars <- obj@Pars[!idx, ]

class(obj)

obj is now of class "semPlotModel" and can be passed directly to semPaths

s <- semPaths(obj, intercepts = FALSE)

enter image description here

You can use str(s) to see the structure of this returned object.

like image 119
user20650 Avatar answered Feb 14 '26 03:02

user20650



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!