

Dear All,
I cannot unfortunately provide any R code, otherwise I would not need to post this in the first place.
I need to generate a sample of N positive nonzero integers such that their mean is *exactly* 2(N1)/N, i.e. the mean depends on the length of the sample.
For a start, we can assume that every integer in my sample can assume only the values 1, 2 and 3.
Any suggestion is appreciated.
Cheers
Lorenzo
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


n_1 + ... + n_N = 2(N1) is requested for integers n_i >= 1.
What about c(rep(2, N2), 1, 1))?
but I'm afraid that this was not what you really wanted. ;)
However, you didn't say if your sample should be random. :)
Best regards  Gerrit

Dr. Gerrit Eichner Mathematical Institute, Room 212
[hidden email] JustusLiebigUniversity Giessen
Tel: +49(0)6419932104 Arndtstr. 2, 35392 Giessen, Germany
http://www.unigiessen.de/eichner
Am 01.08.2019 um 12:27 schrieb Lorenzo Isella:
> Dear All,
> I cannot unfortunately provide any R code, otherwise I would not need to
> post this in the first place.
> I need to generate a sample of N positive nonzero integers such that
> their mean is *exactly* 2(N1)/N, i.e. the mean depends on the length of
> the sample.
> For a start, we can assume that every integer in my sample can assume
> only the values 1, 2 and 3.
> Any suggestion is appreciated.
> Cheers
>
> Lorenzo
>
> ______________________________________________
> [hidden email] mailing list  To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide
> http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Yes, you are right (and yours is one of the possible cases).
I think this works (I resorted to pen and paper for once)
generate_k < function(N, n3){
n1 < 2+n3
n2 < Nn1n3
out < c(rep(1, n1), rep(2, n2), rep(3, n3))
return(out)
}
where N is the length of the sample, n3 is the number of times I have the number 3 in the sample (n1 and n2 are the same for 1 and 2, respectively).
So far it holds!
L.
On Thu, Aug 01, 2019 at 12:37:47PM +0200, Gerrit Eichner wrote:
>n_1 + ... + n_N = 2(N1) is requested for integers n_i >= 1.
>
>What about c(rep(2, N2), 1, 1))?
>
>but I'm afraid that this was not what you really wanted. ;)
>However, you didn't say if your sample should be random. :)
>
> Best regards  Gerrit
>
>
>Dr. Gerrit Eichner Mathematical Institute, Room 212
> [hidden email] JustusLiebigUniversity Giessen
>Tel: +49(0)6419932104 Arndtstr. 2, 35392 Giessen, Germany
> http://www.unigiessen.de/eichner>
>
>Am 01.08.2019 um 12:27 schrieb Lorenzo Isella:
>>Dear All,
>>I cannot unfortunately provide any R code, otherwise I
>>would not need to post this in the first place.
>>I need to generate a sample of N positive nonzero
>>integers such that their mean is *exactly* 2(N1)/N,
>>i.e. the mean depends on the length of the sample.
>>For a start, we can assume that every integer in my
>>sample can assume only the values 1, 2 and 3.
>>Any suggestion is appreciated.
>>Cheers
>>
>>Lorenzo
>>
>>______________________________________________
>> [hidden email] mailing list  To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/rhelp>>PLEASE do read the posting guide
>> http://www.Rproject.org/postingguide.html>>and provide commented, minimal, selfcontained, reproducible code.
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


2(N1)/N = 2  2/N.
So one way to get exactly that mean is to make all the numbers
2 except for two of them which are 1.
N < 2 : can't be done.
N = 2 : only [1,1] does the job.
N = 3 : the sum of the three numbers must be 4, so none of them
can be 3, so [1,1,2] [1,2,1] [2,1,1] are the only
possibilities.
N = 4 : [1,1,1,3] [1,1,2,2] [1,1,3,1] [1,2,1,2] [1,2,2,1] [1,3,1,1]
[2,1,1,2] [2,1,2,1] [2,2,1,1] [3,1,1,1]
Is there a pattern here?
Yes. There must be an integer k such that 0 <= 2k <= N2
and then you have a rearrangement of (k+2) 1s, (N22k) 2s, and k 3s.
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


