Skip to content

Commit

Permalink
* IMPROVED: umxEFA now has an option about reporting the summary fi…
Browse files Browse the repository at this point in the history
…t statistics of a model (default is FALSE) see #103

* TODO: `umxEFA` currently reports either the model or the loadings (or factor scores if requested).
Might be worth considering making scores a model attribute.... Not sure what this nicest UI is for a user just wanting scores.
  • Loading branch information
tbates committed Aug 31, 2019
1 parent a0972d5 commit 29d3aaa
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 34 deletions.
17 changes: 15 additions & 2 deletions R/lavanify2ram.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,24 @@
#' }
#'
#' @section Naming of multiple groups
#'
#' When multiple groups are found the groups are named "name_grouplevel"
#' White space is replaced with "_" and illegal characters are replaced with "x"
#'
#' *note*: Options for group.equal. In future, we might implement (but have not as yet):
#' 1. c("loadings"
#' 1. "intercepts"
#' 1. "means"
#' 1. "regressions"
#' 1. "residuals"
#' 1. "covariances"
#'
#' @param model A lavaan syntax string, e.g. "A~~B"
#' @param data Data to add to model (defaults to auto, which is just sketch mode)
#' @param lavaanMode Auto-magical path settings for cfa/sem (default) or no-defaults ("lavaan")
#' @param std.lv = FALSE Whether to set var of latents to 1 (default FALSE). nb. Toggles fix first.
#' @param group = Column to use for multi-group (default = NULL)
#' @param group.equal = what to equate across groups. Default (NULL) means no equates. Options that might be implemented (but not yet: c("loadings", "intercepts", "means", "regressions", "residuals", "covariances")
#' @param group.equal = what to equate across groups. Default (NULL) means no equates. See details for what we might implement in future.
#' @param std Whether to print estimates. Defaults to FALSE ("raw"), TRUE = "std", for no parameter table use NULL.
#' @param comparison Compare the new model to the old (if updating an existing model: default = TRUE)
#' @param type One of "Auto", "FIML", "cov", "cor", "WLS", "DWLS", "ULS"
Expand Down Expand Up @@ -144,7 +153,11 @@
#' # Formative factor
#' # lavaanify("f5 <~ z1 + z2 + z3 + z4")
#'
umxLav2RAM <- function(model = NA, data = "auto", group = NULL, group.equal= NULL, name = NA, lavaanMode = c("sem", "lavaan"), std.lv = FALSE, suffix = "", comparison = TRUE, type = c("Auto", "FIML", "cov", "cor", "WLS", "DWLS", "ULS"), allContinuousMethod = c("cumulants", "marginals"), autoRun = getOption("umx_auto_run"), tryHard = c("no", "yes", "mxTryHard", "mxTryHardOrdinal", "mxTryHardWideSearch"), verbose = FALSE, optimizer = NULL, std = FALSE, printTab = TRUE){
umxLav2RAM <- function(model = NA, data = "auto", group = NULL, group.equal= NULL, name = NA,
lavaanMode = c("sem", "lavaan"), std.lv = FALSE, suffix = "", comparison = TRUE,
type = c("Auto", "FIML", "cov", "cor", "WLS", "DWLS", "ULS"), allContinuousMethod = c("cumulants", "marginals"),
autoRun = getOption("umx_auto_run"), tryHard = c("no", "yes", "mxTryHard", "mxTryHardOrdinal", "mxTryHardWideSearch"),
verbose = FALSE, optimizer = NULL, std = FALSE, printTab = TRUE){
# TODO: make groups independent
# TODO: support group.equal Equality constraints across multiple
# groups: "loadings", "intercepts", "means", "regressions", "residuals", "covariances"
Expand Down
29 changes: 14 additions & 15 deletions R/umx_build_high_level_models.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@
#' @param x Either 1: data, 2: Right-hand-side ~ formula , 3: Vector of variable names, or 4: Name for the model.
#' @param factors Either number of factors to request or a vector of factor names.
#' @param data A dataframe you are modeling.
#' @param n.obs Number of observations in covmat (if provided, default = NA)
#' @param rotation A rotation to perform on the loadings (default = "varimax" (orthogonal))
#' @param scores Type of scores to produce, if any. The default is none, "Regression" gives Thompson's scores. Other options are 'ML', 'WeightedML', Partial matching allows these names to be abbreviated.
#' @param minManifests The least number of variables required to return a score for a participant (Default = NA).
#' @param name A name for your model
#' @param digits rounding (default = 2)
#' @param return by default, the resulting MxModel is returned. Say "loadings" to get a fact.anal object.
#' @param report Report as markdown to the console, or open a table in browser ("html")
#' @param summary run [umxSummary()] on the underlying umxRAM model? (Default = FALSE)
#' @param name A name for your model (default = efa)
#' @param digits rounding (default = 2)
#' @param n.obs Number of observations in if covmat provided (default = NA)
#' @param covmat Covariance matrix of data you are modeling (not implemented)
#' @return - EFA [mxModel()]
#' @family Super-easy helpers
Expand Down Expand Up @@ -112,9 +113,8 @@
#' m1 = umxEFA(name = "by_number", factors = 2, rotation = "promax", data = mtcars[, myVars])
#' x = umxEFA(name = "score", factors = "g", data = mtcars[, myVars], scores= "Regression")
#' }
umxEFA <- function(x = NULL, factors = NULL, data = NULL, n.obs = NULL,
scores = c("none", 'ML', 'WeightedML', 'Regression'), minManifests = NA,
rotation = c("varimax", "promax", "none"), name = "efa", digits = 2, return = c("model", "loadings"), report = c("markdown", "html"), covmat = NULL){
umxEFA <- function(x = NULL, factors = NULL, data = NULL, scores = c("none", 'ML', 'WeightedML', 'Regression'), minManifests = NA,
rotation = c("varimax", "promax", "none"), return = c("model", "loadings"), report = c("markdown", "html"), summary = FALSE, name = "efa", digits = 2, n.obs = NULL, covmat = NULL){
# TODO: umxEFA: Detect ordinal items and switch to DWLS?
rotation = xmu_match.arg(rotation, c("varimax", "promax", "none"), check = FALSE)
scores = match.arg(scores)
Expand Down Expand Up @@ -217,18 +217,17 @@ umxEFA <- function(x = NULL, factors = NULL, data = NULL, n.obs = NULL,
print("Results")
print(loadings(m1))
}
umxSummary(m1, digits = digits, report = report);
if(summary){
umxSummary(m1, digits = digits, report = report);
}

if(scores != "none"){
x = umxFactorScores(m1, type = scores, minManifests = minManifests)
} else {
if(return == "loadings"){
invisible(x)
}else if(return == "model"){
invisible(m1)
}else{
message(omxQuotes(return), " is not a legal option for 'return'")
}
}
if(return == "loadings"){
invisible(x)
}else if(return == "model"){
invisible(m1)
}
}

Expand Down
24 changes: 13 additions & 11 deletions man/umxEFA.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/umxLav2RAM.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/umx_explode.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/umx_names.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/xmu_describe_data_WLS.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 29d3aaa

Please sign in to comment.