Margaret
Margaret

Reputation: 528

Step halving issue in gnls{nlme}

I am trying to estimate parameters for generalized least-squares regression on some community data. I have successfully done this for one set of data, but when I try the same technique to estimate parameters for another group, I get the following error message:

Error in gnls(SF ~ a * Site_Code^b, data = data, weights = varPower(form = ~Site_Code),  : 
  Step halving factor reduced below minimum in NLS step

I have noticed that other people have the same issue. One proposed solution is to set nlsTol to 0.1 instead of 0.001 (the default) using gnlsControl, but when I do this, I have the same issue. My data looks like this:

Site_Code   SF
5   3
5   0
5   2
5   0
5   0
5   0
5   2
5   0
5   0
5   0
5   0
5   3
1   0
1   1
1   29
1   15
1   7
1   0
1   10
1   12
1   55
2   0
2   5
2   0
2   0
2   3
2   24
2   49
2   17
2   1
3   4
3   48
3   7
3   1
3   31
3   0
3   0
3   1
4   8
4   16
4   29
4   0
4   1
4   2
4   1
4   7
4   3
7   2
7   0
7   0
7   0
7   0
7   0
7   2
7   1
7   0
7   1
7   0
7   0
8   1
8   2
8   1
8   2
8   0
8   0
8   3
8   0
8   2
6   0
6   6
6   0
6   0
6   0
6   0
6   0
6   0
6   0
6   2
6   0
6   3

Upvotes: 0

Views: 3333

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226182

Worked fine for me; you didn't give starting values, so I eyeballed some. Maybe you have worse starting values?

Also, it's not surprising that you're having trouble here -- for the purposes of fitting the mean, you have two parameters and only 4 independent x values ... and the same for the variance estimation.

dat <- read.table("gnlsdat.txt",header=TRUE)
plot(SF~Site_Code,data=x)

library(nlme)
g0 <- gnls(SF ~ a * Site_Code^b, data = dat,
           weights = varPower(form = ~Site_Code),
           start=list(a=30,b=-0.5))

Results:

Generalized nonlinear least squares fit
  Model: SF ~ a * Site_Code^b 
  Data: dat 
  Log-likelihood: -130.3289

Coefficients:
        a         b 
19.319493 -1.152149 

Variance function:
 Structure: Power of variance covariate
 Formula: ~Site_Code 
 Parameter estimates:
    power 
-0.885528 
Degrees of freedom: 33 total; 31 residual
Residual standard error: 28.10023 

Plot:

plot(SF~Site_Code,data=x)
pframe <- data.frame(Site_Code=seq(1,5,length=41))
lines(pframe$Site_Code,predict(g0,newdata=pframe))

enter image description here

Upvotes: 1

Related Questions