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 handling / factors and chars #208

Merged
merged 2 commits into from
May 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions R/fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,17 @@ sdmTMB <- function(
if (identical(family$family[1], "binomial") && !delta) {
## call this to catch the factor / matrix cases
y_i <- model.response(mf[[1]], type = "any")
## allow character
if (is.character(y_i)) {
y_i <- model.response(mf[[1]], type = "factor")
if(nlevels(y_i) > 2) {
cli_abort("More than 2 levels detected for response")
}
}
if (is.factor(y_i)) {
if(nlevels(y_i) > 2) {
cli_abort("More than 2 levels detected for response")
}
## following glm, ‘success’ is interpreted as the factor not
## having the first level (and hence usually of having the
## second level).
Expand Down Expand Up @@ -1119,6 +1129,9 @@ sdmTMB <- function(
no_spatial = no_spatial
)

if(is.na(sum(nobs_RE))) {
cli_abort("One of the groups used in the factor levels is NA - please remove")
}
b_thresh <- matrix(0, 2L, n_m)
if (thresh[[1]]$threshold_func == 2L) b_thresh <- matrix(0, 3L, n_m) # logistic #TODO: change hard coding on index of thresh[[1]]

Expand Down