Hi, in the code below, I am drawing 1000 samples from two beta
distributions, each time using the same random number seed.

Using set.seed(80) produces results I expect, in that the differences
between the distributions are very small.

Using set.seed(20) produces results I can't make sense of. Around half of
the time, it behaves as with set.seed(80), but around half of the time, it
behaves very differently, with a much wider distribution of differences
between the two distributions.


# Beta parameters

#distribution 1
u1.a <- 285.14
u1.b <- 190.09

# distribution 2
u2.a <- 223.79
u2.b <- 189.11

#Good example: output is as expected

set.seed(80); u1.good <- rbeta(1000, u1.a, u1.b)
set.seed(80); u2.good <- rbeta(1000, u2.a, u2.b)


#Bad example: output is different to expected
set.seed(20); u1.bad <- rbeta(1000, u1.a, u1.b)
set.seed(20); u2.bad <- rbeta(1000, u2.a, u2.b)


# plot of distributions using set.seed(80), which behaves as expected
plot(u2.good ~ u1.good, ylim=c(0.45, 0.70), xlim=c(0.45, 0.70))
abline(0,1)

# plot of distributions using set.seed(20), which is different to expected
plot(u2.bad ~ u1.bad, ylim=c(0.45, 0.70), xlim=c(0.45, 0.70))
abline(0,1)

# plot of differences when using set.seed(80)
plot(u1.good - u2.good, ylim=c(-0.2, 0.2))
abline(h=0)

# plot of differences when using set.seed(20)
plot(u1.bad - u2.bad, ylim=c(-0.2, 0.2))
abline(h=0)


Could you explain why using set.seed(20) produces this chaotic pattern of
behaviour?


Many thanks,
Jon

-- 
Dr Jon Minton
Research Associate
Health Economics & Decision Science
School of Health and Related Research
University of Sheffield
Times Higher Education University of the Year
Tel: +44(0)114 222 0836
email: j.minton@sheffield.ac.uk

http://www.shef.ac.uk/scharr/sections/heds
http://scharrheds.blogspot.co.uk/

	[[alternative HTML version deleted]]

