Skip to content

Instantly share code, notes, and snippets.

@MJacobs1985
Last active December 2, 2021 13:07
Show Gist options
  • Select an option

  • Save MJacobs1985/1935cedb191351af0138ebe2658836ad to your computer and use it in GitHub Desktop.

Select an option

Save MJacobs1985/1935cedb191351af0138ebe2658836ad to your computer and use it in GitHub Desktop.
d<-Book%>%dplyr::select(ADG,ADF,Country, Challenge)
d$Country<-as.factor(d$Country);levels(d$Country)
d$Challenge<-as.factor(d$Challenge);levels(d$Challenge)
d$Country_id <- as.integer(d$Country )
d$Challenge_id <- as.integer(d$Challenge )
m5.9 <- quap(
alist(
ADG ~ dnorm( mu , sigma ),
mu <- a[Country_id],
a[Country_id] ~ dnorm(0 , 0.5 ),
sigma ~ dexp( 1 )
) , data=d )
labels <- paste( "a[" , 1:5 , "]:" , levels(d$Country ) , sep="" )
plot(precis( m5.9 , depth=2 , pars="a" ) , labels=labels ,
xlab="expected kcal (std)" )
WAIC(m5.9)
m5.10 <- quap(
alist(
ADG ~ dnorm( mu , sigma ),
mu <- a[Country_id] +b[Challenge_id],
a[Country_id] ~ dnorm(0 , 0.5 ),
b[Challenge_id] ~ dnorm(0 , 0.5 ),
sigma ~ dexp( 1 )
) , data=d )
plot(precis(m5.10, depth=2))
post <- extract.samples(m5.10)
plot(a[,1] ~ a[,2] , post , col=col.alpha(rangi2,0.1) , pch=16 )
rethinking::compare(m5.9, m5.10, func=WAIC )
plot(rethinking::compare(m5.9, m5.10, func=WAIC ))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment