R/Input_floads.R

Defines functions loading.value

Documented in loading.value

#' @title This function specifies the factor loading values.
#' @description The user specifies the factor loadings as a matrix. The values should be given by column for each factor.
#' Columns represent factors and rows represent items.
#' The values entered should be larger than 0 and smaller than 1.
#' Please see the example for a loading matrix for a three-factor model.
#' @author Fatih Orçan
#' @param nf the number of factor/s.
#' @param fl.loads vector of factor loadings
#' @return The function returns the factor loading matrix. The number of columns shows the number of factors in the model. The rows show the number of items
#' @export
#' @examples
#' # This example represents a three-factor CFA model
#' #  where the factors are indicated by 3, 3, and 2 items respectively.
#' #
#' loading.value(nf=3, fl.loads=c(.6,.6,.6,0,0,0,0,0,0,0,0,.7,.7,.7,0,0,0,0,0,0,0,0,.8,.8))

loading.value <-function(nf, fl.loads){

  fl.matx<-matrix(ncol = nf, fl.loads)
  colSums(fl.matx !=0)
  if(nf==1 & length(fl.loads)<=2){stop("Note: One-factor models should have at least 3 items.
                                      Please re-run the function.")}
  if(nf > 1 & any(colSums(fl.matx !=0)<2)){stop("Note: Multiple-factor models should have at least 2 items under each factor.
                                      Please re-run the function.")}
  if (any(fl.loads >= 1) | any(fl.loads < 0 )) {stop("Values of the factor loadings should be between 0 and 1.
                                      Please re-run the function.")}
    return(fl.matx)
}

Try the MonteCarloSEM package in your browser

Any scripts or data that you put into this service are public.

MonteCarloSEM documentation built on May 29, 2024, 11:56 a.m.