[R] create matrices with constraint

John McKown john.archie.mckown at gmail.com
Fri Dec 12 20:45:37 CET 2014


On Fri, Dec 12, 2014 at 12:17 PM, peter dalgaard <pdalgd at gmail.com> wrote:

>
> > On 12 Dec 2014, at 18:00 , Kathryn Lord <kathryn.lord2000 at gmail.com>
> wrote:
> >
> > Dear all,
> >
> > Suppose that I have natural numbers 1 through 28.
> >
> > Based on these numbers, choose 4 numbers 7 times without replacement and
> > make a 4 by 7 matrix, for example,
> >
> >> a1
> >
> ​​
>    [,1] [,2] [,3] [,4] [,5] [,6] [,7]
> > [1,]    1    5    9   13   17   21   25
> > [2,]    2    6   10   14   18   22   26
> > [3,]    3    7   11   15   19   23   27
> > [4,]    4    8   12   16   20   24   28
> >
> > and again create another 4 * 7 matrix, say a2, in the same way; however,
> > every element of each column in a2 does not exist in any column of a1
> like
> > this, e.g.
> >
> >> a2
> >     [,1] [,2] [,3] [,4] [,5] [,6] [,7]
> > [1,]    1    2    3    4    5    6    7
> > [2,]    8    9   10   11   12   13   14
> > [3,]   15   16   17   18   19   20   21
> > [4,]   22   23   24   25   26   27   28
> >>
> >
>
> No comprendo... In which sense does e.g. "1" in the first column of a2 not
> exist in any column of a1????
>

​I was confused about that too. Perhaps what she means is that each column
in the every "a" matrix has at least one value​

​which does not exist in any column of any other "a" matrix. So that the
set of values in a[,?] for a given version does not exist as a set of
values in any other column (ignoring order) of any other version of "a". So
a1[,1] is c(1,2,3,4) which means that no other a?[,?] contains _all_ of
those. It _may_ contain a proper subset, but at least one value in the set
must differ. But I'm not sure that I was any clearer.

Hum. Consider the set of all possible unique 4 value vectors in which the
values in the vectors are taken, without replacement, from the numbers 1
through 28. This is a mathematical concept called "combination". In this
case, there are 35 such: 7!/(4!*3!).
Combine those vectors in groups of 7
​, each group being a separate column,​
in such a way that each resulting matrix contains no duplicate numbers,
which also ensure
​s​
that each resulting matrix does contain all of the values 1 through 28.
Note that the vector c(1,2,3,4) and c(2,1,4,3) are considered identical
​ because, in a combination, order does not matter​
. So a matrix which has a column with c(1,2,3,4) stops any other matrix
from having a column with the values c(2,1,4,3).
​You can also note that two matrices would be consider "identical" if the
only difference is the arrangement of the column. For example:

​

​         ​
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
​   ​
 [1,]    1    5    9   13   17   21   25
​   ​
 [2,]    2    6   10   14   18   22   26
​   ​
 [3,]    3    7   11   15   19   23   27
​   ​
 [4,]    4    8   12   16   20   24   28

​
is really the same as (exchanging [,4] and [,1]):

​
​​
​​

​​

​     ​
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
​   ​
 [1,]
​13
    5    9
​ 1​
   17   21   25
​   ​
 [2,]
​14​
    6   10
​ 2​
   18   22   26
​   ​
 [3,]
​15​
    7   11
​ 3​
   19   23   27
​   ​
 [4,]
​16​
    8   12
​ 4​
   20   24   28


as is
​ (exchanging [3,7] and [4,7])​

​  ​​  ​     ​[,1] [,2] [,3] [,4] [,5] [,6] [,7]
​   ​ [1,]   ​13    5    9   ​ 1​   17   21   25
​   ​ [2,]   ​14​    6   10   ​ 2​   18   22   26
​   ​ [3,]   ​15​    7   11   ​ 3​   19   23   2
​8​
​   ​ [4,]   ​16​    8   12   ​ 4​   20   24   2
​7​



I think this is what the OP was getting at.

I can't think of a way, off hand, to generate all such "a" matrices. I
might be able to do the first part: creating all unique 4 value vectors.
But then combining the vectors together to make the matrices is not clear
to me.
​

>
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>


-- 
​
While a transcendent vocabulary is laudable, one must be eternally careful
so that the calculated objective of communication does not become ensconced
in obscurity.  In other words, eschew obfuscation.

Maranatha! <><
John McKown

	[[alternative HTML version deleted]]



More information about the R-help mailing list