nlsTracePlot returns "is not a function" - 如何解决这个问题?(R)

nlsTracePlot returns "is not a function" - how to solve this issue?(R)

我有一个数据框,

### create sample data
set.seed(1)
x = runif(n = 100, 0, 20)
beta1 = 2
beta2 = 1
beta3 = (1/2)

### Create sample data frame and vector
y = beta1 + beta2*x^(beta3) + rnorm(n = 100, 0, 0.01)
 data = as.data.frame(cbind(y,x))

 ### Fitting the data with nls()-function;
 fit1 = nls(
 y~vb1(x,beta1,beta2,beta3),
 data=data,start=list(beta1 = 0, beta2 = 1, beta3 = 1)
)

哪里

 vb1 = function(x,beta1,beta2,beta3){
   beta1 + beta2*x^(beta3)
 }

最后我想绘制输出:

 plot(y~x, col = 3)
 nlsTracePlot(fit1,vb1(x,beta1,beta2,beta3),legend="bottomright")

但是,它给出了以下错误,

 3. stop(gettextf("'%s' is not a function, character or symbol",           deparse(FUN)), domain = NA)
 2. match.fun(fun)
 1. nlsTracePlot(fit1, vb1(x, beta1, beta2, beta3), legend = "bottomright")

一切正常,直到我尝试用上面的函数绘制它。

假设您使用的是 FSA 包,您需要将 fun 参数传递给原始函数。该功能需要以特定方式指定。有关详细信息,请参阅 nlsTracePlot 的文档。

vb1 <- function(x, beta1, beta2, beta3){
  if (length(beta1) == 3) {
    beta2 <- beta1[2]
    beta3 <- beta1[3]
    beta1 <- beta1[1]
  }
  beta1 + beta2 * x^(beta3)
}

plot(y ~ x, col = 3)
nlsTracePlot(fit1, vb1, legend = "bottomright")