Skip to content
Back to formatted view

Raw Message

Message-ID: <08a601cd3406$9b2f0310$d18d0930$@net>
Date: 2012-05-17T08:25:23Z
From: David A Vavra
Subject: step function stops with "subscript out of bounds"
In-Reply-To: <CAHWp7yRdodyWgojZj7jhVCcmsx7C=w3_pHLXtwWCZWxECX1Kgg@mail.gmail.com>

I've been having a problem using the step function to evaluate models. I've
simplified the code and get the same problem using the dataset Titanic. The
relevant code and output is below. The problem disappears (i.e., 'step' runs
correctly) if I rerun the code but change the 'loglm' call to explicitly
reference Titanic instead of X (as in: loglm(as.formula(Y),data=Titanic)).

What is causing this?

TIA,
DAV	

----------

> catn<-function(...) cat(...,"\n")
> local({  X<-Titanic; print(class(X)); 
           Y<-paste('~',paste(names(dimnames(X)),collapse="*")); 
           print(Y); 
           sm<-loglm(as.formula(Y),data=X); 
           catn("SM"); print(sm); catn('running'); 
           step(sm,direction='backward')  })

Output:

[1] "table"
[1] "~ Class*Sex*Age*Survived"
SM 
Call:
loglm(formula = as.formula(Y), data = X)

Statistics:
                 X^2 df P(> X^2)
Likelihood Ratio   0  0        1
Pearson          NaN  0        1
running 
Start:  AIC=64
~Class * Sex * Age * Survived

Error in loglin(data, margins, start = start, fit = fitted, param = param,
: 
  subscript out of bounds

Enter a frame number, or 0 to exit   

1: local({
    X <- Titanic
    print(class(X))
    Y <- paste("~", paste(names(dimnames(X)), collapse = "*"))
    print(Y)
    sm <- loglm(as.formula(Y), data = X
 2: eval.parent(substitute(eval(quote(expr), envir)))
 3: eval(expr, p)
 4: eval(expr, envir, enclos)
 5: eval(quote({
    X <- Titanic
    print(class(X))
    Y <- paste("~", paste(names(dimnames(X)), collapse = "*"))
    print(Y)
    sm <- loglm(as.formula(Y), dat
 6: eval(expr, envir, enclos)
 7: #1: step(sm, direction = "backward")
 8: #1: drop1(fit, scope$drop, scale = scale, trace = trace, k = k, ...)
 9: #1: drop1.default(fit, scope$drop, scale = scale, trace = trace, k = k,
...)
10: #1: update(object, as.formula(paste("~ . -", tt)), evaluate = FALSE)
11: #1: update.loglm(object, as.formula(paste("~ . -", tt)), evaluate =
FALSE)
12: #1: eval.parent(call)
13: #1: eval(expr, p)
14: #1: eval(expr, envir, enclos)
15: #1: loglm(formula = ~Class + Sex + Age + Survived + Class:Sex +
Class:Age + Sex:Age + Class:Survived + Sex:Survived + Age:Survived +
Class:Sex:Age + Class:
16: #1: loglm1(formula, data, ..., .call = .call, .formula = .formula)
17: #1: loglm1.default(formula, data, ..., .call = .call, .formula =
.formula)
18: #1: loglin(data, margins, start = start, fit = fitted, param = param,
eps = eps, iter = iter, print = print)

Selection: 0