R/02_algebrahelpers_modelMatrix.R

Defines functions Mmatrix

# Form the model matrix M :
Mmatrix <- function(x){
  rows <- seq_len(nrow(x))[x$par!=0]
  cols <- x$par[x$par!=0]
  dims <- c(nrow(x),max(x$par))
  # Check for diagonal matrix:
  # if (all(rows == cols) && dims[1] == dims[2]){
  #   M <- Diagonal(dims[1]) # Diagonal matrix
  # } else {
    M <- sparseMatrix(i = rows, j = cols, dims = dims)
    M <- as(M, "dMatrix")
  # }
  return(M)
}

Try the psychonetrics package in your browser

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

psychonetrics documentation built on June 22, 2024, 10:29 a.m.