Sampling with replacement

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

Sampling with replacement

Somnath Somnath
Dear all, good morning,

I have a population, let say members are tagged with some simple number like
1,2,3,...20. I want to draw a sample with replacement of size 4 (say, can be
more than 20 also). Is there any R function which will show me all such
possible samples?

Thanks

        [[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: Sampling with replacement

Jun Shen-3
sample(1:20,4,replace=TRUE) should do it.

Jun

On Wed, Jun 16, 2010 at 9:20 AM, Somnath Somnath <[hidden email]>wrote:

> Dear all, good morning,
>
> I have a population, let say members are tagged with some simple number
> like
> 1,2,3,...20. I want to draw a sample with replacement of size 4 (say, can
> be
> more than 20 also). Is there any R function which will show me all such
> possible samples?
>
> Thanks
>
>        [[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: Sampling with replacement

Jorge I Velez
In reply to this post by Somnath Somnath
Try

sample(20, 4, replace = TRUE)

HTH,
Jorge


On Wed, Jun 16, 2010 at 10:20 AM, Somnath Somnath <> wrote:

> Dear all, good morning,
>
> I have a population, let say members are tagged with some simple number
> like
> 1,2,3,...20. I want to draw a sample with replacement of size 4 (say, can
> be
> more than 20 also). Is there any R function which will show me all such
> possible samples?
>
> Thanks
>
>        [[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: Sampling with replacement

Rafael Björk
If you for some reason want to be shown all the possible combinations, try
expand.grid(1:20,1:20,1:20,1:20) (ugly code). Don't use this for sampling.

hth Rafael

2010/6/16 Jorge Ivan Velez <[hidden email]>

> Try
>
> sample(20, 4, replace = TRUE)
>
> HTH,
> Jorge
>
>
> On Wed, Jun 16, 2010 at 10:20 AM, Somnath Somnath <> wrote:
>
> > Dear all, good morning,
> >
> > I have a population, let say members are tagged with some simple number
> > like
> > 1,2,3,...20. I want to draw a sample with replacement of size 4 (say, can
> > be
> > more than 20 also). Is there any R function which will show me all such
> > possible samples?
> >
> > Thanks
> >
> >        [[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.
>

        [[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: Sampling with replacement

David Winsemius
In reply to this post by Somnath Somnath

On Jun 16, 2010, at 10:20 AM, Somnath Somnath wrote:

> Dear all, good morning,
>
> I have a population, let say members are tagged with some simple  
> number like
> 1,2,3,...20. I want to draw a sample with replacement of size 4  
> (say, can be
> more than 20 also).

Already answered on the list.

> Is there any R function which will show me all such
> possible samples?

?expand.grid

 > nrow(expand.grid(1:20, 1:20, 1:20, 1:20))
[1] 160000

--
David Winsemius, MD
West Hartford, CT

______________________________________________
[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: Sampling with replacement

Jorge I Velez
In reply to this post by Rafael Björk
Hi Rafael,

You might try:

> r <- expand.grid(rep(list(1:20), 4))
> dim(r)
[1] 160000      4

HTH,
Jorge


2010/6/16 Rafael Björk <>

> If you for some reason want to be shown all the possible combinations, try
> expand.grid(1:20,1:20,1:20,1:20) (ugly code). Don't use this for sampling.
>
> hth Rafael
>
> 2010/6/16 Jorge Ivan Velez <>
>
> Try
>>
>> sample(20, 4, replace = TRUE)
>>
>> HTH,
>> Jorge
>>
>>
>> On Wed, Jun 16, 2010 at 10:20 AM, Somnath Somnath <> wrote:
>>
>> > Dear all, good morning,
>> >
>> > I have a population, let say members are tagged with some simple number
>> > like
>> > 1,2,3,...20. I want to draw a sample with replacement of size 4 (say,
>> can
>> > be
>> > more than 20 also). Is there any R function which will show me all such
>> > possible samples?
>> >
>> > Thanks
>> >
>> >        [[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.
>>
>
>
        [[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: Sampling with replacement

Tom La Bone
In reply to this post by Somnath Somnath
How about


library(TeachingSampling)
SupportWR(20,4)


Tom
Reply | Threaded
Open this post in threaded view
|

Re: Sampling with replacement

Somnath Somnath
In reply to this post by Jorge I Velez
Thanks for all those reply. Is there any general rule to determine how many
samples I would get from a population of size "n", I draw a sample of size
"m" ("m" may be greater than "n") if sample is drawn with replacement?

Thanks,

2010/6/16 Jorge Ivan Velez <[hidden email]>

> Hi Rafael,
>
> You might try:
>
> > r <- expand.grid(rep(list(1:20), 4))
> > dim(r)
> [1] 160000      4
>
> HTH,
> Jorge
>
>
> 2010/6/16 Rafael Björk <>
>
>> If you for some reason want to be shown all the possible combinations, try
>> expand.grid(1:20,1:20,1:20,1:20) (ugly code). Don't use this for sampling.
>>
>> hth Rafael
>>
>> 2010/6/16 Jorge Ivan Velez <>
>>
>> Try
>>>
>>> sample(20, 4, replace = TRUE)
>>>
>>> HTH,
>>> Jorge
>>>
>>>
>>> On Wed, Jun 16, 2010 at 10:20 AM, Somnath Somnath <> wrote:
>>>
>>> > Dear all, good morning,
>>> >
>>> > I have a population, let say members are tagged with some simple number
>>> > like
>>> > 1,2,3,...20. I want to draw a sample with replacement of size 4 (say,
>>> can
>>> > be
>>> > more than 20 also). Is there any R function which will show me all such
>>> > possible samples?
>>> >
>>> > Thanks
>>> >
>>> >        [[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.
>>>
>>
>>
>
        [[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: Sampling with replacement

William Dunlap
> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Somnath Somnath
> Sent: Wednesday, June 16, 2010 10:28 AM
> To: [hidden email]
> Subject: Re: [R] Sampling with replacement
>
> Thanks for all those reply. Is there any general rule to
> determine how many
> samples I would get from a population of size "n", I draw a
> sample of size
> "m" ("m" may be greater than "n") if sample is drawn with replacement?

If you consider two samples equivalent if they
differ only in their ordering (e.g., c(1,2,2)
is equivalent to c(2,1,2) and c(2,2,1)) then
the answer is
    choose(n+m-1, m)
If order matters then it is
    n^m

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com

> Thanks,
>
> 2010/6/16 Jorge Ivan Velez <[hidden email]>
>
> > Hi Rafael,
> >
> > You might try:
> >
> > > r <- expand.grid(rep(list(1:20), 4))
> > > dim(r)
> > [1] 160000      4
> >
> > HTH,
> > Jorge
> >
> >
> > 2010/6/16 Rafael Björk <>
> >
> >> If you for some reason want to be shown all the possible
> combinations, try
> >> expand.grid(1:20,1:20,1:20,1:20) (ugly code). Don't use
> this for sampling.
> >>
> >> hth Rafael
> >>
> >> 2010/6/16 Jorge Ivan Velez <>
> >>
> >> Try
> >>>
> >>> sample(20, 4, replace = TRUE)
> >>>
> >>> HTH,
> >>> Jorge
> >>>
> >>>
> >>> On Wed, Jun 16, 2010 at 10:20 AM, Somnath Somnath <> wrote:
> >>>
> >>> > Dear all, good morning,
> >>> >
> >>> > I have a population, let say members are tagged with
> some simple number
> >>> > like
> >>> > 1,2,3,...20. I want to draw a sample with replacement
> of size 4 (say,
> >>> can
> >>> > be
> >>> > more than 20 also). Is there any R function which will
> show me all such
> >>> > possible samples?
> >>> >
> >>> > Thanks
> >>> >
> >>> >        [[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.
> >>>
> >>
> >>
> >
>
> [[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: Sampling with replacement

Johannes Huesing
In reply to this post by Somnath Somnath
Somnath Somnath <[hidden email]> [Wed, Jun 16, 2010 at 07:27:32PM CEST]:
> Thanks for all those reply. Is there any general rule to determine how many
> samples I would get from a population of size "n", I draw a sample of size
> "m" ("m" may be greater than "n") if sample is drawn with replacement?

m^n

--
Johannes Hüsing               There is something fascinating about science.
                              One gets such wholesale returns of conjecture
mailto:[hidden email]  from such a trifling investment of fact.                
http://derwisch.wikidot.com         (Mark Twain, "Life on the Mississippi")

______________________________________________
[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: Sampling with replacement

Jim Lemon
In reply to this post by Somnath Somnath
On 06/17/2010 03:27 AM, Somnath Somnath wrote:
> Thanks for all those reply. Is there any general rule to determine how many
> samples I would get from a population of size "n", I draw a sample of size
> "m" ("m" may be greater than "n") if sample is drawn with replacement?
>
Hi Somnath,
If you mean "how many unique values", I think this is the "occupancy"
problem that is discussed in:

Feller, W. (1950) An introduction to probability theory and its
applications (Vol 1). New York: Wiley.

and probably other places. You can calculate the probability of
obtaining each possible number of outcomes using the Maxwell-Botlzmann
distribution.

Jim

______________________________________________
[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.