[Rd] LM/GLM can't find weights vector from within a function (PR#13735)

gaidys at uol.com.br gaidys at uol.com.br
Mon Jun 1 03:35:12 CEST 2009


Full_Name: Alberto Gaidys
Version: 2.9.0
OS: Mac OS X 10.5.7
Submission from: (NULL) (201.81.185.155)


When calling LM or GLM from within a function, R gives a message error that it
can't find the specified weights object "Erro em eval(expr, envir, enclos) :
objeto 'W' não encontrado" (Error in eval(expr, envir, enclos) : object 'W' not
found). 

The call from within the user-defined function where the error happens is:

   rReg<-lm(formula=rFormula,data=rData,subset=1:i,weights=W,x=TRUE,y=TRUE)

where rFormula is a text string, rData is a 1422 x 17 timeSeries data matrix,
both passed from the console, i is a counter, W is a 1422 x 1 numeric vector of
weights declared locally within the function.

The function definition is as follows:

   redls<-function(rFormula, rData, nStart, rBeta=1., nDelayed=3)

I already tried to define W externally to the function and parse it as a
parameter, change its name, declare it as an array, declare it as a timeSeries
object, with always the same error. Invoking glm instead of lm gives also the
same error. The ls.str listing of W immediately before calling lm, showing it
does exist, is:

   W :  num [1:1422(1d)] 0.00628 0.0064 0.00654 0.00667 0.00681 ...

The exactly same lm call, with the objects created exactly the same way from the
console produces no error though.



More information about the R-devel mailing list