[R] random number generation

2007-07-18 Thread Hadi Darzian Azizi
Hi there,
I am relatively new user of R. I need to generate random number following
Gamma distribution with mean 14 und st.dev 3. I read the help-text but I can
not understand it well.

Regards,
Azizi

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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] random number generation

2007-07-18 Thread Francisco J. Zagmutt
Hello Hadi,

See ?rgamma

The Gamma distribution usually takes two parameters, shape and scale, 
not the mean and st. deviation.  If you have data, you can estimate 
those parameters using MLE methods, which are nicely provided in MASS:

library(MASS)
fitdistr(yourdata,Gamma)

Once you have your parameters you can generate random values using 
rgamma i.e. rgamma(1000,10,1) will generate 1000 random samples from a 
Gamma distribution with shape = 10 and scale = 1.

If you only have the mean and standard deviation you can approximate the 
shape and scale parameters using:

scale=variance/mean
shape=mean^2/var

Remember the variance is equal to sd^2

I hope this helps,


Francisco J. Zagmutt

PS: Please read the posting guide (see the link at the bottom of this 
email). It really helps people trying to help you :-)



Hadi Darzian Azizi wrote:
 Hi there,
 I am relatively new user of R. I need to generate random number following
 Gamma distribution with mean 14 und st.dev 3. I read the help-text but I can
 not understand it well.
 
 Regards,
 Azizi
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch 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-help@stat.math.ethz.ch 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] random number generation from a-/symmetric distribution

2006-09-20 Thread Garbade, Sven
Hi list,

are there any functions or ideas to compute random numbers with a specific 
population mean and standard deviation from symmetric (but not normal) and 
asymmetric distributions? My first idea was to use e.g. rf() (and other 
R-functions for random number generation)  and then scale the random numbers 
(for example: mean 300 and standard deviation 40), but I don't know if I'm 
wrong...

Thanks, Sven

__
R-help@stat.math.ethz.ch 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] random number generation from a-/symmetric distribution

2006-09-20 Thread mel
Garbade, Sven a écrit :

 Hi list,
 are there any functions or ideas to compute random numbers with a specific 
 population mean and standard deviation from symmetric (but not normal) and 
 asymmetric distributions? My first idea was to use e.g. rf() (and other 
 R-functions for random number generation)  and then scale the random numbers 
 (for example: mean 300 and standard deviation 40), but I don't know if I'm 
 wrong...
 Thanks, Sven

http://cran.r-project.org/src/contrib/Descriptions/boot.html
and all methods/packages related to bootstraping.
hih

__
R-help@stat.math.ethz.ch 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] Random number generation

2006-06-01 Thread Carl
Hi All.
(This is probably an incredibly stupid question :))

I have just noticed that every time I start an R2.3 session and request 
a random number (say with rnorm) that I receive the same number. AFAIK I 
have not set a seed at any point. Returning to an older version of 
R(v1.8) I get the behaviour that I have come to expect, where a new seed 
is automatically generated for each new session (actually it was a 
student running bootstraps on multiple machines that has noticed this).

I am running R2.3 for windows on winXP pro, AMD Athlon 2400+.

Thanks in advance and be gentle.
C

...retreats and waits for imminent admonishment...

-- 
~
Dr. Carl Donovan
Research Fellow in Statistical Computing
Ph +44 1334 461802
The Observatory
Buchanan Gardens
University of St Andrews
St Andrews
Fife
KY16 9LZ
Scotland

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Random number generation

2006-06-01 Thread Duncan Murdoch
On 6/1/2006 3:13 PM, Carl wrote:
 Hi All.
 (This is probably an incredibly stupid question :))
 
 I have just noticed that every time I start an R2.3 session and request 
 a random number (say with rnorm) that I receive the same number. AFAIK I 
 have not set a seed at any point. Returning to an older version of 
 R(v1.8) I get the behaviour that I have come to expect, where a new seed 
 is automatically generated for each new session (actually it was a 
 student running bootstraps on multiple machines that has noticed this).
 
 I am running R2.3 for windows on winXP pro, AMD Athlon 2400+.

