rmcelreath / rethinking

Statistical Rethinking course and book package
2.1k stars 596 forks source link

quap allows incorrect(?) definition with categorical variable #436

Closed michaldanaj closed 2 weeks ago

michaldanaj commented 3 weeks ago

In mu definition, I omtited the index variable. Quap accepted it and gave results substantially different than with indexes. I think it's a bug, as there are no alpha and beta parameters defined, but alpha_S and beta_S.

  library(rethinking)
  data("Howell1")
  d <- Howell1[Howell1$age < 13,]
  d$S <- d$male + 1

  m2.3<- quap(
    alist(
      weight ~ dnorm(mu, sigma),
      mu <- alpha + beta * age,
      #mu <- alpha[S] + beta[S] * age,
      sigma ~ dexp(1/10),

      alpha[S] ~ dnorm(3,4),
      beta[S] ~ dunif(0,10)

    ), data = d
    ,start=list(alpha=10, beta=3, sigma=10)
  )

posterior2.3 <- precis(m2.3, depth = 2)
posterior2.3
rmcelreath commented 2 weeks ago

Seems to work as intended, in the sense that you defined vectors for alpha and beta and then used the vectors in the linear model. This means that "alpha" is the name if the whole vector, which you declared in the model code.