Simulation from discrete uniform

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Simulation from discrete uniform

cassie jones
Dear all,

I am trying to simulate from discrete uniform distribution. But I could not
find any in-built code in R. Could anyone help me please?


Thanks in advance for the time and help.




Cassie

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Simulation from discrete uniform

djmuseR
Hi:

Suppose X has a discrete uniform distribution on the sample space S = {0, 1,
2, ..., 9}. Then a random sample of size 100 from this distribution, for
example, would be

dus <- sample(0:9, 100, replace = TRUE)
# Checks:
table(dus)
lattice::barchart( ~ table(dus), xlim = c(0, 20))

The sample space comprises the first argument of sample(), the sample size
is the second argument, and the replace = TRUE argument allows an element of
the sample space to be selected more than once.

HTH,
Dennis

On Thu, Apr 7, 2011 at 6:15 PM, cassie jones <[hidden email]>wrote:

> Dear all,
>
> I am trying to simulate from discrete uniform distribution. But I could not
> find any in-built code in R. Could anyone help me please?
>
>
> Thanks in advance for the time and help.
>
>
>
>
> Cassie
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Simulation from discrete uniform

Søren Højsgaard
In reply to this post by cassie jones
?sample
-----Oprindelig meddelelse-----
Fra: [hidden email] [mailto:[hidden email]] På vegne af cassie jones
Sendt: 8. april 2011 03:16
Til: [hidden email]
Emne: [R] Simulation from discrete uniform

Dear all,

I am trying to simulate from discrete uniform distribution. But I could not
find any in-built code in R. Could anyone help me please?


Thanks in advance for the time and help.




Cassie

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Simulation from discrete uniform

BSanders
In reply to this post by cassie jones
If you wanted a discrete uniform from 1-10 use: ceiling(10*runif(1))
if you wanted from 0-12, use: ceiling(13*runif(1))-1
Reply | Threaded
Open this post in threaded view
|

Re: Simulation from discrete uniform

Mehmet Suzen
Why don't you use sample;
> sample(1:10,10,replace=TRUE)


-----Original Message-----
From: [hidden email] [mailto:[hidden email]]
On Behalf Of BSanders
Sent: 26 October 2011 08:49
To: [hidden email]
Subject: Re: [R] Simulation from discrete uniform

If you wanted a discrete uniform from 1-10 use: ceiling(10*runif(1))
if you wanted from 0-12, use: ceiling(13*runif(1))-1

--
View this message in context:
http://r.789695.n4.nabble.com/Simulation-from-discrete-uniform-tp3434980
p3939694.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
[hidden email] 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.
LEGAL NOTICE
This message is intended for the use o...{{dropped:10}}

______________________________________________
[hidden email] 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.