Bug 15935 - drop1 gives error if no terms can be dropped
Summary: drop1 gives error if no terms can be dropped
Status: CLOSED FIXED
Alias: None
Product: R
Classification: Unclassified
Component: Analyses (show other bugs)
Version: R 3.1.1
Hardware: All Linux
: P5 minor
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2014-08-15 11:22 UTC by Adrian Baddeley
Modified: 2014-08-15 11:58 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Adrian Baddeley 2014-08-15 11:22:11 UTC
drop1.lm, drop1.glm and drop1.default all give error messages if the fitted model has no terms that can be dropped. See examples below.

The bug is similar in each function:
        ns <- length(scope)
        .......
        for(i in 1:ns) { ...... }
                 ****

If there are no terms that can be dropped, then 'scope' = character(0), and 'ns' = 0, so a loop over 1:ns or seq(ns) is not correct.

Examples:
> y <- 1:3
> drop1(lm(y~1))
Error in data.frame(Df = dfs, `Sum of Sq` = c(NA, RSS[-1L] - RSS[1L]),  : 
  'row.names' should specify one of the variables
> drop1(glm(y~1))
Error in data.frame(Df = dfs, Deviance = dev, AIC = aic, row.names = scope,  : 
  'row.names' should specify one of the variables
> stats:::drop1.default(glm(y~1))
Error in terms.formula(tmp, simplify = TRUE) : 
  invalid model formula in ExtractVars
Comment 1 Duncan Murdoch 2014-08-15 11:58:38 UTC
I see this, and will fix it in R-devel and R-patched.  Thanks!