Skip to content

What is the equivalent of column.prods() from S in R?

7 messages · Peng Yu, David Winsemius, William Dunlap

#
Chambers' book Statistical Models in S mentioned 'column.prods()'. But
I don't find it in R. I'm wondering if there is an equivalent in R?
#
On Nov 9, 2009, at 8:43 PM, Peng Yu wrote:

            
??rowProds
??colProds

(They are in both fUtilities and timeSeries.)


--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT
19 days later
#
On Mon, Nov 9, 2009 at 8:35 PM, David Winsemius <dwinsemius at comcast.net> wrote:
Are you sure that colProds() is equivalent to column.prods()? It seems
that column.prods() should be a very basic function in S, but I have
to load a package in order to call colProds().

I don't see how to construct a matrix give terms as mentioned in the
book. Would you please give me some examples?
#
On Nov 28, 2009, at 11:28 PM, Peng Yu wrote:

            
Page numbers? Specifics? ....something to go on?
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
#
On Sat, Nov 28, 2009 at 11:00 PM, David Winsemius
<dwinsemius at comcast.net> wrote:
As is mentioned in the appendix of the book, it is on page 38.
#
S's and S+'s column.prods(x1,x2), where nrow(x1)==nrow(x2),
returns the nrow(x1) row by ncol(x1)*ncol(x2) column matrix
containing the products of all pairs of columns
from x1 and x2, respectively.  The column names are set to
reflect which columns in x1 and x2 the products come from.
E.g., one can use it to compute the interaction colunns
in a model matrix:
  > x1<-cbind(one=c(1,0,0),two=c(0,1,0))
  > x2<-cbind(A=c(11,12,13), B=c(101,105,111))
  > column.prods(x1,x2)
       oneA twoA oneB twoB
  [1,]   11    0  101    0
  [2,]    0   12    0  105
  [3,]    0    0    0    0

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
#
On Nov 29, 2009, at 12:20 AM, Peng Yu wrote:

            
It's a chapter on the internal representation of models. So, no, I  
agree, the colProds function does not do what column.prods did in S  
which was to represent interaction terms.  The terms.object help page  
says these are different than in S. I suspect that the function you  
want is model.matrix. An example with from its help page:

dd <- data.frame(a = gl(3,4), b = gl(4,1,12))# balanced 2-way
options("contrasts")
model.matrix( ~ a + b, dd)
# and then the "product" design matrix
model.matrix( ~ a * b, dd)