Next: pushmodel() Up: MacAnova Help File Previous: probit()   Contents

prod()

Usage:
prod(x [,squeeze:T] [,silent:T,undefval:U]), x REAL or LOGICAL or a
  structure with REAL or LOGICAL components, U a REAL scalar
prod(x, dimensions:J [,squeeze:T] [,silent:T,undefval:U]), vector of
  positive integers J
prod(x, margins:K [,squeeze:F] [,silent:T,undefval:U]), vector of
  positive integers K
prod(x1,x2,... [,silent:T,undefval:U]), x1, x2, ... REAL or LOGICAL
  vectors, all the same type.



Keywords: summary statistics
prod(x) computes the product of the elements of a REAL or LOGICAL vector
x.

If x is LOGICAL, True is interpreted as 1 and False as 0 and hence
prod(x) has value 1 if all elements of x are True and 0 if any is False.

If x is a m by n matrix, prod(x) computes a row vector (1 by n matrix)
consisting of the product of the elements in each column of x.

If x is an array with dimensions n1, n2, n3, ..., y <- prod(x) computes
an array with dimensions 1, n2, n3, ... such that y[1,j,k,...] =
prod(x[i,j,k,...], i=1,...,n1).  This is consistent with what happens
when x is a matrix.  Note: MacAnova3.35 and earlier produced a result
with dimensions n2, n3, ... .

prod(x, squeeze:T) does the same, except the first dimension of the
result (of length 1) is squeezed out unless the result is a scalar.  In
particular, if x is a matrix, prod(x,squeeze:T) will be identical to
vector(prod(x)), and if x is an array, prod(x,squeeze:T) will be
identical to array(prod(x),dim(x)[-1]).

prod(NULL) is NULL.

prod(a,b,c,...) is equivalent to prod(vector(a,b,c,...)) if a, b, c,
... are all vectors.  They must all have the same type, REAL or LOGICAL
or be NULL.  prod(NULL, NULL, ..., NULL) is NULL.

prod(x, silent:T) or prod(a,b,c,...,silent:T) does the same but
suppresses warning messages about MISSING values or overflows.

If all the elements of a vector x are MISSING, prod(x) is 1.0.

prod(x, undefval:U), where U is a REAL scalar does the same, except the
returned value is U when all the elements of x are MISSING.

If x is a structure, prod(x) computes a structure, each of whose
components is prod() applied to that component of x.

prod(x, dimensions:J [,squeeze:T] [,silent:T] [undefval:U]) computes
products over the dimensions in J = vector(j1,j2,...,jn) where j1, ...,
jn are distinct positive integers <= ndims(x).  Without 'squeeze:T', the
result has the same number of dimensions as x, with dimensions j1, j2,
..., jn of length 1.  With 'squeeze:T', these dimensions are removed
from the result.  The order of j1, j2, ... is ignored.

It is an error if max(J) > ndims(x) or if there are duplicate elements
in J.

For example, if x is a matrix, prod(x, dimensions:2) computes the row
products as a nrows(x) by 1 matrix and prod(x, dimensions:2,squeeze:T)
computes them as a one dimensional vector.

prod(x, margins:K [,squeeze:F] [,silent:T] [undefval:U]) computes
products over the dimensions not in K = vector(k1, k2, ..., km), where
k1, ..., km are distinct positive integers <= ndims(x).  This computes
marginal products for the margins specified in K.

Without 'squeeze:F', only the dimensions in K are retained in the
result.  Otherwise the other dimensions are retained but have length 1.
This is opposite from the default with 'dimensions:J'.

It is an error if max(K) > ndims(x) or if there are duplicate elements
in K.

Examples:
  Cmd> x # matrix with labels
              B1          B2
  A1          18          15
  A2          17          26
  A3          18          19

  Cmd> prod(x) # products down columns
               B1          B2
  (1)        5508        7410

  Cmd> prod(x)/x # elements in row are products of other rows of x
              B1          B2
  A1         306         494
  A2         324         285
  A3         306         390

  Cmd> prod(x,dimensions:2) # products accross rows
             (1)
  A1         270
  A2         442
  A3         342

  Cmd> prod(x,margins:1) # same as a vector
            A1          A2          A3
           270         442         342

See also topics sum(), 'NULL'.


Gary Oehlert 2003-01-15