mardi 27 octobre 2015

random number generation from a copula using set.seed

I'm running two sessions of RStudio on my laptop.

When I ran

set.seed(1)
runif(1)

twice in each session, four of them gave the same number 0.2655087.

But if I generate random numbers from a copula using rCopula function of copula package, it does not work. It produces the same numbers if I run it twice within the same session, but different numbers in a different session.

On session 1,

set.seed(5)  
dat = rCopula(50, gumbelCopula(2.07, dim = 2))
dat[1,]
# [1] 0.7058623 0.3512414
set.seed(5)  
dat = rCopula(50, gumbelCopula(2.07, dim = 2))
dat[1,]
# [1] 0.7058623 0.3512414

On session 2,

set.seed(5)
dat = rCopula(50, gumbelCopula(2.07, dim = 2))
dat[1,]
# [1] 0.2489993 0.6595176
set.seed(5)
dat = rCopula(50, gumbelCopula(2.07, dim = 2))
dat[1,]
# [1] 0.2489993 0.6595176

Why does it happen and how can I get the same numbers?




Aucun commentaire:

Enregistrer un commentaire