library(rethinking)

G <- c("D","ND")
Purple <- c(670, 601)
Pink <- c(315,604)
Total <- c(985, 1205)
GID <- c(1,2)
Data <- data.frame(G, Purple, Pink, Total, GID)

model_1a <- quap(
  alist(
    Purple ~ dbinom(Total,p) , 
    Total <- Total[ID] ,
    p <- a[ID] ,
    a[ID] ~ dbeta(10,10)    
  ) , data = Data)
precis(model_1a, depth=2)

When I run this problem it throws me the error:

# Error in quap(alist(Purple ~ dbinom(Total, p), Total <- Total[ID], p <- a[ID],  : non-finite value supplied by optim".

Even though I have the same thing as my professor did in one of his lectures, his model runs, mine does not.

I am just trying to get done my lab assignment following the help video my professor posted, and I am running into this issue.

1

There are 1 best solutions below

0
IRTFM On

It takes a long time to assemble all the dependencies but after running the code and looking at the arguments inside the quap call, I noticed there was no definition for ID and wondered if it might be a triple typo (ID -> GID):

model_1a <- quap(
    alist(
        Purple ~ dbinom(Total,p) , 
        Total <- Total[GID] ,
        p <- a[GID] ,
        a[GID] ~ dbeta(10,10)    
    ) , data = Data)
precis(model_1a, depth=2)
#-----------------
     mean   sd 5.5% 94.5%
a[1] 0.68 0.01 0.65  0.70
a[2] 0.50 0.01 0.48  0.52

Seems to have been so.