Hello Dennis,
I don't know the exact answer to your question (I don't have a current
copy of SPlus any more, and in any event I am not familiar with the
GLM functions. However, I am trying to answer based on memory of some
past discussion / a basic understanding of the way things work.
I think the issue is that in SPLus the user defined function you
mention creates its own environment (workspace, if you wish) while
perhaps in R the FORMULA object might be found within the global
context. (I don't know the comparative rules, but the only thing you
need to know is that the scoping rules differ between R and SPlus --
to understand your problem). So, there are two ways to fix this:
a) Pass the FORMULA object to the function in question (and assign it
to a local object called "FORMULA" in there) (relying on globals is a
bad idea in most situation anyway) or
b) Create the FORMULA object within the function in the first place --
then it will be in the environment from which glm was called (ie the
environment of the function).
Hope this gets you going. If not, please let us know.
Vivek
On 3/19/06, Dennis Fisher <fisher@plessthan.com> wrote:
>
> 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=FRAME)
> 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
>
>
>
--
-- Vivek Satsangi
Student, Rochester, NY USA
Life is short, the art long, opportunity fleeting, experiment
treacherous, judgement difficult.
|