On Mon, 25 Feb 2002, Andreas Pauling wrote:
> Dear R-community
> The following loops produce the error message:
>
> Error in round(x, digits) : Non-numeric argument to mathematical
> function
>
> after performing the outer loop 6 times
>
> Splus can execute these loops but is very much slower than R .
> Interestingly, if the scale-argument in the step-function is omitted R
> performes these loops a few times more.
> What could be the reason for that error?
Hard to tell. You haven't used traceback() or options(error=dump.frames) to
find out where it is occurring. But as you are using round() in your
function, a plausible guess is that summary(fit)$r.squared is NULL because
intercept-only models do not return that component.
This is a good opportunity for you to learn how to debug S code.
BTW, I am suspicious of scale = 2. How do you know in advance that the
error variance is exactly 2 for all 286 of your responses? (It has the
same meaning as scale in summary.lm.)
> Any hint is appreciated!
>
> Andreas
>
>
> RQuadrat<-list()
> elimParam<-list()
> frei.grade<-list()
> RQuadrat<-c(rep(list(rep(NA,286)),26))
> elimParam<-c(rep(list(rep(NA,286)),26))
> frei.grade<-c(rep(list(rep(NA,286)),26))
>
> cat('\nVerarbeitete Gitterpunkte (von 286):\n')
>
> for(i in 1:286)
> {
> j<-1
> if(any(is.na(annJMSLTv.box[,i])==F))
> {
>
>
fit<-lm(annJMSLTv.box~.,data=data.frame(annJMSLTv.box=annJMSLTv.box[,i],docuProxies),
> na.action=na.omit)
> RQuadrat[[j]][i]<-round(summary(fit)$r.squared, dig=3)
> frei.grade[[j]][i]<-fit$df.residual
>
> for(j in 2:26)
> {
> backfit<-step(fit,scale=2,trace=F,steps=1)
> fit<-eval(backfit$call)
> RQuadrat[[j]][i]<-round(summary(fit)$r.squared,3)
> frei.grade[[j]][i]<-fit$df.residual
>
>
elimParam[[j]][i]<-paste(as.character(backfit$anova$Step),collapse="")
> }
> cat(i,' ')
> }
> }
>
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
>
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._