[R] Shafer's MIX: Query on code
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Apr 29 16:40:43 CEST 2003
On Tue, 29 Apr 2003 Ted.Harding at nessie.mcc.ac.uk wrote:
> Thanks to Fernando Tusell and especially to Brian Ripley for
> their work on 'mix', leading to an apparently good package
> mow available on CRAN.
> Going through the R code for the function prelim.mix, I am
> wondering why the following method of calculation is used
> at one point:
> umd <- as.integer(round(exp(cumsum(log(d)))))
> (d is a vector containing, in effect, the numbers of levels of
> the factors in col1, col2, ... of the categorical variables.
> Therefore umd is a vector containing the numbers of possible
> combinations of factor levels in col1, col1&col2, ... )
> But why not do it as
> umd <- as.integer(cumprod(d))
> ?? [It can't be that this number could go out or range, since
> that would be equally true of exp(cumsum(log(d)))) ]
I expect the author didn't know about cumprod. It isn't in the Blue Book,
which even does a similar calculation this way (on page 361).
There's a lot of other code that is not idiomatic S in mix.
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help