r - Can we make prediction with nlxb from nlmrt package? -
i'm asking question because couldn't figure out why nlxb
fitting function not work predict() function.
i have been looking around solve far no luck:(
i use dplyr
group data , use do
fit each group using nlxb
nlmrt
package.
here attempt
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))
--------------------------------------------------------
there 2 points finally,
1)first, how fitting coefficients of each group in continuation dffit
pipeline.
2) doing prediction of based on new x values.
for instance range <- data.frame(x=seq(1e-5,20000,length.out=10000))
predict(fit,data.frame(x=range)
error in usemethod("predict") : no applicable method 'predict' applied object of class "nlmrt"
since nlxb
working smoothly compared nls
r-minpack-lmnls-lm-failed-with-good-results prefer solutions nlxb
. if have better solution please let know.
there no coef
or predict
methods "nlmrt"
class objects nlmrt package provide wrapnls
run nlmrt
, nls
"nls"
object results , object can used "nls"
class methods.
also note nls.lm.control
nlslm package , should not used here -- use list
instead.
Comments
Post a Comment