Re: [R] same random numbers in different sessions

2010-10-10 Thread Liviu Andronic
Dear all
Thanks for all the pointers.

On Sat, Oct 9, 2010 at 11:39 PM, Daniel Nordlund
djnordl...@frontier.com wrote:
 Could you be reloading a workspace at start-up that is setting the seed?  
 What happens if you start R using the --vanilla option?

It seems that this is the culprit. For some reason, my $HOME session
already has
 ls(all=T)
[1] .Random.seed

If I open a session in /tmp, or using --vanilla then I get actual
pseudo-random numbers. It seems that require(IPSUR) is not at fault,
either.

Regards
Liviu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] same random numbers in different sessions

2010-10-10 Thread Liviu Andronic
Hello

On Sun, Oct 10, 2010 at 1:16 AM, jim holtman jholt...@gmail.com wrote:
 You need to set the set.seed yourself.  There are some simulation
 where I do want the same numbers generated and can use the set.seed to
 set it to a know value.  If you want something random each time, then
 use the time of day in the call to set.seed.

I try to do this, but I get funny results. I put
try(rm(.Random.seed))
set.seed(Sys.time())

in
/usr/lib/R/etc/Rprofile.site

but I get the following error
Error in rm(.Random.seed) : cannot remove variables from base namespace
[Previously saved workspace restored]

and it is as if the set.seed() call didn't work, since I get the same
random values.
 rnorm(1:10)
 [1] -1.3618103  0.4241701  1.0720076  0.2208145 -0.5375314 -0.4846588
 [7]  0.7576768  0.6527407 -0.6868786  0.8718527

If I do
 set.seed(Sys.time())
 rnorm(1:10)
 [1] -0.6165650  0.6305187 -0.9316815  0.6034638 -0.8593514 -1.0243644
 [7] -0.1050344  0.4408562 -0.3466161  0.4058430

manually, within the session, the seed seems to be changed as
requested. Am I doing something wrong?
Liviu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] same random numbers in different sessions

2010-10-10 Thread Duncan Murdoch

On 10/10/2010 4:30 AM, Liviu Andronic wrote:

Hello

On Sun, Oct 10, 2010 at 1:16 AM, jim holtman jholt...@gmail.com wrote:

You need to set the set.seed yourself.  There are some simulation
where I do want the same numbers generated and can use the set.seed to
set it to a know value.  If you want something random each time, then
use the time of day in the call to set.seed.


I try to do this, but I get funny results. I put
try(rm(.Random.seed))
set.seed(Sys.time())

in
/usr/lib/R/etc/Rprofile.site

but I get the following error
Error in rm(.Random.seed) : cannot remove variables from base namespace
[Previously saved workspace restored]

and it is as if the set.seed() call didn't work, since I get the same
random values.

rnorm(1:10)

 [1] -1.3618103  0.4241701  1.0720076  0.2208145 -0.5375314 -0.4846588
 [7]  0.7576768  0.6527407 -0.6868786  0.8718527

If I do

set.seed(Sys.time())
rnorm(1:10)

 [1] -0.6165650  0.6305187 -0.9316815  0.6034638 -0.8593514 -1.0243644
 [7] -0.1050344  0.4408562 -0.3466161  0.4058430

manually, within the session, the seed seems to be changed as
requested. Am I doing something wrong?


The Rprofile.site is being executed before the saved workspace is 
restored.  See ?Startup for the sequence of events on startup. You could 
put the rm() in .First() in the saved workspace and it would do what you 
want.


But more generally, I would say the thing you are doing wrong is saving 
.RData sometimes, but not consistently saving it.  In my opinion it's 
safest to never save it; then you won't recover unexpected things from 
your history.  But it's also safe to always save it.  Then you'll get a 
new copy of .Random.seed saved each time.


I think the q() function makes it a little too easy to do what you did: 
 if you intend to never save it, but answer Yes just once, you get 
into your situation.  I don't know what the alternative should be.


One possibility would be for R to record whether the workspace was 
restored at the start of the session, and use that to determine the 
default when ending it.  But that would mess up people who are trying to 
reproduce things from identical conditions, e.g. when tracking down a bug.


Duncan Murdoch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] same random numbers in different sessions

2010-10-09 Thread Liviu Andronic
Dear all
I'm using Xubuntu Lucid and I keep getting the same random numbers
whenever I start a new session of R. For example, I keep getting
 sample(1:1000, 1)
[1] 87

or
 rnorm(1:10)
 [1] -1.3618103  0.4241701  1.0720076  0.2208145 -0.5375314 -0.4846588
 [7]  0.7576768  0.6527407 -0.6868786  0.8718527

I expected that some set.seed() instruction woudl be present in a
config file in
/usr/lib/R/etc/

but after grepping the only reference came out in Rprofile.site and it
was commented out:
# set.seed(1234)

