如何在不使用ssfpl的情况下创建四参数自启动功能?
我尝试使用以下公式创建自启动函数:
((bpX * ((bpY * x)^s2)) / (1 + ((bpY * x)^s2)))^(s1 / s2)
这是自启动功能:
SS_sample <- selfStart(
((bpX * ((bpY * x)^s2)) / (1 + ((bpY * x)^s2)))^(s1 / s2),
model = function(x, breakPointX, breakPointY, slope1, slope2)
{
ifelse(x > breakPointX,
(x - breakPointX) * slope2 + breakPointY,
(x - breakPointX) * slope1 + breakPointY)
},
initial = function(mCall, data, LHS)
{
xy <- sortedXyData(mCall[["x"]], LHS, data)
n <- nrow(xy)
if (n < 4) {
stop("TOO FEW DISTINCT INPUT VALUES TO FIT THE MODEL")
}
first <- seq(from=1, length.out=4)
last <- seq(length.out=4, to=n)
fit1 <- coefficients(lm.fit(cbind(1,xy[first,"x"]), xy[first,"y"]))
fit2 <- coefficients(lm.fit(cbind(1,xy[last,"x"]), xy[last,"y"]))
slope1 <- fit1[[2]]
slope2 <- fit2[[2]]
bpXY <- solve(cbind(-c(slope1,slope2), 1),
as.matrix(c(fit1[[1]], fit2[[1]])))
breakPointX <- bpXY[1]
breakPointY <- bpXY[2]
structure(list(breakPointX, breakPointY, slope1, slope2),
names=as.character(mCall[c("breakPointX", "breakPointY", "slope1", "slope2")]))
},
parameters = c("breakPointX", "breakPointY", "slope1", "slope2"))
当我尝试将函数拟合到nls模型上时,它总是以奇异的梯度错误结束。
我们非常感谢您的帮助。谢谢。