Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in multi-species occupancy models prediction #13

Closed
Xuletajr opened this issue Sep 1, 2022 · 3 comments
Closed

Error in multi-species occupancy models prediction #13

Xuletajr opened this issue Sep 1, 2022 · 3 comments

Comments

@Xuletajr
Copy link

Xuletajr commented Sep 1, 2022

Hi Jeff,

I've tried to make prediction for the latent occupancy at new locations for multi-species occupancy models (84 species; function = msPGOcc). However, I've receive the following error message:

"Error in t(as.matrix(X.fix[j, ])) %*% t(beta.samples[, sp.indx == i]) : non-conformable arguments". It seems this error occurs when you attempt to multiply two matrices.

Do you have any idea how I can fix this error in R?

Best regards

@doserjef
Copy link
Collaborator

doserjef commented Sep 1, 2022

Hi José,

Thanks for the note. You are correct that this error is happening when multiplying matrices that will generate the predicted occupancy probabilities. First make sure you are working with the latest version on CRAN (0.4.0), as version 0.4.0 did fix a problem in prediction for multi-species occupancy models when random effects were included when fitting the model. Here are two things I'll mention that could be causing the issue:

  1. If you fit your occupancy model with an intercept, make sure that the first column in the X.0 argument of the predict function is all 1s.
  2. If you included non-spatial random effects in the occupancy portion of the model and want to predict using new values of the random effects, make sure the ignore.RE argument is set to TRUE when calling predict and the column names in X.0 match the names of the variables used in the occ.formula argument you specified when you fit the msPGOcc function. If predicting without the random effects, set ignore.RE = FALSE and then X.0 should only contain the fixed effect covariates (and an intercept if applicable).

If none of that resolves the issue, feel free to email me your code and I'll take a look.

Jeff

@doserjef
Copy link
Collaborator

doserjef commented Sep 2, 2022

We determined this was happening as predict.msPGOcc() (and for other multi-species models in spOccupancy fails when X.0 is sent in as a data frame and not as a matrix. Converting the data frame to as.matrix() results in the prediction working properly. I will allow X.0 to be a data frame or matrix for all predict functions in spOccupancy in the next CRAN release and will leave this open until then.

@doserjef
Copy link
Collaborator

Updated on CRAN in v0.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants