Learn R Programming

fungible (version 2.4.8)

Rmad: Generate a random R matrix with given MAD from a user-defined, population R

Description

Rmad(Rpop, MAD = .10, tries = 1E5, SEED = NULL)

Usage

Rmad(Rpop, MAD = 0.03, tries = 1e+05, SEED = NULL)

Value

  • R A random R matrix with a known MAD from Rpop.

  • Rpop The model-implied, population correlation matrix.

  • Delta The vector of model-errors.

  • H A hollow matrix used to create a fungible R matrix.

  • iter Iteration number at convergence (or max iteration number).

  • MAD The target mean absolute deviation.

  • converged. A Boolean that describes the convergence status of the optimization algorithm.

  • SEED The initial value for the random number generator.

Arguments

Rpop

(matrix) A model-implied, population correlation matrix.

MAD

(scalar) The desired mean absolute deviation value (i.e., \(mad(Rpop - R) = MAD\) where \(mad\) computes the mean absolute deviation for the nonredundant, non-diagonal values of its argument).

tries

(scalar) The maximum number of tries for the optimization algorithm. Default(\(tries = 1E5\)).

SEED

(numeric) The starting seed for the random number generator. If SEED is not supplied then the program will generate (and return) a randomly generated seed.

Author

Niels Waller

Examples

Run this code
 # Example 1
  Rpop <- matrix(.35, 6, 6)
  diag(Rpop) <- 1
  
  out <- Rmad(Rpop, MAD = .038, SEED = 123)
               
  out$R |> round(3)            
 
# E = mattix of model error values
  E = Rpop - out$R 
  mean(abs(E[lower.tri(E, diag = FALSE)]))
   

Run the code above in your browser using DataLab