[R] Error: C stack usage is too close to the limit

William Dunlap wdunlap at tibco.com
Mon Sep 14 19:39:49 CEST 2009


> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Luis Ridao Cruz
> Sent: Monday, September 14, 2009 6:24 AM
> To: R-help
> Subject: [R] Error: C stack usage is too close to the limit
> 
> R-help,
> 
> I 'm trying to optimize a model to data using log-likelihoods
> but I encounter the following error message:
> 
> > l= c(49.4, 57.7,64.8,70.9,78.7,86.6,88.3,91.6,99,115)
> > t=3:12
> > fn <- function(params, l=l, t=t) {

You should not make the default value of an argument be
the argument itself or a function of itself as that leads to
infinite recursion.  Make l and t free variables (to be retrieved
from the environment that fn is defined in) or give the function
argument a different name than its default value (so the
default value is read from the defining environment) or use no
default value and have optim pass in the arguments on each
call.

Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com 

> 		Linf   <-  params[1]
> 		k       <-  params[2]
> 		t0     <-  params[3]
>                                sigma <-  params[4]
>                                 lhat   <-  
> params[1]*(1-exp(-params[2]*(t-params[3])))
> 		logL   <-  
> -sum(dnorm(log(l),log(lhat),sqrt(sigma),TRUE))
> 		return(logL)
>                     }
> 
> > resop <- optim(c(120, .1, 0, 1), fn, 
> method="L-BFGS-B",lower=c(0.0, 0.001, 0.001,0.01)
> +     ,upper = rep(Inf, 4), hessian=TRUE, control=list(trace=1))
> 
> Error: C stack usage is too close to the limit
> 
> Thanks in advance.
> 
> 
> Running R on a Windows XP machine
> > version
>                _                           
> platform       i386-pc-mingw32             
> arch           i386                        
> os             mingw32                     
> system         i386, mingw32               
> status                                     
> major          2                           
> minor          8.1                         
> year           2008                        
> month          12                          
> day            22                          
> svn rev        47281                       
> language       R                           
> version.string R version 2.8.1 (2008-12-22)
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 




More information about the R-help mailing list