Skip to content

Commit

Permalink
Rename create.mxModel to sem
Browse files Browse the repository at this point in the history
  • Loading branch information
mikewlcheung committed Aug 2, 2024
1 parent 8386ada commit 5402a0b
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 62 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: metaSEM
Type: Package
Title: Meta-Analysis using Structural Equation Modeling
Version: 1.4.5
Date: 2024-07-27
Date: 2024-08-01
Depends: R (>= 3.4.0), OpenMx
Imports: Matrix, MASS, ellipse, graphics, stats, utils, mvtnorm, numDeriv, lavaan
Suggests: metafor, semPlot, R.rsp, testthat, matrixcalc
Expand Down
12 changes: 6 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ S3method(plot, character)
S3method(plot, wls)
S3method(plot, osmasem)
S3method(plot, osmasem2)
S3method(plot, mxRAMmodel)
S3method(plot, sem)
# S3method(plot, osmasem3L)

S3method(summary, wls)
Expand All @@ -31,7 +31,7 @@ S3method(summary, Cor3L)
S3method(summary, bootuniR2)
S3method(summary, osmasem)
S3method(summary, osmasem2)
S3method(summary, mxRAMmodel)
S3method(summary, sem)
# S3method(summary, osmasem3L)
# S3method(summary, tssemRobust1)

Expand All @@ -41,7 +41,7 @@ S3method(anova, wls)
S3method(anova, reml)
S3method(anova, osmasem)
S3method(anova, osmasem2)
S3method(anova, mxRAMmodel)
S3method(anova, sem)
# S3method(anova, osmasem3L)

S3method(coef, tssem1FEM)
Expand All @@ -54,7 +54,7 @@ S3method(coef, meta3LFIML)
S3method(coef, reml)
S3method(coef, osmasem)
S3method(coef, osmasem2)
S3method(coef, mxRAMmodel)
S3method(coef, sem)
# S3method(coef, osmasem3L)
# S3method(coef, tssemRobust1)

Expand All @@ -68,7 +68,7 @@ S3method(vcov, meta3LFIML)
S3method(vcov, reml)
S3method(vcov, osmasem)
S3method(vcov, osmasem2)
S3method(vcov, mxRAMmodel)
S3method(vcov, sem)
# S3method(vcov, osmasem3L)
# S3method(vcov, tssemRobust1)

Expand All @@ -89,7 +89,7 @@ S3method(print, uniR1)
S3method(print, summary.CorPop)
S3method(print, summary.Cor3L)
S3method(print, summary.bootuniR2)
S3method(print, summary.mxRAMmodel)
S3method(print, summary.sem)

