File: parse_parameters.R

package info (click to toggle)
r-cran-regsem 1.6.2+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 496 kB
  • sloc: cpp: 263; ansic: 15; makefile: 2
file content (24 lines) | stat: -rw-r--r-- 783 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#' Takes either a vector of parameter ids or a
#' vector of named parameters and returns a vector of parameter ids
#' @param x Parameter labels
#' @param model Lavaan model
#' @return NULL if undefined input. Else vector of parameter ids
#'
parse_parameters <- function(x, model)
{
  if (is.null(x)) {return(x)} else
  if (is.numeric(x)) {return (x)}
  else if (is.character(x)) {
    labels <- parTable(model)$label
    ids <- parTable(model)$free
    matching.ids <- which(labels %in% x)
    if (length(matching.ids)!=length(x)) {
      stop("Have to specify parameter number in pars_pen for equality constrained labels")
    }
    return(ids[matching.ids])

  } else {
    warning("Unknown class type passed to parse_parameters().")
    return(NULL)
  }
}