# How does “thin” setting affect the number of samples in WinBUGS?

I do not understander how "thin" setting affects the number of samples in WinBUGS. Here is my case:

Case 1: In Model --> Update... -> Update Tool, I set updates 5000, refresh 100, thin 1, click update. In Inference -> Samples...-> sample is 4500 in stats

Case 2: In Model --> Update... -> Update Tool, I set updates 5000, refresh 100, thin 2, click update. In Inference -> Samples...-> sample is 4750 in stats

Case 3: In Model --> Update... -> Update Tool, I set updates 5000, refresh 100, thin 5, click update. In Inference -> Samples...-> sample is 4900 in stats

Case 4: In Model --> Update... -> Update Tool, I set updates 5000, refresh 100, thin 10, click update. In Inference -> Samples...-> sample is 4950 in stats

Based on WinBUGS User Manual, thin is the samples from every kth iteration will be stored, where k is the value of thin. Setting k > 1 can help to reduce the autocorrelation in the sample, but there is no real advantage in thinning except to reduce storage requirements and the cost of handling the simulations when very long runs are being carried out.

My questions are

1. In Case 1, why sample is 4500 not 5000?
2. How does the "thin" setting affect the sample size in Node Statistics?

The following is my code.

model {
for(i in 1: N) {
CF01[i] ~ dnorm(0, 20)
CF02[i]  ~ dnorm(0, 1)
h[i] ~ dpois (lambda [i])
log(lambda [i]) <- beta0 + beta1*CF03[i] + beta2*CF02[i] + beta3*CF01[i] + beta4*IND[i]
}
beta0 ~ dnorm(0.0, 1.0E-6)
beta1 ~ dnorm(0.0, 1.0E-6)
beta2 ~ dnorm(0.0, 1.0E-6)
beta3 ~ dnorm(0.0, 1.0E-6)
beta4  <- log(p)
p ~ dunif(lower, upper)
}

INITS
list(beta0 = 0, beta1 = 0, beta2 = 0, beta3 = 0, p = 0.9)

DATA(LIST)
list(N = 15, lower = 0.80, upper = 0.95,

h = c(1,4,1,2,1,2,1,1,1,3,3,0,0,0,NA),

CF03 = c(-1.5,0.1,1.0,0.1,-0.7,0.6,0.2,
0.1,-0.3,1.9,-1.5,0.2,1.0,-0.3,0.8),

CF02 = c(NA,NA,0.3,0.1,-0.9,-0.1,-0.2,-0.7,
-0.9,2.3,1.4,1.2,1.2,-0.7,-1.5),

CF01 = c(NA,NA,NA,-0.1,-0.2,-0.3,-0.2,-0.2,-0.2,
-0.1,0.1,-0.2,-0.2,-0.1,0.1),

IND = c(1,1,0,0,0,0,0,0,0,0,0,0,0,0,0))

-
What did you set the burn-in to? –  onestop Jul 9 '12 at 18:32
@ onestop, thanks for your help. I do not know how to set burn-in. In Sample Monitor Tool, I just use the default setting of beg of 1, and end of 1000000. Is that for burn-in setting? Thanks again –  Bo Yu Jul 9 '12 at 18:35
Sorry, ignore that, it's a while since I've used WinBUGS and i'd forgotten that you don't explicitly set the burn-in, you just run the sampler without monitoring anything. –  onestop Jul 9 '12 at 18:47

Let $N$ be the number of updates, $T$ be the 1 / the thin rate (e.g., 10 = return 1 out of every 10 samples), $B$ be the number of burnin samples, and $S$ be the number of returned samples.

The number of burnin samples defaults to $0.1N$. The total number of samples is the number of updates divided by the thin rate, $NT$. We then subtract off the burnin samples to get the number of (unthinned) samples $NT-B$, and multiply by the thin rate to get the number of samples actually returned.

Thus $B = 0.1N$ and $S = (NT-B)/T$.

-
@ jbowman, you answered my question very clearly. Yes, I checked the return samples based on your formula: For my cases, N = 5000, default burnin samples is 0.1*N = 500 (1) Case 1: the number of samples actually returned is 5000 - B/T = 5000-500/1 = 4500 (2) Case 2: the number of samples actually returned is 5000 - B/T = 5000-500/2 = 4750 (3) Case 3: the number of samples actually returned is 5000 - B/T = 5000-500/5 = 4900 (4) Case 4: the number of samples actually returned is 5000 - B/T = 5000-500/10 = 4950 Thank you very much! Best Regards, –  Bo Yu Jul 9 '12 at 19:05