Skip to content

Commit

Permalink
* IMPROVED: umx_score_scale tell user what the max response is for …
Browse files Browse the repository at this point in the history
…reversed items if they leave this blank

more \dontrun{}
  • Loading branch information
tbates committed May 25, 2020
1 parent e1282c8 commit 0f53a97
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 23 deletions.
29 changes: 19 additions & 10 deletions R/misc_and_utility.R
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,12 @@ umx_score_scale <- function(base= NULL, pos = NULL, rev = NULL, min= 1, max = NU
# = Reverse any items needing this =
# ==================================
if(!is.null(rev)){
umx_check(!is.null(max), "stop", "If there are reverse items, you must set 'max' (the highest possible score for an item) in umx_score_scale (note: min defaults to 1)")
if(is.null(max)){
maxs = umx_apply("max", data[ , paste0(base, rev), drop = FALSE], by = "columns", na.rm= TRUE)
message("If there are reverse items, you must set 'max' (the highest possible score for an item) in umx_score_scale (note: min defaults to 1)")
print(table(data[ , paste0(base, rev[1])] ))
stop("FYI, the max appears to be ", max(maxs))
}
revItems = data[,paste0(base, rev), drop= FALSE]
revItems = (max + min) - revItems
data[,paste0(base, rev)] = revItems
Expand Down Expand Up @@ -2939,6 +2944,18 @@ xmu_dot_rank <- function(vars, pattern, rank) {
#' toLabel= c('a','b','c'), fromType= "latent");
#' umx_msg(out$latents)
#'
#'
#' # ========================
#' # = Label a means matrix =
#' # ========================
#'
#' tmp = umxMatrix("expMean", "Full", 1, 4, free = TRUE, values = 1:4)
#' out = xmu_dot_mat2dot(tmp, cells = "left", from = "rows",
#' fromLabel= "one", toLabel= c("v1", "v2")
#' )
#' cat(out$str)
#'
#' \dontrun{
#' # ==============================================
#' # = Get a string which includes CI information =
#' # ==============================================
Expand All @@ -2954,15 +2971,7 @@ xmu_dot_rank <- function(vars, pattern, rank) {
#' toLabel= paste0("x", 1:5), fromType = "latent", model= m1);
#' umx_msg(out$str); umx_msg(out$latents)
#'
#' # ========================
#' # = Label a means matrix =
#' # ========================
#'
#' tmp = umxMatrix("expMean", "Full", 1, 4, free = TRUE, values = 1:4)
#' out = xmu_dot_mat2dot(tmp, cells = "left", from = "rows",
#' fromLabel= "one", toLabel= c("v1", "v2")
#' )
#' cat(out$str)
#' }
#'
xmu_dot_mat2dot <- function(x, cells = c("diag", "lower", "lower_inc", "upper", "upper_inc", "any", "left"), from = c("rows", "cols"), fromLabel = NULL, toLabel = NULL, showFixed = FALSE, arrows = c("forward", "both", "back"), fromType = NULL, toType = NULL, digits = 2, model = NULL, SEstyle = FALSE, p = list(str = "", latents = c(), manifests = c())) {
from = match.arg(from)
Expand Down
7 changes: 4 additions & 3 deletions R/xmu.R
Original file line number Diff line number Diff line change
Expand Up @@ -2051,13 +2051,14 @@ xmu_string2path <- function(from) {
#' @references - <https://tbates.github.io>, <https://github.com/tbates/umx>
#' @md
#' @examples
#' \dontrun{
#' require(umx); data(demoOneFactor)
#' manifests = names(demoOneFactor)
#'
#' m1 = umxRAM("get_CI_example", data = demoOneFactor, type = "cov",
#' umxPath("G", to = manifests),
#' umxPath(var = manifests),
#' umxPath(var = "G", fixedAt = 1.0)
#' umxPath(var = "G", fixedAt = 1)
#' )
#' m1 = umxCI(m1, run= "yes")
#'
Expand All @@ -2066,12 +2067,12 @@ xmu_string2path <- function(from) {
#' xmu_get_CI(model= m1, "x1_with_x1", SEstyle=TRUE, digits=3)
#'
#' # prefix (submodel) and suffix (e.g. std) are ignored if not needed
#' xmu_get_CI(model =m1, "x1_with_x1", prefix = "top.", suffix = "_std")
#' xmu_get_CI(model= m1, "x1_with_x1", prefix = "top.", suffix = "_std")
#'
#' \dontrun{
#' xmu_get_CI(fit_IP, label = "ai_r1c1", prefix = "top.", suffix = "_std")
#' xmu_get_CI(fit_IP, label = "ai_r1c1", prefix = "top.", SEstyle = TRUE, suffix = "_std")
#' }
#'
xmu_get_CI <- function(model, label, prefix = "top.", suffix = "_std", digits = 2, SEstyle = FALSE, verbose= FALSE){
# xmu_get_CI ?
# TODO xmu_get_CI: Look for CIs, if not found look for SEs, if not found compute with mxSE (high priority!)
Expand Down
22 changes: 13 additions & 9 deletions man/xmu_dot_mat2dot.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_get_CI.Rd

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

0 comments on commit 0f53a97

Please sign in to comment.