[R] lda in R vs S

Prof Brian D Ripley ripley at stats.ox.ac.uk
Thu May 6 22:24:07 CEST 1999

On Thu, 6 May 1999, Marc R. Feldesman wrote:

> I'm running a discriminant analysis in R (0.64.1) to compare it with SPlus

That's not released until tomorrow!  I guess you have the pre-release,
prerw0641, which is actually of 0.64.0.

> 4.5R2.  The following command line works fine in SPlus but gives an error
> in R.  I've only used R for a little while so I'm not certain here what R
> (or lda) is complaining about.  The dependent variable (sarich.na[,3]) is
> an alpha categorical variable, if that makes a difference.  I'm using

What's that? The response ought to be a factor, according to the docs:

 formula: A formula of the form `groups ~ x1 + x2 + ...{}'
          That is, the response is the grouping factor and
          the right hand side specifies the (non-factor)

> version VR5.3 (file name VR5.3pl037.zip).
> lda.out<-lda(sarich.na[,3]~., data=sarich.na[,4:32])
> Error in model.frame(formula, rownames, variables, varnames, extras,
> extranames,  : invalid variable type
> Is this an lda issue or an R issue?

It is an R issue. Only logical, integer and real variables are allowed
in R model frames, for as the code says

    /* Sanity checks to ensure that the the answer can become */
    /* a data frame.  Be deeply suspicious here! */

But that is not the `right' way to do this in either. Use either

lda.out<-lda(sarich.na[,4:32], sarich.na[,3])


lda.out<-lda(somename ~ ., data=sarich.na[,3:32])

where somename is the name of column 3, and that had better be a factor.

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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list