# required by R3.3
importFrom("graphics", "abline", "arrows", "layout", "par", "plot",
Expand Down
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Release 1.4.5 (Aug 1, 2024)
====================================
Rename create.mxModel() to sum().

Release 1.4.4 (Jul 27, 2024)
====================================
* Add osmasem2() and friends.
Expand Down
2 changes: 1 addition & 1 deletion R/rerun.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ rerun <- function(object, autofixtau2=FALSE, extraTries=10, ...) {
"meta3LFIML", "reml",
"tssem1FEM.cluster", "wls.cluster",
"osmasem", "osmasem2", "osmasem3L",
"MxModel", "mxRAMmodel")))
"MxModel", "sem")))
stop("'object' must be an object of neither class 'meta', 'meta3LFIML',
'wls', 'reml', 'tssem1FEM', 'tssem1REM', 'tssem1FEM.cluster', 'wls.cluster',
'osmasem', 'osmasem2', 'osmasem3L', 'MxModel', or 'mxRAMModel'.")
Expand Down
72 changes: 42 additions & 30 deletions R/create.mxModel.R → R/sem.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
## intervals.type="LB", it returns an error because some parameters are
## replaced with the new parameters in the constraints. However, the
## names of these new parameters are not in the CI object.
create.mxModel <- function(model.name="mxModel", RAM=NULL, data=NULL,
Cov=NULL, means=NULL, numObs,
intervals.type=c("z", "LB"), startvalues=NULL,
replace.constraints=FALSE, mxModel.Args=NULL,
run=TRUE, silent=TRUE, ...) {
sem <- function(model.name="sem", RAM=NULL, data=NULL, Cov=NULL,
means=NULL, numObs, intervals.type=c("z", "LB"),
startvalues=NULL, replace.constraints=FALSE,
mxModel.Args=NULL, run=TRUE, silent=TRUE, ...) {

intervals.type <- match.arg(intervals.type)

Expand All @@ -21,7 +20,6 @@ create.mxModel <- function(model.name="mxModel", RAM=NULL, data=NULL,
## Extract all observed and latent variable names
var.names <- colnames(Fmatrix$values)


## Without raw data
if (is.null(data)) {
## Without means
Expand Down Expand Up @@ -218,13 +216,27 @@ create.mxModel <- function(model.name="mxModel", RAM=NULL, data=NULL,

out <- list(mx.fit=mx.fit, RAM=RAM, data=data, mxalgebras=mxalgebras.ci,
intervals.type=intervals.type)
class(out) <- "mxRAMmodel"
class(out) <- "sem"
out
}

summary.mxRAMmodel <- function(object, robust=FALSE, ...) {
if (!is.element("mxRAMmodel", class(object)))
stop("\"object\" must be an object of class \"mxRAMmodel\".")
## Will be depreciated in the future
create.mxModel <- function(model.name="sem", RAM=NULL, data=NULL,
Cov=NULL, means=NULL, numObs,
intervals.type=c("z", "LB"), startvalues=NULL,
replace.constraints=FALSE, mxModel.Args=NULL,
run=TRUE, silent=TRUE, ...) {
.Deprecated("create.mxModel")
sem(model.name=model.name, RAM=RAM, data=data, Cov=Cov, means=means,
numObs=numObs, intervals.type=intervals.type, startvalues=startvalues,
replace.constraints=replace.constraints, mxModel.Args=mxModel.Args,
run=run, silent=silent, ...)
}


summary.sem <- function(object, robust=FALSE, ...) {
if (!is.element("sem", class(object)))
stop("\"object\" must be an object of class \"sem\".")

# calculate coefficients
my.mx <- summary(object$mx.fit)
Expand Down Expand Up @@ -308,13 +320,13 @@ summary.mxRAMmodel <- function(object, robust=FALSE, ...) {
Minus2LL=my.mx$Minus2LogLikelihood,
Mx.status1=object$mx.fit@output$status[[1]],
informationCriteria=informationCriteria)
class(out) <- "summary.mxRAMmodel"
class(out) <- "summary.sem"
out
}

print.summary.mxRAMmodel <- function(x, ...) {
if (!is.element("summary.mxRAMmodel", class(x))) {
stop("\"x\" must be an object of class \"summary.mxRAMmodel\".")
print.summary.sem <- function(x, ...) {
if (!is.element("summary.sem", class(x))) {
stop("\"x\" must be an object of class \"summary.sem\".")
}

cat("95% confidence intervals: ")
Expand Down Expand Up @@ -343,16 +355,16 @@ print.summary.mxRAMmodel <- function(x, ...) {
if (!(x$Mx.status1 %in% c(0,1))) warning("OpenMx status1 is neither 0 or 1. You are advised to 'rerun' it again.\n")
}

coef.mxRAMmodel <- function(object, ...) {
if (!is.element("mxRAMmodel", class(object)))
stop("\"object\" must be an object of class \"mxRAMmodel\".")
coef.sem <- function(object, ...) {
if (!is.element("sem", class(object)))
stop("\"object\" must be an object of class \"sem\".")

coef(object$mx.fit)
}

vcov.mxRAMmodel <- function(object, robust=FALSE, ...) {
if (!is.element("mxRAMmodel", class(object)))
stop("\"object\" must be an object of class \"mxRAMmodel\".")
vcov.sem <- function(object, robust=FALSE, ...) {
if (!is.element("sem", class(object)))
stop("\"object\" must be an object of class \"sem\".")

if (robust) {
suppressMessages(imxRobustSE(object$mx.fit, details=TRUE)$cov)
Expand All @@ -361,24 +373,24 @@ vcov.mxRAMmodel <- function(object, robust=FALSE, ...) {
}
}

anova.mxRAMmodel <- function(object, ..., all=FALSE) {
anova.sem <- function(object, ..., all=FALSE) {
base <- lapply(list(object), function(x) x$mx.fit)
comparison <- lapply(list(...), function(x) x$mx.fit)
mxCompare(base=base, comparison=comparison, all=all)
}

plot.mxRAMmodel <- function(x, manNames=NULL, latNames=NULL,
labels=c("labels", "RAM"), what="est", nCharNodes=0,
nCharEdges=0, layout=c("tree", "circle", "spring",
"tree2", "circle2"),
sizeMan=8, sizeLat=8, edge.label.cex=1.3,
color="white", weighted=FALSE, ...) {

plot.sem <- function(x, manNames=NULL, latNames=NULL,
labels=c("labels", "RAM"), what="est", nCharNodes=0,
nCharEdges=0, layout=c("tree", "circle", "spring",
"tree2", "circle2"),
sizeMan=8, sizeLat=8, edge.label.cex=1.3,
color="white", weighted=FALSE, ...) {
if (!requireNamespace("semPlot", quietly=TRUE))
stop("\"semPlot\" package is required for this function.")

if (!inherits(x, "mxRAMmodel"))
stop("'mxRAMmodel' object is required.\n")
if (!inherits(x, "sem"))
stop("'sem' object is required.\n")

A <- x$mx.fit@matrices$Amatrix$values
S <- x$mx.fit@matrices$Smatrix$values
Expand Down
4 changes: 2 additions & 2 deletions man/anova.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
\alias{anova.reml}
\alias{anova.osmasem}
\alias{anova.osmasem2}
\alias{anova.mxRAMmodel}
\alias{anova.sem}
\title{Compare Nested Models with Likelihood Ratio Statistic
}
\description{It compares nested models with the likelihood ratio
Expand All @@ -18,7 +18,7 @@
\method{anova}{reml}(object, \dots, all=FALSE)
\method{anova}{osmasem}(object, \dots, all=FALSE)
\method{anova}{osmasem2}(object, \dots, all=FALSE)
\method{anova}{mxRAMmodel}(object, \dots, all=FALSE)
\method{anova}{sem}(object, \dots, all=FALSE)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
Expand Down
8 changes: 4 additions & 4 deletions man/coef.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
\alias{coef.reml}
\alias{coef.osmasem}
\alias{coef.osmasem2}
\alias{coef.mxRAMmodel}
\alias{coef.sem}

\title{Extract Parameter Estimates from various classes.
}
Expand All @@ -27,14 +27,14 @@
\method{coef}{reml}(object, \dots)
\method{coef}{osmasem}(object, select=c("fixed", "all", "random"), \dots)
\method{coef}{osmasem2}(object, select=c("fixed", "all", "random"), \dots)
\method{coef}{mxRAMmodel}(object, \dots)
\method{coef}{sem}(object, \dots)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
\item{object}{An object returned from either class
\code{tssem1FEM}, class \code{tssem1FEM.cluster}, class \code{tssem1REM},
class \code{wls}, class \code{wls.cluster}, class \code{meta}, class
\code{reml}, class \code{osmasem}, class \code{osmasem2}, or class \code{mxRAMmodel}
\code{reml}, class \code{osmasem}, class \code{osmasem2}, or class \code{sem}
}
\item{select}{Select \code{all} for both fixed- and random-effects parameters, \code{fixed} for the
fixed-effects parameters or \code{random} for the random-effects
Expand All @@ -43,7 +43,7 @@
}
\item{\dots}{Further arguments; currently none is used}
}
\note{\code{coef.mxRAMmodel} is simply a wraper of
\note{\code{coef.sem} is simply a wraper of
\code{omxGetParameters}. Extra arguments will be passed to it}

\value{Parameter estimates for both fixed-effects (if any) and random-effects (if any)
Expand Down
2 changes: 1 addition & 1 deletion man/metaSEM-package.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Package: \tab metaSEM\cr
Type: \tab Package\cr
Version: \tab 1.4.5\cr
Date: \tab 2024-07-27\cr
Date: \tab 2024-08-01\cr
License: \tab GPL (>=2)\cr
LazyLoad: \tab yes\cr
}
Expand Down
4 changes: 2 additions & 2 deletions man/plot.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
\alias{plot.wls}
\alias{plot.osmasem}
\alias{plot.osmasem2}
\alias{plot.mxRAMmodel}
\alias{plot.sem}

\title{Plot methods for various objects
}
Expand Down Expand Up @@ -48,7 +48,7 @@
layout=c("tree", "circle", "spring", "tree2", "circle2"),
sizeMan=8, sizeLat=8, edge.label.cex=1.3, color="white",
weighted=FALSE, \dots)
\method{plot}{mxRAMmodel}(x, manNames=NULL, latNames=NULL, labels=c("labels", "RAM"),
\method{plot}{sem}(x, manNames=NULL, latNames=NULL, labels=c("labels", "RAM"),
what="est", nCharNodes=0, nCharEdges=0,
layout=c("tree", "circle", "spring", "tree2", "circle2"),
sizeMan=8, sizeLat=8, edge.label.cex=1.3, color="white",
Expand Down
19 changes: 13 additions & 6 deletions man/create.mxModel.Rd → man/sem.Rd
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
\name{create.mxModel}
\name{sem}
\alias{sem}
\alias{create.mxModel}
\title{Create an mxModel
\title{Fit a structural equation model using OpenMx
}
\description{It creates a mxModel from a RAM object.
\description{It fits a structural equation model by creating a mxModel from a RAM object.
}
\usage{
create.mxModel(model.name="mxModel", RAM=NULL, data=NULL,
## Depreciated in the future
create.mxModel(model.name="sem", RAM=NULL, data=NULL,
Cov=NULL, means=NULL, numObs,
intervals.type=c("z", "LB"), startvalues=NULL,
replace.constraints=FALSE, mxModel.Args=NULL,
run=TRUE, silent=TRUE, ...)
sem(model.name="sem", RAM=NULL, data=NULL,
Cov=NULL, means=NULL, numObs,
intervals.type=c("z", "LB"), startvalues=NULL,
replace.constraints=FALSE, mxModel.Args=NULL,
run=TRUE, silent=TRUE, ...)
}
\arguments{
\item{model.name}{A string for the model name in \code{\link[OpenMx]{mxModel}}.
Expand Down Expand Up @@ -58,7 +65,7 @@ plot(model)

RAM <- lavaan2RAM(model, obs.variables=c("y", "x"))

my.fit <- create.mxModel(RAM=RAM, data=my.df)
my.fit <- sem(RAM=RAM, data=my.df)
summary(my.fit)

## A meta-analysis
Expand All @@ -72,7 +79,7 @@ plot(model)
RAM <- lavaan2RAM(model, obs.variables="yi", std.lv=FALSE)

## Use likelihood-based CI
my.fit <- create.mxModel(RAM=RAM, data=Hox02, intervals="LB")
my.fit <- sem(RAM=RAM, data=Hox02, intervals="LB")
summary(my.fit)
}
}
Expand Down
8 changes: 4 additions & 4 deletions man/summary.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
\alias{summary.bootuniR2}
\alias{summary.osmasem}
\alias{summary.osmasem2}
\alias{summary.mxRAMmodel}
\alias{summary.sem}
\alias{print.summary.tssem1FEM}
\alias{print.summary.tssem1FEM.cluster}
\alias{print.summary.wls}
Expand All @@ -22,7 +22,7 @@
\alias{print.summary.CorPop}
\alias{print.summary.Cor3L}
\alias{print.summary.bootuniR2}
\alias{print.summary.mxRAMmodel}
\alias{print.summary.sem}
\title{Summary Method for tssem1, wls, meta, and meta3LFIML Objects
}
\description{It summaries results for various class.
Expand All @@ -36,7 +36,7 @@
\method{summary}{meta}(object, homoStat=TRUE, robust=FALSE, \dots)
\method{summary}{meta3LFIML}(object, allX=FALSE, robust=FALSE, \dots)
\method{summary}{reml}(object, \dots)
\method{summary}{mxRAMmodel}(object, robust=FALSE, \dots)
\method{summary}{sem}(object, robust=FALSE, \dots)
\method{summary}{CorPop}(object, \dots)
\method{summary}{Cor3L}(object, \dots)
\method{summary}{bootuniR2}(object, probs=c(0, 0.1, 0.5, 0.9, 1),
Expand All @@ -49,7 +49,7 @@
\method{print.summary}{meta}(x, \dots)
\method{print.summary}{meta3LFIML}(x, \dots)
\method{print.summary}{reml}(x, \dots)
\method{print.summary}{mxRAMmodel}(x, \dots)
\method{print.summary}{sem}(x, \dots)
\method{print.summary}{CorPop}(x, \dots)
\method{print.summary}{Cor3L}(x, \dots)
\method{print.summary}{bootuniR2}(x, \dots)
Expand Down
4 changes: 2 additions & 2 deletions man/vcov.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
\alias{vcov.reml}
\alias{vcov.osmasem}
\alias{vcov.osmasem2}
\alias{vcov.mxRAMmodel}
\alias{vcov.sem}
\title{Extract Covariance Matrix Parameter Estimates from Objects of
Various Classes
}
Expand All @@ -27,7 +27,7 @@
\method{vcov}{reml}(object, \dots)
\method{vcov}{osmasem}(object, select=c("fixed", "all", "random"), robust=FALSE, \dots)
\method{vcov}{osmasem2}(object, select=c("fixed", "all", "random"), robust=FALSE, \dots)
\method{vcov}{mxRAMmodel}(object, robust=FALSE, \dots)
\method{vcov}{sem}(object, robust=FALSE, \dots)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
Expand Down
Loading

0 comments on commit 5402a0b

Please sign in to comment.