s-news
[Top] [All Lists]

Odd behavior in "step'

To: s-news@lists.biostat.wustl.edu
Subject: Odd behavior in "step'
From: Dennis Fisher <fisher@plessthan.com>
Date: Sun, 19 Mar 2006 09:20:42 -0800
In-reply-to: <20060318112006.090DE33E454@smtp.biostat.wustl.edu>
References: <20060318112006.090DE33E454@smtp.biostat.wustl.edu>
Colleagues

I have encountered some odd behavior in "step".  I am performing a GLM as following:

FRAME <- cbind(Column1, OtherColumns)
FORMULA <- as.formula(paste(Column1, " ~ ", NamesOfOtherColumns, collapse=" "))
FORMFIT <- glm(FORMULA, data="">
print(FORMFIT) # for diagnostic purposes only
STEP <- step(FORMFIT, direction="both")

When I run these steps at the command line, they work.  However, when this same code exists within a function, it fails at the final command.  The output is:

Call:
glm(formula = FORMULA)

Coefficients:
(Intercept)       dosegrp         KG           AGE       bsa          cr          CrCl   bilirubin         ast         alt
  -0.0218229 -4.901972e-05 0.01046179 -0.0005088998 -0.740975 -0.09453478 -0.0004937748 -0.08117933 0.002980082 0.001140366

   livermult  livercateg       alkphos   totalprot   albumin          ca
-0.02819336 -0.04540486 -0.0002865876 -0.09739364 0.1807325 -0.04145678

Degrees of Freedom: 92 Total; 76 Residual

Residual Deviance: 5.060708

Problem in eval(oc, list()): Object "FORMULA" not found

The error message above (which is generated at execution of the "step" command) does not make sense to me.  The earlier statement "Call: glm(formula = FORMULA)" indicates the S-plus found FORMULA once.  

In attempting to diagnose the problem, I removed the commands from a user-defined function - this solved the problem.  So, there is something about assignments within a function that appears to be creating the problem.

Incidentally, the identical code works in R.

Thoughts?

Dennis


Dennis Fisher MD

P < (The "P Less Than" Company)

Phone: 1-866-PLessThan (1-866-753-7784)

Fax: 1-415-564-2220

www.PLessThan.com



<Prev in Thread] Current Thread [Next in Thread>