Skip to content

Help needed: unmarkedMultFrame dimension mismatch in yearlySiteCovs

1 message · MOHAMED EL MEKKAOUI

#
Dear R-sig-ecology community,

I am currently using the unmarked package to create a unmarkedMultFrame for
analyzing wildlife data. I am facing an issue where the yearlySiteCovs
object, which I am passing as one of the arguments, contains elements that
appear as "arrays" rather than matrices, despite my efforts to convert them.

Here's the context:
yearlySiteCovs contains three periods (period1, period2, period3), each
having dimensions 368x18.
However, when I check the class of each element in yearlySiteCovs, I see
that they are reported as "arrays" instead of matrices.
Even after using functions like as.matrix() and drop(), the elements are
still identified as arrays, which is causing issues when I try to run the
unmarkedMultFrame model.

Example script:
# My yearlySiteCovs is a list containing three periods
yearlySiteCovs <- list(
  period1 = matrix(c(1, 2, 3, 4), nrow = 368, ncol = 18),
  period2 = matrix(c(2, 3, 4, 5), nrow = 368, ncol = 18),
  period3 = matrix(c(3, 4, 5, 6), nrow = 368, ncol = 18)
)
# Attempt to convert to matrix
yearlySiteCovs <- lapply(yearlySiteCovs, function(x) {
  if (is.array(x)) {
    x <- as.vector(x)  # Flatten the array
    x <- matrix(x, nrow = 368, ncol = 18, byrow = TRUE)
  }
  return(x)
})

sapply(yearlySiteCovs, function(x) c(class(x), dim(x)))
    period1  period2  period3
[1,] "matrix" "matrix" "matrix"
*[2,] "array"  "array"  "array"*
[3,] "368"    "368"    "368"
[4,] "18"     "18"     "18"

Despite these efforts, the issue persists, and I receive the error:

"*At least one element of yearlySiteCovs has an incorrect number of
dimensions.*"

What I've tried:
I have used as.matrix(), drop(), and other standard methods to flatten and
convert the arrays into matrices.
I verified the dimensions of all the objects in yearlySiteCovs, and they
all appear to have the correct dimensions (368 rows and 18 columns).
I confirmed the format of y_matrix_processed, siteCovs, and obs_covs, all
of which are correctly formatted.
Could anyone help me understand why the "array" issue persists, and how I
can resolve it to ensure that yearlySiteCovs works correctly with
unmarkedMultFrame?

Any insights or suggestions would be greatly appreciated!

Thank you in advance!

-- 

*Mohamed EL Mekkaoui*
*Doctorant - Chercheur* *Laboratoire de Biodiversit?, ?cologie et G?nome (*
BGCG*)* Facult? des Sciences, Universit? Mohammed V de Rabat

*LinkedIn :* <http://goog_85098632>linkedin.com/in/mohamed-el-mekkaoui

*Email :* mohamedelmekkaoui98 at gmail.com

*T?l :* +212 7 08 00 50 71