I want to fit a normal distribution that is truncated at some value L, but the T(L,) bit in my JAGS code is simply ignored. Using simulated data I've been able to replicate this behaviour on three different Windows machines, using JAGS 4.1 run from R >3.2 via the jagsUI package. In contrast, two colleagues who're running JAGS 3.4 get the right answer.
The code is here below, where I attempt to fit both the normal and the truncated normal model to the same truncated data set, but then get essentially the same estimates from both.
Thanks a lot for your help.
Best regards --- Marc
n<-1000# Number of values drawnmean<-600# Average body mass of male peregrinessd<-30# Inter-individual variability (SD)y<-rnorm(n,mean,sd)# draw n valuestrunc.limit<-560# Truncation limitytrunc<-y[y>trunc.limit]# left-truncate# Fit model with and without truncation in same BUGS model# Package datastr(bugs.data<-list(y1=ytrunc,y2=ytrunc,n=length(ytrunc),trunc.limit=trunc.limit))# Write model in BUGS languagecat(file="model.txt","model{# Submodel using the original model that ignores the truncation# Priorsmu1~dnorm(0,1.0E-06)tau1<-pow(sd1,-2)sd1~dunif(0,1000)# Likelihood for data assumed without truncationfor(iin1:n){y1[i]~dnorm(mu1,tau1)}# Submodel for truncated data# Priorsmu2~dnorm(0,1.0E-06)tau2<-pow(sd2,-2)sd2~dunif(0,1000)# Likelihood for truncated datafor(iin1:n){y2[i]~dnorm(mu2,tau2)T(trunc.limit,)}}")inits<-function()list(mu1=rnorm(1))# initsparams<-c("mu1","sd1","mu2","sd2")ni<-2000;nt<-1;nb<-1000;nc<-3# Call JAGS from R, check convergence and look at estimateslibrary(jagsUI)out<-jags(bugs.data,inits,params,"model.txt",n.chains=nc,n.thin=nt,n.iter=ni,n.burnin=nb)print(out3,3)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Confirmed. I can't see anything wrong with the code for the truncated likelihood so I'm going to have to step through your example to see where it is going wrong.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes there is a bug. It's one of those tiny ones that is virtually impossible to see unless you pay attention with a "<" instead of a ">". The truncated likelihood evaluation is now working.
I recently stumbled upon this exact situation in JAGS 4.3.1 for Apple silicon (M1). I will test in a linux machine if T(,) is ignored as well. But I was wondering if the bug was fixed or maybe is an Apple M1 specific issue.
Many thanks,
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I would be surprised if this exact problem came back. Marc's example still works correctly for me. If you can share a reproducible example of your problem then that will help.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I can confirm that T(,) behaves (in general) as expected on Apple silicon (and the official binary passed the test suite before being released). But if you can share a reproducible example I can run it on the same hardware to double check your use case.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you for looking into this. I discovered I specified the truncation in the wrong way. After re-reading the manual, and fix it according to what is specified in page 35. My apologies for the lack of clarity in the post and also lack of a reproducible example in my previous post.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
.Much obliged to you for investigating this. I found I determined the truncation in the incorrect manner. After re-perusing the manual, and fix it as per what is determined in page. My conciliatory sentiments for the absence of lucidity in the post and furthermore absence of a reproducible model in my past post.
Last edit: lisa302 2023-07-23
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Dear all,
I want to fit a normal distribution that is truncated at some value L, but the T(L,) bit in my JAGS code is simply ignored. Using simulated data I've been able to replicate this behaviour on three different Windows machines, using JAGS 4.1 run from R >3.2 via the jagsUI package. In contrast, two colleagues who're running JAGS 3.4 get the right answer.
The code is here below, where I attempt to fit both the normal and the truncated normal model to the same truncated data set, but then get essentially the same estimates from both.
Thanks a lot for your help.
Best regards --- Marc
Confirmed. I can't see anything wrong with the code for the truncated likelihood so I'm going to have to step through your example to see where it is going wrong.
Great, thank you, Martyn. This almost drove me mad yesterday !
Best regards --- Marc
Yes there is a bug. It's one of those tiny ones that is virtually impossible to see unless you pay attention with a "<" instead of a ">". The truncated likelihood evaluation is now working.
A bug that just gives you the wrong answer without any warning is the worst kind of bug. I'm going to publish a new version of JAGS with the bug fix.
Great, thanks.
Marc
I just need to add some unit tests to the test suite to make sure this does not come back.
Hi all,
I recently stumbled upon this exact situation in JAGS 4.3.1 for Apple silicon (M1). I will test in a linux machine if T(,) is ignored as well. But I was wondering if the bug was fixed or maybe is an Apple M1 specific issue.
Many thanks,
I would be surprised if this exact problem came back. Marc's example still works correctly for me. If you can share a reproducible example of your problem then that will help.
I can confirm that T(,) behaves (in general) as expected on Apple silicon (and the official binary passed the test suite before being released). But if you can share a reproducible example I can run it on the same hardware to double check your use case.
Hi all,
Thank you for looking into this. I discovered I specified the truncation in the wrong way. After re-reading the manual, and fix it according to what is specified in page 35. My apologies for the lack of clarity in the post and also lack of a reproducible example in my previous post.
.Much obliged to you for investigating this. I found I determined the truncation in the incorrect manner. After re-perusing the manual, and fix it as per what is determined in page. My conciliatory sentiments for the absence of lucidity in the post and furthermore absence of a reproducible model in my past post.
Last edit: lisa302 2023-07-23