我有一个数据框,
### 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")
一切正常,直到我尝试使用上述功能将其绘制出来。
答案 0 :(得分:1)