sim() from model with missing value imputation breaks with error "function merge_missing not found"

Open
#411 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
Half a day
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
r
Domain
backend

Research direction

The error comes from merge_missing being called inside sim() for a model fitted with ulam that has missing-value imputation, so start by checking where merge_missing is defined in the package and whether it is exported or reachable from the sim code path. Reproduce with the m15.5 snippet in the issue and confirm that sim(m15.5) fails. Done means the call succeeds and returns simulated outcomes, with a test covering a model that imputes missing values.

Written by the indexing model from the issue text.

Description

enhancement

I executed the code for model 15.5 from the book (for doing missing data imputation with primate milk data.
The model runs fine but when I try to sample from posterior distribution using sim() function an exception is raised with error

Error in merge_missing(B_missidx, to_vector(B), B_impute) : 
  could not find function "merge_missing"

Any idea how to fix it @rmcelreath ?

Full code to reproduce the bug:

library(rethinking)
data(milk)
d <- milk
d$neocortex.prop <- d$neocortex.perc / 100
d$logmass <- log(d$mass)
dat_list <- list(
K = standardize( d$kcal.per.g ),
B = standardize( d$neocortex.prop ),
M = standardize( d$logmass ) )
m15.5 <- ulam(
alist(
K ~ dnorm( mu , sigma ),
mu <- a + bB*B + bM*M,
B ~ dnorm( nu , sigma_B ),
c(a,nu) ~ dnorm( 0 , 0.5 ),
c(bB,bM) ~ dnorm( 0, 0.5 ),
sigma_B ~ dexp( 1 ),
sigma ~ dexp( 1 )
) , data=dat_list , chains=4 , cores=4 )
sim(m15.5)
Dominant language
R
Stars
2.4k
Forks
632
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rmcelreath/rethinking

All issues in rmcelreath/rethinking

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.