0
我想,以適應使用dplyr
和broom
(最終mclapply
)並行使用wrapnls
許多非線性配合,但我從nlxb
得到一個解析計算錯誤:如何在dplyr中運行nlxb和wrapnls?
Error in parse(text = joe) (from #11) : <text>:1:6: unexpected input
1: b1.10% <- 20
我得到同時使用do
這個錯誤lapply
方法。
library(nlmrt)
library(dplyr)
library(purrr)
library(broom)
data_frame(x = seq(0, 200, 0.1),
y = 1.2*exp(-(times - 10)^2/(2*4.2^2)) + 2.4*exp(-(times - 50)^2/(2*3.8^2)) + 5.3*exp(-(times - 80)^2/(2*5.1^2)) + rnorm(length(times), sd = 0.05)) %>%
do({
xl <- quantile(.$x, 0.1, na.rm = TRUE)
xm <- quantile(.$x, 0.5, na.rm = TRUE)
xh <- quantile(.$x, 0.8, na.rm = TRUE)
starts <- c(a1 = 5, a2 = 5, a3 = 5,
b1 = xl, b2 = xm, b3 = xh,
c1 = 5, c2 = 5, c3 = 5)
fmla <- y ~ a1*exp(-(x - b1)^2/(2*c1^2)) + a2*exp(-(x - b2)^2/(2*c2^2)) + a3*exp(-(x - b3)^2/(2*c3^2))
df <- data_frame(x = .$x, y = .$y)
mod <- wrapnls(fmla, lower = 0, upper = 200, start = starts, data = df)
tidy(mod)
})
有沒有辦法解決這個問題?
這比我想象的要簡單。謝謝,我會記住不要在有特殊評估的情況下直接使用'quantile'魔法正在進行:) – wdkrnls