【发布时间】:2021-02-01 12:36:25
【问题描述】:
当我使用 geom_smooth nls 拟合我的数据时,我得到了一个非常好的拟合。但是,如果我使用独立的 nls 函数使用相同的方程和起始值来拟合我的数据,我得到的拟合效果要差得多。我想提取拟合参数,所以真的需要独立的 nls 来生成与 geom_smooth nls 相同的拟合。
对可能发生的事情有任何建议/提示吗?
df <- data.frame("x" = c(4.63794469, 1.54525711, 0.51508570, 0.17169523, 0.05737664, 5.11623138, 1.70461130, 0.56820377, 0.18940126, 0.06329358, 0.02109786),
"y" = c(0.1460101, 0.7081954, 0.9619413, 1.0192286, 1.0188301, 0.3114495, 0.7602488, 0.8205661, 0.9741323, 1.0922553, 1.1130464))
fit <- nls(data = df, y ~ (1/(1 + exp(-b*x + c))), start = list(b=1, c=0))
df$stand_alone_fit <- predict(fit, df)
df %>% ggplot() +
geom_point(aes(x = x, y = y)) +
scale_x_log10() +
ylim(0,1.2) +
geom_smooth(aes(x = x, y = y), method = "nls", se = FALSE,
method.args = list(formula = y ~ (1/(1 + exp(-b*x + c))), start = list(b= 1, c=0))) +
geom_line(aes(x = x, y = stand_alone_fit), color = "red") +
labs(title = "Blue: geom_smooth nls fit\nRed: stand alone nls fit")
【问题讨论】:
标签: r ggplot2 data-fitting nls