我总是得到错误:
级别(x)出错:缺少参数“object”,没有默认值
试图适应时:
fit60 <- nls(Predicted.Bromide~c+a*(1-exp(-b*n)),start=C(a=10,b=0.02,c=0),data=min60)
或者将列提取到x = min60min和y = area:
fit60 <- nls(area~C+A*(1-exp(-B*min60min)),start=C(A=0,B=0,C=0))
数据集:
dput(min60)
structure(list(Predicted.Bromide = c(4721.05, 16030.5, 17251.1,
20353.1, 22997.8, 24657.3, 26896.4, 26529.1, 25282.7, 26546.2,
27265.3, 27491.1, 27678.4, 30140.1, 28285.4, 28079.6, 29111.3,
28781.1, 28723.7, 27959.3, 29430.7, 30273.6, 28618.7, 29716,
29761.5, 30276.7, 29642.6, 31369.1, 33416.5, 31204.2, 32652.1,
31013.3, 32591.6, 33436.7, 32240.2, 32557.2, 31548.4, 33701.9,
32376.5, 34323.4, 34430.5, 33255.7, 33988.1, 32779.9, 34013.3,
35157.1, 34905.4, 32918.9, 34915.6, 35001.5, 33874.1, 34954.4,
34495.8, 34679.4, 33409.8, 34318.7), n = c(1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56)), .Names = c("Predicted.Bromide", "n"), row.names = c(NA,
56L), na.action = structure(57L, .Names = "57", class = "omit"), class = "data.frame")
可能是什么问题?在我看来,代码中的一切都是正确的。
答案 0 :(得分:0)
fit60 <- nls(Predicted.Bromide~c+a*(1-exp(-b*n)),start=C(a=10,b=0.02,c=0),data=min60)
中有一个拼写错误,它应该是一个小c
。然后它只是找到正确的起始值。
我不确定你想要的方程是否正确。不应该
a*(1 - exp(-b*n))
Terazaki(1915)/ Schumacher
答案 1 :(得分:0)
这是一个可能的解决方案:
min60 <- structure(list(Predicted.Bromide = c(4721.05, 16030.5, 17251.1,
20353.1, 22997.8, 24657.3, 26896.4, 26529.1, 25282.7, 26546.2,
27265.3, 27491.1, 27678.4, 30140.1, 28285.4, 28079.6, 29111.3,
28781.1, 28723.7, 27959.3, 29430.7, 30273.6, 28618.7, 29716,
29761.5, 30276.7, 29642.6, 31369.1, 33416.5, 31204.2, 32652.1,
31013.3, 32591.6, 33436.7, 32240.2, 32557.2, 31548.4, 33701.9,
32376.5, 34323.4, 34430.5, 33255.7, 33988.1, 32779.9, 34013.3,
35157.1, 34905.4, 32918.9, 34915.6, 35001.5, 33874.1, 34954.4,
34495.8, 34679.4, 33409.8, 34318.7), n = c(1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56)), .Names = c("Predicted.Bromide", "n"), row.names = c(NA,
56L), na.action = structure(57L, .Names = "57", class = "omit"), class = "data.frame")
head(min60)
plot(Predicted.Bromide ~ n, min60)
FUN <- function(n, a, b, c){
Predicted.Bromide <- c+a*(1-exp(-b*n))
Predicted.Bromide
}
plot(min60$n, FUN(min60$n,1e5,0.1,1000), t="l")
points(Predicted.Bromide ~ n, min60)
starting.values <- list(a=1e5,b=0.1,c=1000)
#lower.values <- list(a=1,b=0,c=0)
#upper.values <- list(a=1e7,b=3,c=10000)
fit60 <- nls(Predicted.Bromide ~ FUN(n,a,b,c),
data=min60,
start = starting.values,
#lower = lower.values,
#upper = upper.values,
algorithm = "port"
)
fit60
plot(Predicted.Bromide ~ n, min60)
lines(predict(fit60, min60))
答案 2 :(得分:0)
正如@ Mateusz1981指出的那样,错误是由于拼写错误而发生的。如果你修正了这个错字,你最终会得到另一条错误信息(&#34;奇异渐变&#34;)。这意味着您必须调整起始值。以下工作对我来说很好:
fit60 <- nls(Predicted.Bromide~c+a*(1-exp(-b*n)),start=c(a=8000,b=0.2,c=4000),data=min60)
plot(Predicted.Bromide ~ n, min60)
lines(predict(fit60, min60), col='red')
答案 3 :(得分:0)
对此问题使用"plinear"
算法,您不需要线性参数的起始值。在.lin1
和.lin2
下面的解决方案是a
和c
:
fit60 <- nls(Predicted.Bromide ~ cbind(1, 1-exp(-b*n)), data = min60,
start = list(b = 0.02), algorithm = "plinear")
,并提供:
> fit60
Nonlinear regression model
model: Predicted.Bromide ~ cbind(1, 1 - exp(-b * n))
data: min60
b .lin1 .lin2
1.231e-01 9.265e+03 2.384e+04
residual sum-of-squares: 1.97e+08
Number of iterations to convergence: 23
Achieved convergence tolerance: 5.93e-06