[R] Parameter estimation in nls

Peter Dalgaard p.dalgaard at biostat.ku.dk
Tue Nov 25 10:59:47 CET 2003


Dr Andrew Wilson <eia018 at comp.lancs.ac.uk> writes:

> I am trying to fit a rank-frequency distribution with 3 unknowns (a, b
> and k) to a set of data.
> 
> This is my data set:
> 
> y <- c(37047647,27083970,23944887,22536157,20133224,
> 20088720,18774883,18415648,17103717,13580739,12350767,
> 8682289,7496355,7248810,7022120,6396495,6262477,6005496,
> 5065887,4594147,2853307,2745322,454572,448397,275136,268771)
> 
> and this is the fit I'm trying to do:
> 
> nlsfit <- nls(y ~ a * x^k * b^x, start=list(a=5,k=1,b=3))
> 
> (It's a Yule distribution.)
> 
> However, I keep getting:
> 
> "Error in nls(y ~ a * x^k * b^x, start = list(a = 5, k = 1, b = 3)) : 
> singular gradient"
> 
> I guess this has something to do with the parameter start values.
> 
> I was wondering, is there a fully automated way of estimating parameters
> which doesn't need start values close to the final estimates?  I know
> other programs do it, so is it possible in R?

You don't seem to have an x anywhere. Are you making the (apparently
not uncommon) mistake of trying to use a program for fitting nonlinear
relations by least squares to fit a probability density? If so, look
for fitdistr() instead.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list