What else could be causing this? Regards
Liviu

 sessionInfo()
R version 2.11.1 (2010-05-31)
x86_64-pc-linux-gnu

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=C  LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

other attached packages:
[1] fortunes_1.4-0 sos_1.3-0  brew_1.0-3 IPSUR_1.1


-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] same random numbers in different sessions

2010-10-09 Thread Daniel Nordlund
 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of Liviu Andronic
 Sent: Saturday, October 09, 2010 2:15 PM
 To: r-help@r-project.org Help
 Subject: [R] same random numbers in different sessions
 
 Dear all
 I'm using Xubuntu Lucid and I keep getting the same random numbers
 whenever I start a new session of R. For example, I keep getting
  sample(1:1000, 1)
 [1] 87
 
 or
  rnorm(1:10)
  [1] -1.3618103  0.4241701  1.0720076  0.2208145 -0.5375314 -0.4846588
  [7]  0.7576768  0.6527407 -0.6868786  0.8718527
 
 I expected that some set.seed() instruction woudl be present in a
 config file in
 /usr/lib/R/etc/
 
 but after grepping the only reference came out in Rprofile.site and it
 was commented out:
 # set.seed(1234)
 
 What else could be causing this? Regards
 Liviu
 

Could you be reloading a workspace at start-up that is setting the seed?  What 
happens if you start R using the --vanilla option?

Dan

Daniel Nordlund
Bothell, WA USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] same random numbers in different sessions

2010-10-09 Thread G. Jay Kerns
Dear Liviu,

On Sat, Oct 9, 2010 at 5:14 PM, Liviu Andronic landronim...@gmail.com wrote:
 Dear all
 I'm using Xubuntu Lucid and I keep getting the same random numbers
 whenever I start a new session of R. For example, I keep getting
 sample(1:1000, 1)
 [1] 87

 or
 rnorm(1:10)
  [1] -1.3618103  0.4241701  1.0720076  0.2208145 -0.5375314 -0.4846588
  [7]  0.7576768  0.6527407 -0.6868786  0.8718527

 I expected that some set.seed() instruction woudl be present in a
 config file in
 /usr/lib/R/etc/

 but after grepping the only reference came out in Rprofile.site and it
 was commented out:
 # set.seed(1234)

 What else could be causing this? Regards
 Liviu

 sessionInfo()
 R version 2.11.1 (2010-05-31)
 x86_64-pc-linux-gnu

 locale:
  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
  [5] LC_MONETARY=C              LC_MESSAGES=en_US.UTF-8
  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
  [9] LC_ADDRESS=C               LC_TELEPHONE=C
 [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

 attached base packages:
 [1] stats     graphics  grDevices utils     datasets  methods   base

 other attached packages:
 [1] fortunes_1.4-0 sos_1.3-0      brew_1.0-3     IPSUR_1.1




I notice that you have the IPSUR package loaded;  you know, just a
shot in the dark here, but did you try not loading it?

I ask because the vignette is built by making a special choice for
set.seed, and the workspace that ships with the package might be
interacting in an unexpected way.

Please let me know if IPSUR is the culprit.

Regards,
Jay

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] same random numbers in different sessions

2010-10-09 Thread jim holtman
You need to set the set.seed yourself.  There are some simulation
where I do want the same numbers generated and can use the set.seed to
set it to a know value.  If you want something random each time, then
use the time of day in the call to set.seed.

On Sat, Oct 9, 2010 at 5:14 PM, Liviu Andronic landronim...@gmail.com wrote:
 Dear all
 I'm using Xubuntu Lucid and I keep getting the same random numbers
 whenever I start a new session of R. For example, I keep getting
 sample(1:1000, 1)
 [1] 87

 or
 rnorm(1:10)
  [1] -1.3618103  0.4241701  1.0720076  0.2208145 -0.5375314 -0.4846588
  [7]  0.7576768  0.6527407 -0.6868786  0.8718527

 I expected that some set.seed() instruction woudl be present in a
 config file in
 /usr/lib/R/etc/

 but after grepping the only reference came out in Rprofile.site and it
 was commented out:
 # set.seed(1234)

 What else could be causing this? Regards
 Liviu

 sessionInfo()
 R version 2.11.1 (2010-05-31)
 x86_64-pc-linux-gnu

 locale:
  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
  [5] LC_MONETARY=C              LC_MESSAGES=en_US.UTF-8
  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
  [9] LC_ADDRESS=C               LC_TELEPHONE=C
 [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

 attached base packages:
 [1] stats     graphics  grDevices utils     datasets  methods   base

 other attached packages:
 [1] fortunes_1.4-0 sos_1.3-0      brew_1.0-3     IPSUR_1.1


 --
 Do you know how to read?
 http://www.alienetworks.com/srtest.cfm
 http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
 Do you know how to write?
 http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.