在gnls {nlme}中减少一半的问题

时间:2012-05-09 00:49:58

标签: r regression linear linear-regression

我正在尝试估算某些社区数据的广义最小二乘回归的参数。我已经成功地为一组数据做了这个,但是当我尝试使用相同的技术来估计另一个组的参数时,我收到以下错误消息:

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

我注意到其他人也有同样的问题。一个建议的解决方案是使用gnlsControl将nlsTol设置为0.1而不是0.001(默认值),但是当我这样做时,我遇到了同样的问题。我的数据如下:

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

1 个答案:

答案 0 :(得分:1)

对我来说工作得很好;你没有给出起始值,所以我用眼睛看了一些。也许你的起始值更差?

另外,你在这里遇到麻烦也就不足为奇了 - 为了拟合均值,你有两个参数,只有4个独立的x值......对于方差估计也是如此。

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))

结果:

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(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