R saves the random seed in a variable called .Random.seed.  (Because of 
the initial dot, this is not normally shown by ls().  Use ls(all=T) to 
see it.

If you save this to an .RData file, it will be reloaded next time you 
run, and your RNG will continue on from before.

I'm guessing you saved a copy once, but are *not* saving your workspace 
each time you restart:  hence you get the same seed each time.

You can avoid this by deleting the saved workspace, or just deleting 
.Random.seed and saving it (but it will be resurrected next time you do 
a save), or by always saving your workspace (so you save a different 
seed every time).

My advice would be not to save the workspace; I save individual objects 
sometimes, but I like a nice clean workspace each time I start.

Duncan Murdoch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Random number generation

2006-06-01 Thread Dimitrios Rizopoulos
according to ?.Random.seed, `Note' section, different R sessions give 
differen simulation results; maybe each time you start R you load a 
previously saved workspace, with an existing .Random.seed, i.e., check 
if the .Random.seed value is the same each time you start R.

I hope it helps.

Best,
Dimitris

 
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting Carl [EMAIL PROTECTED]:

 Hi All.
 (This is probably an incredibly stupid question :))
 
 I have just noticed that every time I start an R2.3 session and
 request 
 a random number (say with rnorm) that I receive the same number.
 AFAIK I 
 have not set a seed at any point. Returning to an older version of 
 R(v1.8) I get the behaviour that I have come to expect, where a new
 seed 
 is automatically generated for each new session (actually it was a 
 student running bootstraps on multiple machines that has noticed
 this).
 
 I am running R2.3 for windows on winXP pro, AMD Athlon 2400+.
 
 Thanks in advance and be gentle.
 C
 
 ...retreats and waits for imminent admonishment...
 
 -- 
 ~
 Dr. Carl Donovan
 Research Fellow in Statistical Computing
 Ph +44 1334 461802
 The Observatory
 Buchanan Gardens
 University of St Andrews
 St Andrews
 Fife
 KY16 9LZ
 Scotland
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide!
 http://www.R-project.org/posting-guide.html
 
 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Random number generation

2006-06-01 Thread plummer
That certainly sounds like the behaviour you would get if you
had a .Random.seed in your work space.  If you do not save your
workspace at the end of the session then the random seed will
be in exactly the same state every time you start a new R session,
and you will get identical simulations from the same sequence
of function calls. So you either need to save your work space
or launch R from the command line with --no-restore or --vanilla
and get a fresh starting seed in each session based on the
time stamp.

Have you tried checking for the existence of .Random.seed before
you call any random number functions (e.g. with
objects(all.names=TRUE))?

I don't know why you would get different behaviour from R 1.8.0
since the RNG hasn't changed since 1.7.0.

Martyn

Quoting Carl [EMAIL PROTECTED]:
 Hi All.
 (This is probably an incredibly stupid question :))

 I have just noticed that every time I start an R2.3 session and request
 a random number (say with rnorm) that I receive the same number. AFAIK I
 have not set a seed at any point. Returning to an older version of
 R(v1.8) I get the behaviour that I have come to expect, where a new seed
 is automatically generated for each new session (actually it was a
 student running bootstraps on multiple machines that has noticed this).

 I am running R2.3 for windows on winXP pro, AMD Athlon 2400+.

 Thanks in advance and be gentle.
 C

 ...retreats and waits for imminent admonishment...

 --
 ~
 Dr. Carl Donovan
 Research Fellow in Statistical Computing
 Ph +44 1334 461802
 The Observatory
 Buchanan Gardens
 University of St Andrews
 St Andrews
 Fife
 KY16 9LZ
 Scotland

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html




---
This message and its attachments are strictly confidential. ...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] random number generation

2003-10-28 Thread nmi13
Hi every one,

I am trying to generate a normally distributed random variable with the 
following descriptive statistics,

min=1, max=99, variance=125, mean=38.32, 1st quartile=38, median=40, 3rd 
quartile=40, skewness=-0.274.

I know the rnorm will allow me to simulate random numbers with mean 38.32 
and Sd=11.18(sqrt(125)). But I need to have the above mentioned descriptive 
statistics for the data that I generate.

I would be thankful to anyone who can help me with this problem.

Regards
Murthy

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] random number generation

2003-10-28 Thread nmi13
Hi every one,

I am trying to generate a random variable with the following descriptive 
statistics,

min=1, max=99, variance=125, mean=38.32, 1st quartile=38, median=40, 3rd
quartile=40, skewness=-0.274.

I tried with rgamma and as I cannot use rnorm, can any one please suggest me 
what distribution would give me the negative skewness. I need to have the 
above mentioned descriptive statistics for the data generated.

I would be thankful to anyone who can help me with this problem.

Regards
Murthy

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] random number generation

2003-10-28 Thread Pascal A. Niklaus
You need to know the exact distribution of the random numbers you want 
to generate. For rnorm, in fact, you do not just specify the mean and 
the variance, but implicitely also that the data is normally 
distributed. Likewise, it is not sufficient to give min, max, skewness 
etc, you also need to know the distribution and then maybe you can use 
runif() as base for your code.

Pascal

nmi13 wrote:

Hi every one,

I am trying to generate a normally distributed random variable with the 
following descriptive statistics,

min=1, max=99, variance=125, mean=38.32, 1st quartile=38, median=40, 3rd 
quartile=40, skewness=-0.274.

I know the rnorm will allow me to simulate random numbers with mean 38.32 
and Sd=11.18(sqrt(125)). But I need to have the above mentioned descriptive 
statistics for the data that I generate.

I would be thankful to anyone who can help me with this problem.

Regards
Murthy
 

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] random number generation

2003-10-28 Thread Prof Brian Ripley
Is this a student exercise?  If not, please enlighten us as to the
real-world problem from which this is extracted.

Given that 50% of the probability mass lies between 38 and 40, and the 
median and 3rd quartile are both 40, this cannot be a continuous
distribution.  I would design a discrete distribution on the integers 
1, ..., 99 to meet your requirements: that is `just' a constrained 
non-linear optimization problem.

BTW, a random variable cannot have those characteristics: its distribution 
could, or a sample could and it is unclear which you mean.  The first is 
easier and so that's what I have assumed.

On Wed, 29 Oct 2003, nmi13 wrote:

 I am trying to generate a random variable with the following descriptive 
 statistics,
 
 min=1, max=99, variance=125, mean=38.32, 1st quartile=38, median=40, 3rd
 quartile=40, skewness=-0.274.
 
 I tried with rgamma and as I cannot use rnorm, can any one please suggest me 
 what distribution would give me the negative skewness. I need to have the 
 above mentioned descriptive statistics for the data generated.
 
 I would be thankful to anyone who can help me with this problem.

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] random number generation

2003-10-28 Thread Peter Flom
These conditions are mutually exclusive for a lot of reasons, therefore,
there's no way to generate such data.  Briefly, the normal distribution
is fully specified by the mean and variance, the other conditions are
superfluous, and, in some cases, impossible

Please tell us what you are actually trying to do and why you need to
do it, and perhaps we can help.   

Peter

Peter L. Flom, PhD
Assistant Director, Statistics and Data Analysis Core
Center for Drug Use and HIV Research
National Development and Research Institutes
71 W. 23rd St
www.peterflom.com
New York, NY 10010
(212) 845-4485 (voice)
(917) 438-0894 (fax)



 nmi13 [EMAIL PROTECTED] 10/28/2003 3:38:22 AM 
Hi every one,

I am trying to generate a normally distributed random variable with the

following descriptive statistics,

min=1, max=99, variance=125, mean=38.32, 1st quartile=38, median=40,
3rd 
quartile=40, skewness=-0.274.

I know the rnorm will allow me to simulate random numbers with mean
38.32 
and Sd=11.18(sqrt(125)). But I need to have the above mentioned
descriptive 
statistics for the data that I generate.

I would be thankful to anyone who can help me with this problem.

Regards
Murthy

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help