sim() not working for models with simplex
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Start by running the reproduction script in the issue: the ulam model m12.6 with a simplex[8] parameter delta, then sim() on it. Compare the simulated outcomes against the observed Trolley responses, and check how sim() handles simplex parameters versus the plain-parameter model m12.7, which works. The issue has no comments or linked pull request, so the cause is still open. Done means sim() on the simplex model produces a distribution matching the data, with a test covering it.
Written by the indexing model from the issue text.
Description
Hello everyone,
I faced odd results from sim() using it with (ulam) models that have simplex predictors in it. I tested it with a modified version of model m12.6:
data(Trolley)
d <- Trolley %>% sample_n(1000)
edu_levels <- c( 6 , 1 , 8 , 4 , 7 , 2 , 5 , 3 )
d$edu_new <- edu_levels[ d$edu ]
dat <- list(
R = d$response ,
action = d$action,
intention = d$intention,
contact = d$contact,
E = as.integer( d$edu_new ), # edu_new as an index
alpha = rep( 2 , 8 ) ) # delta prior
m12.6 <- ulam(
alist(
R ~ ordered_logistic( phi , kappa ),
phi <- bE*sum( delta[1:E] ) + bA*action + bI*intention + bC*contact,
kappa ~ normal( 0 , 1.5 ),
c(bA,bI,bC,bE) ~ normal( 0 , 1 ),
simplex[8]: delta ~ dirichlet( alpha )
), data=dat , chains=4 , cores=4 )
summary(m12.6)
temp <- sim(m12.6) %>% as_tibble()
d$response %>% hist()
temp %>% pivot_longer(everything()) %>% pull(value) %>% hist()
I had to estimate the first parameter of the simplex model as well instead setting it zero to get sim() working.
The original data looks like:
The prediction of the model with simplex looks like:
Using the model m12.7 works just fine:
dat$edu_norm <- normalize( d$edu_new )
m12.7 <- ulam(
alist(
R ~ ordered_logistic( mu , cutpoints ),
mu <- bE*edu_norm + bA*action + bI*intention + bC*contact,
c(bA,bI,bC,bE) ~ normal( 0 , 1 ),
cutpoints ~ normal( 0 , 1.5 )
), data=dat , chains=4 , cores=4 )
temp2 <- sim(m12.7) %>% as_tibble()
temp2 %>% pivot_longer(everything()) %>% pull(value) %>% hist()
The prediction looks well:
- 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
- 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.
More from rmcelreath/rethinking
-
Typo: p.381Open
Difficulty 1/5 Under an hour Newbie friendliness 95/100
rmcelreath/rethinking#482 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
rmcelreath/rethinking#476 ·
-
Typo: p.302Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
rmcelreath/rethinking#475 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 62/100
rmcelreath/rethinking#474 ·
-
Comma splice: p.557Open
Difficulty 1/5 Under an hour Newbie friendliness 90/100
rmcelreath/rethinking#471 ·
All issues in rmcelreath/rethinking
Similar issues
-
1.7
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
pharmaverse/admiral#3235 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
SticsRPacks/CroPlotR#185 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day