Skip to content

Commit

Permalink
version 1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Sacha Epskamp authored and cran-robot committed Apr 5, 2019
1 parent b328207 commit b3b1ac7
Show file tree
Hide file tree
Showing 15 changed files with 394 additions and 47 deletions.
19 changes: 14 additions & 5 deletions DESCRIPTION
Expand Up @@ -2,20 +2,29 @@ Package: semPlot
Type: Package
Title: Path Diagrams and Visual Analysis of Various SEM Packages'
Output
Version: 1.1
Author: Sacha Epskamp, with contributions from Simon Stuber
Version: 1.1.1
Authors@R: c(
person("Sacha", "Epskamp", email = "mail@sachaepskamp.com",role = c("aut", "cre")),
person("Simon", "Stuber", role = c("ctb")),
person("Jason", "Nak", role = c("ctb")),
person("Myrthe", "Veenman", role = c("ctb"))
)
Maintainer: Sacha Epskamp <mail@sachaepskamp.com>
Depends: R (>= 2.15.0)
Suggests: MplusAutomation (>= 0.5-3)
Imports: qgraph (>= 1.2.4), lavaan (>= 0.5-11), sem (>= 3.1-0), plyr,
XML, igraph (>= 0.6-3), lisrelToR, rockchalk, colorspace,
corpcor, methods, semTools, OpenMx
corpcor, methods, semTools, OpenMx, regsem
ByteCompile: yes
Description: Path diagrams and visual analysis of various SEM packages' output.
URL: https://github.com/SachaEpskamp/semPlot
License: GPL-2
LazyLoad: yes
NeedsCompilation: no
Packaged: 2017-03-27 11:23:02 UTC; sachaepskamp
Packaged: 2019-04-05 14:51:15 UTC; sachaepskamp
Author: Sacha Epskamp [aut, cre],
Simon Stuber [ctb],
Jason Nak [ctb],
Myrthe Veenman [ctb]
Repository: CRAN
Date/Publication: 2017-03-27 13:56:21 UTC
Date/Publication: 2019-04-05 15:40:03 UTC
24 changes: 14 additions & 10 deletions MD5
@@ -1,37 +1,39 @@
ff547ababc85108875b8e8f94239d4dd *COPYING
2fee16c126d42660baf51724b240b4e2 *DESCRIPTION
96cd52570a9a1c4863716d7e1a52510d *NAMESPACE
de486ac1f425b04fbb403fb1a071142b *NEWS
4c7776f3a60c386fa932c50f46009977 *R/00classes.R
6c713ff4fab0124861fa5288cf1aa6a0 *DESCRIPTION
d2155d739b9edf23acb03d29c0167560 *NAMESPACE
a345e358fd661ef77d9b04fb4a1d497b *NEWS
6331dde1ac9c8dbbe8e76c99bee595f2 *R/00classes.R
579e8b2641f3e8a5178eba4a297314f1 *R/Imin.R
8c3648e41405f1aa7f68faffe5ba2efa *R/IntInNode.r
f00557c10fd736d2f515eec0b22c285f *R/OpenMx.R
5b72ddd986870bd8e073676db942234a *R/Pars2Matrix.R
b92da836d47ecc0b7f2b48815e406c19 *R/amos.R
a12d237e8ab65edc2757040b398eccb4 *R/cvregsemplot.R
89ff726b3c2aa9772615acc067622404 *R/defExo.R
a148129fc1a655b4f125a49358697e7b *R/editFuns.R
8f3707a6268747000876753d89cc25d9 *R/factanal.R
f5fb2ffd916521a1f63d47490c7a03c7 *R/glm.R
5475c928a8b21487dfb7208eba80a749 *R/greplVarType.R
f21b6d9493451ecdbe3b98974bc33bab *R/isColor.R
b5888bd25f1e83dcdef363ad5b51762e *R/lavaan.R
e62786174242a3e3a758b5405aef918b *R/lavaan.R
db340141043be8e68780902e1465ef10 *R/lavaanModel.R
5adb76ba7df5c50bdf532aacc49424be *R/lisrelMat2RAM.R
1221e8a125bb29366df794486075aa28 *R/lisrelModel.R
9712136db8a6c349c63b2068d79de141 *R/lists.R
6c9247a19b360e63d9ab2f619e60ae57 *R/lists.R
b067b152cf18742ea06c9cc0b4e2900c *R/loadings.R
7f1a3ef88b527ae5b1495e3fe8834813 *R/mappingfuns.R
4d17fa82fa3781ff1ca86fc3d1f4e18b *R/modelMatrices.R
ba29d86c283bb917427f0fd91b1178f6 *R/mplus.R
79d6e5374d64dc7a6450693de1b96f5b *R/mplus.R
0e93679cadc5ac57360bbe1a36b1dbdf *R/onyx.R
69629ec92e90326d3aa630ac725cbb41 *R/operators.R
7622d921838cf952fbeaabe3caa5e894 *R/principal.R
b05fdedba97ed0e1a86f91ab12565180 *R/princomp.R
c5a5eba09d49930b6e0160a7b9ec6925 *R/ramModel.R
676e244f3f1fa6c1f5bd838b8c142916 *R/regsemplot.R
19b287a454a13bda0aaeef4094a41c4d *R/sem.R
2f61fd62584bf9c98bba51b97d80d3f4 *R/semCors.R
3b788e07050739e522904acf5c183363 *R/semMatrixAlgebra.R
f8cb61b043a65c952770b91b3fcfca4e *R/semPaths.R
54a416fe9b76c32e914eb46bb9c1ffc8 *R/semPaths.R
2f263f9f0d9b3323ad2cdac9132664e4 *R/semPathsHelperFuns.R
492f9b0d221bdcc8601974802df5bbc1 *R/semSyntax.R
685428c6eeee5aaca688f466d517c4f2 *R/semspec.R
Expand All @@ -41,16 +43,18 @@ eb883c696362d7353bd74cb606fa6e23 *R/standardizeRAM_2.R
f9721ef43e5f912ddea844bafbf43ec5 *README
600343cabf23256660d9adc754f3f6e4 *inst/COPYRIGHTS
fe8f33483833e151113dced7d32ca2ff *man/Imin.Rd
6485f1332059c3deb3601786ff6cafb3 *man/cvregsemplot.Rd
dfd6670b4e9fc9fb2e63169fbcdf5783 *man/edits.Rd
c55952e755b8121768815bb2634be5f1 *man/lisrelModel.Rd
be9227da2ee17e68b646df700c4ce800 *man/modelMatrices.Rd
ac4887c32ddfead1ecf9d1bec73df9a8 *man/modelMatrices.Rd
ee8008d40ba3d4c6391a4d44c8c95c56 *man/ramModel.Rd
916a25b62e55877c4a1371a7185276bd *man/regsemplot.Rd
5c6f88a5afd453c7a93137e70ecb8732 *man/semCors.Rd
512a8e0140b61ad7ff8bf3bca8038d8e *man/semMatrixAlgebra.Rd
7cebc5ca573b167c6bb6f26241e7f585 *man/semPaths.Rd
7fcdabc526259cdaa114ff3b2fb9f6aa *man/semPlot-package.Rd
e5996043cd0f0d7f8bc03b8dd621c366 *man/semPlotModel-class.Rd
22750cd7bc8ba837d473b9647350af2a *man/semPlotModel.Rd
c4fced0a3e226caed2d7422da3483664 *man/semPlotModel.Rd
5a26e6059f4f9f0a488631d89df21a97 *man/semPlotModel.S4-methods.Rd
115cd8caf7dc32804aad0cf9cb3a86d0 *man/semSyntax.Rd
98aebe08c8a4c48a6c36c81ec0b37f39 *man/tricks.Rd
10 changes: 8 additions & 2 deletions NAMESPACE
@@ -1,4 +1,5 @@
export(semPaths,semPlotModel,semCors,lisrelModel,ramModel,semSyntax,semMatrixAlgebra,modelMatrices,Imin,semPlotModel_lavaanModel)
export(semPaths,semPlotModel,semCors,lisrelModel,ramModel,semSyntax,
semMatrixAlgebra,modelMatrices,Imin,semPlotModel_lavaanModel)

