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

sim() not working for models with simplex #440

Open
Famondir opened this issue Jul 28, 2024 · 0 comments
Open

sim() not working for models with simplex #440

Famondir opened this issue Jul 28, 2024 · 0 comments

Comments

@Famondir
Copy link

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:
grafik

The prediction of the model with simplex looks like:
grafik

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:
grafik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant