[R] Error using nls()

Dietrich Trenkler Dietrich.Trenkler at uni-osnabrueck.de
Fri Sep 21 14:57:27 CEST 2007


Hallo HelpeRs,

I try to reconstruct some results from an econometric text book
(Heij et al. (2004), pp. 218-20).

For the data

 > x <- structure(list(q1 = c(345, 331, 320, 314, 299, 395, 415,
    490, 547, 656, 628, 627), d1 = c(1, 1, 1, 1, 1, 1, 1.05,
    1.05, 1.05, 1.15, 1.15, 1.15)), .Names = c("q1", "d1"), row.names = 
as.integer(c(NA,
    12)), class = "data.frame")

I tried to estimate a nonlinear regression model using nls(). I get

 > 
nls(log(q1)~b1+(b2/b3)*(d1^b3-1),data=x,start=list(b1=0,b2=1,b3=1),trace=TRUE)
246.132 :  0.0000  1.0000  1.0000 51.0907
Error in qr.solve(QR.B, cc) : singular matrix 'a' in solve

However, using:

 > jjf <- function(x){z <- log(q1)-x[1]+(x[2]/x[3])*(d1^x[3]-1);sum(z*z)}
 > optim(c(0,1,1),jjf)

rendered (some of) the results desired in a jiffy. What am I doing 
wrong?    

Dietrich

-- 
Dietrich Trenkler c/o Universitaet Osnabrueck 
Rolandstr. 8; D-49069 Osnabrueck, Germany    
email: Dietrich.Trenkler at Uni-Osnabrueck.de



More information about the R-help mailing list