我问这个问题是因为我不明白为什么nlxb
拟合函数不能与 Predict() 函数一起使用。
我一直在寻找解决这个问题的方法,但到目前为止还没有运气:(
I use dplyr
对数据进行分组并使用do
适合每个组使用nlxb
from nlmrt
包裹。
这是我的尝试
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))
预测(拟合,data.frame(x =范围)
Error in UseMethod("predict") :
no applicable method for 'predict' applied to an object of class "nlmrt"
Since nlxb
相比之下工作顺利nls
r-minpack-lmnls-lm 失败但结果良好 https://stackoverflow.com/questions/35409099/r-minpack-lmnls-lm-failed-with-good-results/35516421#35516421我更喜欢以下解决方案nlxb
。但如果您有更好的解决方案,请告诉我们。