Error by `log_lik()` in case of observation weights
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 401
- Forks
- 136
- PR merge metrics
- No merged PRs in 30d
Description
Summary:
The log_lik.stanreg() method fails when observation weights exist.
Description:
As shown in the reproducible steps below, calling log_lik() in a situation where observation weights exist throws an error. In the example below, I specified argument weights in the call to log_lik() even though it does not exist (and the log_lik.stanreg() documentation for ... says "Currently ignored"). However, omitting argument weights in the log_lik() call leads to the same error.
Reproducible Steps:
data(df_gaussian, package = "projpred")
dat <- data.frame(y = df_gaussian$y, df_gaussian$x)
library(rstanarm)
options(mc.cores = parallel::detectCores(logical = FALSE))
set.seed(7352)
wobs <- sample.int(2, size = nrow(dat), replace = TRUE)
rfit <- stan_glm(y ~ X1 + X2 + X3 + X4 + X5,
data = dat,
weights = wobs,
seed = 1140350788)
nobs_new <- 3
dat_new <- setNames(as.data.frame(matrix(rnorm(nobs_new * 5), nrow = nobs_new)),
paste0("X", 1:5))
dat_new$y <- rnorm(nobs_new)
wobs_new <- sample.int(2, size = nobs_new, replace = TRUE)
ll_new <- log_lik(rfit,
newdata = dat_new,
weights = wobs_new)
## Throws:
# Error in `$<-.data.frame`(`*tmp*`, "weights", value = c(2L, 1L, 2L, 2L, :
# replacement has 100 rows, data has 3
##
RStanARM Version:
2.21.3
R Version:
4.2.1
Operating System:
Ubuntu 22.04 LTS
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the reproducible example for log_lik.stanreg() with observation weights, then inspect that entry point and the handling of newdata and weights. Done means log_lik() accepts weighted new observations without the data-frame row-count error, both when weights is supplied and when it is omitted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100