stan-dev / projpred

Projection predictive variable selection
https://mc-stan.org/projpred/
Other
110 stars 26 forks source link

Quick fix for bug introduced by #433 #434

Closed fweber144 closed 1 year ago

fweber144 commented 1 year ago

This is a quick fix for a bug introduced by PR #433. Illustration of the bug (the RDS file is available here):

arr1 <- readRDS("arr1.rds")
devtools::load_all()
str(arr2augmat(arr1, margin_draws = 1))

At the current state of master (commit 5717fd49ff69c844b01861ee113cff42fc60e2b6), the last line fails with the error

Error in `[.augvec`(ob, !is.na(ob)) : is_wholenumber(n_discr) is not TRUE

With this PR, the last line does not fail anymore.

It is only a quick fix because as a longer-term objective, it would probably be better to replace the role of attribute nobs_orig by an attribute that refers to the number of (possibly latent) response categories. The reason is that subsetting the rows of an augmented-rows matrix (or the elements of an augmented-length vector) is only legal in terms of the observations (individuals), not in terms of the (possibly latent) response categories. So the number of (possibly latent) response categories should always stay the same, in contrast to the number of observations. str() (and possibly other functions) may not adhere to the subsetting convention we are requiring, but even in those cases, it should be ok to assume the number of (possibly latent) response categories not to change (for str(), this is indeed correct). I'm sorry that the nobs_orig thing seems to have been a bad design choice from my side in PR #322.