8000 sim() not working for models with simplex · Issue #440 · rmcelreath/rethinking · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
sim() not working for models with simplex #440
Open
@Famondir

Description

@Famondir

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0