# export Classes
exportClasses(
Expand Down Expand Up @@ -26,13 +27,16 @@ S3method(semPlotModel,msemObjectiveML)
export(semPlotModel_Onyx)
export(semPlotModel_Amos)
export(exo,"exo<-",endo,"endo<-",lat,"lat<-",man,"man<-")
S3method(semPlotModel,regsem)
S3method(semPlotModel,cvregsem)

# importFrom(MplusAutomation,"readModels")
importFrom(sem,"sem","standardizedCoefficients","specifyModel")
importFrom(lavaan,"lavaan","cfa","standardizedSolution", "standardizedsolution", "parameterEstimates", "parameterestimates","inspect","lavaanNames","lavaanify")
importClassesFrom(lavaan,"lavaan")
importFrom(stats,"factanal")
importFrom(rockchalk,standardize)
importFrom(regsem, "regsem","cv_regsem")
import(plyr)
import(lisrelToR)
import(XML)
Expand All @@ -47,4 +51,6 @@ importFrom(corpcor,"pseudoinverse")
importFrom("graphics", "lines", "par", "text")
importFrom("stats", "ave", "coef", "cov", "cov2cor", "loadings",
"median", "pnorm", "weighted.mean")
importFrom("utils", "packageDescription")
importFrom("utils", "packageDescription")


3 changes: 3 additions & 0 deletions NEWS
@@ -1,3 +1,6 @@
Changes in Version 1.1.1
o regsem and cv_regsem support added, thanks to Myrthe Veenman and Jason Nak!

Changes in Version 1.1
o Fixed a bug with lavaan input
o Fixed a bug with OpenMx 2 input
Expand Down
4 changes: 2 additions & 2 deletions R/00classes.R
Expand Up @@ -99,7 +99,7 @@ semPlotModel.default <- function(object,...)
head <- readLines(object, 10)
if (any(grepl("mplus",head,ignore.case=TRUE)))
{
return(semPlotModel.mplus.model(object))
return(semPlotModel.mplus.model(object,...))
}

if (any(grepl("l\\s*i\\s*s\\s*r\\s*e\\s*l",head,ignore.case=TRUE)))
Expand All @@ -112,7 +112,7 @@ semPlotModel.default <- function(object,...)
mod <- try(semPlotModel_lavaanModel(object,...),silent=TRUE)
if (!"try-error"%in%class(mod)) return(mod)

mod <- try(semPlotModel.mplus.model(object),silent=TRUE)
mod <- try(semPlotModel.mplus.model(object,...),silent=TRUE)
if (!"try-error"%in%class(mod)) return(mod)

mod <- try(semPlotModel(readLisrel(object)),silent=TRUE)
Expand Down
89 changes: 89 additions & 0 deletions R/cvregsemplot.R
@@ -0,0 +1,89 @@


semPlotModel.cvregsem <- function(object,model,...){
if (missing(model)){
stop("Please supply lavaan model with 'model' argument!")
}
## Save parts of the output in objects
object1 <- object # parameters
object2 <- model@ParTable # lavaan parameters
varnames <- unique(c(object2$lhs, object2$rhs)) # all names
mannames <- model@Model@dimNames[[1]][1] # manifest variables
names(varnames) <- 'name'
names(mannames) <- 'manifest'

'%!in%' <- function(x,y)!('%in%'(x,y))

## Add the fixed relations to the parameter estimates of regsem
namelist <- strsplit(names(object1$final_pars)," ") # split names and operators
inout <- data.frame(1,2)
for(i in 1:length(namelist)){
inout[i,1] <- namelist[[i]][1]
inout[i,2] <- namelist[[i]][3]
} # create data frame of regsem variables

int <- data.frame(1,2)
for(i in 1:length(object2$lhs)){
int[i,1] <- ifelse(object2$op[i]=="~"|object2$op[i]=="~1",object2$rhs[i],object2$lhs[i])
int[i,2] <- ifelse(object2$op[i]=="~"|object2$op[i]=="~1",object2$lhs[i],object2$rhs[i])
} # create data frame of lavaan variables

## paste together
pinout <- with(inout, paste0(X1, X2))
pint <- with(int, paste0(X1, X2))

counter <- 0
for(i in 1:length(object2$free)){ # if free before,
if(object2$free[i] == 0){
object1$regest[i] <- 1
counter = counter + 1
} else{
object1$regest[i] <- object1$final_pars[i - counter]
}
} # match regsem estimates with lavaan variables, set fixed to 1


## Create a S4 list
semModel <- new("semPlotModel")

## Create a Pars data frame
semModel@Pars <- data.frame(
label = rep("", length(object2$id)),
lhs = ifelse(object2$op=="~"|object2$op=="~1",object2$rhs,object2$lhs), # first went from left to right without checking relationship
edge = "--",
rhs = ifelse(object2$op=="~"|object2$op=="~1",object2$lhs,object2$rhs),
est = object1$regest, # check if we should take estimates from other model, if estimates are same as in regsem
std = NA,
group = object2$group,
fixed = object2$free == 0,
par = object2$free,
stringsAsFactors=FALSE)
row.names(semModel@Pars) <- 1:length(object2$id)

## translate operators
semModel@Pars$edge[object2$op=="~~"] <- "<->"
semModel@Pars$edge[object2$op=="~*~"] <- "<->"
semModel@Pars$edge[object2$op=="~"] <- "~>"
semModel@Pars$edge[object2$op=="=~"] <- "->"
semModel@Pars$edge[object2$op=="~1"] <- "int"
semModel@Pars$edge[grepl("\\|",object2$op)] <- "|"

semModel@Pars <- semModel@Pars[!object2$op%in%c(':=','<','>','==','|','<', '>'),]

## Create a vars data frame
semModel@Vars <- data.frame(
name = varnames,
manifest = varnames[1:length(varnames)] %in% mannames$manifest[1:length(mannames$manifest)],
exogenous = NA,
stringsAsFactors = FALSE
)

## Miscellaneous data frames
semModel@Thresholds <- data.frame()
semModel@ObsCovs <- list()
semModel@ImpCovs <- list()
semModel@Computed <- FALSE
semModel@Original <- list(object)

return(semModel)
}
17 changes: 13 additions & 4 deletions R/lavaan.R
Expand Up @@ -9,8 +9,10 @@
## EXTRACT MODEL ###
setMethod("semPlotModel_S4",signature("lavaan"),function(object){

if (class(object)=="blavaan") class(object) <- 'lavaan'
if (class(object)!="lavaan") stop("Input must me a 'lavaan' object")


# Extract parameter estimates:
pars <- parameterEstimates(object,standardized=TRUE)
list <- inspect(object,"list")
Expand Down Expand Up @@ -76,11 +78,17 @@ setMethod("semPlotModel_S4",signature("lavaan"),function(object){
exogenous = NA,
stringsAsFactors=FALSE)

if (!is.null(object@SampleStats@res.cov[[1]])){
semModel@ObsCovs <- object@SampleStats@res.cov
if (!is.null(object@SampleStats@res.cov) && !length(object@SampleStats@res.cov) == 0){
if (!is.null(object@SampleStats@res.cov[[1]])){
semModel@ObsCovs <- object@SampleStats@res.cov
} else {
semModel@ObsCovs <- object@SampleStats@cov
}
} else {
semModel@ObsCovs <- object@SampleStats@cov
}
semModel@ObsCovs <- list(matrix(NA,
length(varNames),length(varNames)))
}


names(semModel@ObsCovs) <- object@Data@group.label
for (i in 1:length(semModel@ObsCovs))
Expand All @@ -90,6 +98,7 @@ setMethod("semPlotModel_S4",signature("lavaan"),function(object){

semModel@ImpCovs <- object@Fit@Sigma.hat
names(semModel@ImpCovs) <- object@Data@group.label

for (i in 1:length(semModel@ImpCovs))
{
rownames(semModel@ImpCovs[[i]]) <- colnames(semModel@ImpCovs[[i]]) <- object@Data@ov.names[[i]]
Expand Down
6 changes: 3 additions & 3 deletions R/lists.R
@@ -1,7 +1,7 @@

semPlotModel.list <- function(object, ...)
semPlotModel.list <- function(object,...)
{
if ("mplus.model"%in%class(object)) return(semPlotModel.mplus.model(object))
if ("mplus.model"%in%class(object)) return(semPlotModel.mplus.model(object,...))

mod <- try(semPlotModel_lavaanModel(object,...),silent=TRUE)
if (!"try-error"%in%class(mod)) return(mod)
Expand All @@ -14,4 +14,4 @@ semPlotModel.list <- function(object, ...)
for (i in 2:length(object)) Res <- Res + object[[i]]
return(Res)
} else return(object)
}
}

0 comments on commit b3b1ac7

Please sign in to comment.