我在问这个问题,因为我无法弄清楚为什么nlxb
拟合函数不适用于predict()函数。我们可以使用nlmrt软件包进行nlxb预测吗?
我一直在四处寻找解决这一点,但至今没有运气:(
我用dplyr
对数据进行分组,并使用do
从nlmrt
包适合使用nlxb
每个组。
这里是我的尝试
set.seed(12345)
set =rep(rep(c("1","2","3","4"),each=21),times=1)
time=rep(c(10,seq(100,900,100),seq(1000,10000,1000),20000),times=1)
value <- replicate(1,c(replicate(4,sort(10^runif(21,-6,-3),decreasing=FALSE))))
data_rep <- data.frame(time, value,set)
> head(data_rep)
# time value set
#1 10 1.007882e-06 1
#2 100 1.269423e-06 1
#3 200 2.864973e-06 1
#4 300 3.155843e-06 1
#5 400 3.442633e-06 1
#6 500 9.446831e-06 1
* * * *
library(dplyr)
library(nlmrt)
d_step <- 1
f <- 1e9
d <- 32
formula = value~Ps*(1-exp(-2*f*time*exp(-d)))*1/(sqrt(2*pi*sigma))*exp(-(d-d_ave)^2/(2*sigma))*d_step
dffit = data_rep %>% group_by(set) %>%
do(fit = nlxb(formula ,
data = .,
start=c(d_ave=44,sigma=12,Ps=0.5),
control=nls.lm.control(maxiter = 100),
trace=TRUE))
------------------------------------------- -------------
我最后想得到两点,
1)首先,如何得到每组的拟合系数连续到dffit
管道。
2)根据新的x值做预测。
例如range <- data.frame(x=seq(1e-5,20000,length.out=10000))
预测(FIT,data.frame(x =范围)
Error in UseMethod("predict") :
no applicable method for 'predict' applied to an object of class "nlmrt"
由于nlxb
是否工作顺利相比nls
r-minpack-lmnls-lm-failed-with-good-results我宁愿解决方案nlxb
。但如果你有一个更好的解决方案,请让我们知道。
感谢您的建议。我会在检查完'wrapnls'后通知你。 – Alexander
我检查了'wrapnls'并且拟合不会收敛并且得到奇异的梯度误差。你有没有看到我的最新帖子[未能做到 - 尝试与nls-nlxb-and-wrapnls合作](http://stackoverflow.com/questions/37133471/failed-to-do-fitting-几家尝试与 - NLS-nlxb-和wrapnls) – Alexander