R-beta: Various R Questions and Comments

Doug Morse (morse@pobox.com)
Mon, 16 Feb 1998 10:30:51 -0600 (CST)

Message-Id: <199802161630.KAA22951@playground.ltc.vanderbilt.edu>
Subject: R-beta: Various R Questions and Comments
To: r-help@stat.math.ethz.ch
Date: Mon, 16 Feb 1998 10:30:51 -0600 (CST)
From: morse@pobox.com (Doug Morse)


I've been using R for about nine months now -- it's great.  Nicely done!

Here are some questions / comments I have.  Some are trivialities, but I
thought I'd mention them anyway.  Others are a bit more involved.  BTW,
I run R (Version 0.61.1 Alpha) on RedHat Linux 4.1

1.  Interrupt Key

    How is one supposed to interrupt a command?  In S-Plus, one uses
    the 'Escape' key.  In R, I can press my terminal's Interrupt
    key (Ctrl-C), but this only works *once*.  After that, the event
    seems to get ignored.  This is a nuicance for two reasons:  (a) I
    can't interrupt a command but once in a session, and (b) at the
    "> " prompt, I can't press Ctrl-C to abort my many typing errors
    but once a session as well.

2.  Sourcing MS-DOS Files

    I also use R on my laptop (Win95) and often transfer files
    back and forth between it and my linux host.  R doesn't
    seem to like this much -- I always have to convert [newlines]
    to [newlines-carriage returns] and back.  Not a big deal, but
    a bit annoying.  Could 'source' not be modified to auto-detect
    end-of-line method?

3.  Coercing Types within a DataFrame

    This is a more serious problem.  In S-Plus, I can run:
        myframe <- read.table('mydata.dat', T);
        myframe[, 'Steps'] <- as.factor(myframe[, 'Steps']);

    but in R this generates:
        Error: incompatible types in subset assignment

    The 'Steps' column in my data file is all numerics, but it is
    actually a factor (at levels 10, 13, and 16).  R's read.table()
    is converting this column to a numeric type, as it should.
    I'm trying to then tell R to convert this particular column
    to a factor, but I can't.  Big problem for my analysis. ;-)
    The only way around I can figure to do at present is to use
    the 'data.frame' method and then manually fix the column names:
        myframe <- read.table('mydata.dat', T);
        myframe[, 'Steps'] <- as.factor(myframe[, 'Steps']);
        myframe <- data.frame(myframe[,1:5], as.factor(myframe[,'Steps']), \
        names(myframe)[6] <- 'Steps';

    This is not only a lot more to code, it seems like it's inefficient,
    too.  Moreover, it breaks if I change the column ordering in my data set
    (I like to always reference columns symbolically, never by position).

4.  Anovalist.lm

    Whenever the dependent variables in a formula don't match exactly,
    'anovalist.lm' issues a warning and then removes the offending formula
    from the list of formulas.  In most cases I can see why this behavior is
    desirable.  However, in some cases, formulas are comparable even when
    the DVs aren't exactly the same.
    For example, the following should be allowed:

    Analysis of Variance Table
    Model 1: Satisfaction + Age ~ Anxiety
    Model 2: Satisfaction ~ Age + Severity + Anxiety
       Res.Df  Res.Sum-Sq  Df  Sum-Sq       F  Pr(>F)
    1      21        2152
    2      19        2012   2   139.9  0.6609  0.5279
    It represents a test of whether beta1 = -1.0 and beta2 = 0.0
    using the generalized linear test statistic (see "Applied
    Linear Statistical Models" by Neter, Kutner, Nachtsheim,
    & Wasserman, 4th. Ed., 1996, pp. 315-316).

    I've modified the function to issue just a warning and go ahead and do
    the comparison regardless, but it seems as though a more thorough
    analysis of the comparability of the formulas should be made (or at
    least an option to 'anova' should be settable allowing one to override
    the default behavior of removing the offending formulas, which would
    then in turn get passed on to 'anovalist.[lm|glm]'):

    anovalist.lm <- function (object, ..., test = NULL)
        objects <- list(object, ...)
        responses <- as.character(lapply(objects,
            function(x) as.character(x$terms[[2]])))
        sameresp <- responses == responses[1]
        if (!all(sameresp)) {
    # dlm 12/10/97
    #               objects <- objects[sameresp]
    #               warning(paste("Models with response",
    #                       deparse(responses[!sameresp]),
    #                       "removed because response differs from", "model 1"))
                    warning(paste("Models with response",
                            "differ from", "model 1"))
    # dlm 12/10/97

5.  AOV

    Any word on 'aov' and friends?  Or alternatively, getting 'lm' (and
    associated 'anova' functions) to take multistratum error terms, so that
    one could call something like:

    anova(lm(Accuracy ~ Condition * MaxSteps * Difficulty +
             Error(Subject / MaxSteps + Subject / Difficulty), Data)));

    Is anyone currently working on this issue?  I *might* be able to lend a
    hand come May-June '98 if needed.  But, I suspect that this
    functionality would require changes / enhancements beyond the interpeted
    R language and into the guts of the R system itself.  While I can help
    at that level of programming as well, clearly I'd face a steep learning
    curve in terms of learning R's interals.  (Probably v. useful for
    one to know, but likely very time consuming as well).


Doug Morse                      please visit URL       Voice:   615 / 340-3400
Learning Technology Ctr   http://www.pobox.com/~morse    Fax:   615 / 340-3410
Vanderbilt University         for more information    E-Mail:  morse@pobox.com
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@stat.math.ethz.ch