I don't know why I thought you wanted a *random* sequence..
The 'rep' function can do more than you realise.
generate_k < function (N, n3) rep(1:3, c(n3+2, N2n3*2, n3))
On Thu, 1 Aug 2019 at 22:48, Lorenzo Isella < [hidden email]>
wrote:
> Yes, you are right (and yours is one of the possible cases).
> I think this works (I resorted to pen and paper for once)
>
>
>
> generate_k < function(N, n3){
>
> n1 < 2+n3
> n2 < Nn1n3
>
>
> out < c(rep(1, n1), rep(2, n2), rep(3, n3))
>
> return(out)
> }
>
> where N is the length of the sample, n3 is the number of times I have the
> number 3 in the sample (n1 and n2 are the same for 1 and 2, respectively).
> So far it holds!
>
> L.
>
> On Thu, Aug 01, 2019 at 12:37:47PM +0200, Gerrit Eichner wrote:
> >n_1 + ... + n_N = 2(N1) is requested for integers n_i >= 1.
> >
> >What about c(rep(2, N2), 1, 1))?
> >
> >but I'm afraid that this was not what you really wanted. ;)
> >However, you didn't say if your sample should be random. :)
> >
> > Best regards  Gerrit
> >
> >
> >Dr. Gerrit Eichner Mathematical Institute, Room 212
> > [hidden email] JustusLiebigUniversity Giessen
> >Tel: +49(0)6419932104 Arndtstr. 2, 35392 Giessen, Germany
> > http://www.unigiessen.de/eichner> >
> >
> >Am 01.08.2019 um 12:27 schrieb Lorenzo Isella:
> >>Dear All,
> >>I cannot unfortunately provide any R code, otherwise I
> >>would not need to post this in the first place.
> >>I need to generate a sample of N positive nonzero
> >>integers such that their mean is *exactly* 2(N1)/N,
> >>i.e. the mean depends on the length of the sample.
> >>For a start, we can assume that every integer in my
> >>sample can assume only the values 1, 2 and 3.
> >>Any suggestion is appreciated.
> >>Cheers
> >>
> >>Lorenzo
> >>
> >>______________________________________________
> >> [hidden email] mailing list  To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/rhelp> >>PLEASE do read the posting guide
> >> http://www.Rproject.org/postingguide.html> >>and provide commented, minimal, selfcontained, reproducible code.
>
> ______________________________________________
> [hidden email] mailing list  To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide
> http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
>
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Hello,
On Thu, Aug 01, 2019 at 11:17:30PM +1200, Richard O'Keefe wrote:
>2(N1)/N = 2  2/N.
>So one way to get exactly that mean is to make all the numbers
>2 except for two of them which are 1.
>
>N < 2 : can't be done.
>N = 2 : only [1,1] does the job.
>N = 3 : the sum of the three numbers must be 4, so none of them
> can be 3, so [1,1,2] [1,2,1] [2,1,1] are the only
> possibilities.
>N = 4 : [1,1,1,3] [1,1,2,2] [1,1,3,1] [1,2,1,2] [1,2,2,1] [1,3,1,1]
>[2,1,1,2] [2,1,2,1] [2,2,1,1] [3,1,1,1]
>
>Is there a pattern here?
>Yes. There must be an integer k such that 0 <= 2k <= N2
>and then you have a rearrangement of (k+2) 1s, (N22k) 2s, and k 3s.
This is what I did by solving a set of equations
n1+n2+n3=N (i.e. the number of 1, 2 and 3 equals N, the length of my sample) and
n2+2*n2+3*n3=2*(N1)
without delving into the details, you are composing (fractal) structures of N spheres in 3D, with an algorithm which establishes that every sphere has on average (2*N1)/N neighbours. One solution is a simple chain, without bifurcations, where every sphere has two neighbours apart from the two terminal spheres, each of which has just one neighbour. Whenever a bifurcation arises, one sphere will have three neighbors.
L.
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.

