gpt4 book ai didi

r - 如何在 geom_smooth 中使用方法 ="nlsLM"(在 minpack.lm 包中)

转载 作者:行者123 更新时间:2023-12-01 01:49:09 28 4
gpt4 key购买 nike

test <- data.frame(Exp = c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 
5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6), t = c(0, 0.33, 0.67,
1, 1.33, 1.67, 2, 4, 6, 8, 10, 0, 33, 0.67, 1, 1.33, 1.67, 2, 4, 6, 8, 10,
0, 0.33, 0.67, 1, 1.33, 1.67, 2, 4, 6, 8, 10), fold = c(1,
0.957066345654286, 1.24139015724819, 1.62889151698633, 1.72008539595879,
1.82725412314402, 1.93164365299958, 1.9722929538061, 2.15842019312484,
1.9200507796933, 1.95804730344453, 1, 0.836176542548747, 1.07077717914707,
1.45471712491441, 1.61069357875771, 1.75576377806756, 1.89280913889538,
2.00219054189937, 1.87795513639311, 1.85242493827193, 1.7409346372629, 1,
0.840498729335292, 0.904130905000499, 1.23116185602517, 1.41897551928886,
1.60167656534099, 1.72389226836308, 1.80635095956481, 1.76640786872057,
1.74327897001172, 1.63581509884482))

d <- ggplot(test,aes(x=t, y=fold))+
#to make it obvious I use argument names instead of positional matching
geom_point()+
geom_smooth(method="nls",
formula=y~1+Vmax*(1-exp(-x/tau)), # this is an nls argument
method.args = list(start=c(tau=0.2,Vmax=2)), # this too
se=FALSE)

我在这个网站上找到了代码,但我想知道如何在 geom_smooth 中将 method="nls" 更改为 method = "nlsLM",因为在设置起始值时,原始的“nls”对我来说确实是一个大问题。
ggplot2中geom_smooth的方法有没有办法使用cran中的包?
谢谢

最佳答案

你似乎什么都没试过。你可以简单地做显而易见的事情:

library(ggplot2)
library(minpack.lm)
d <- ggplot(test,aes(x=t, y=fold))+
geom_point()+
geom_smooth(method="nlsLM",
formula=y~1+Vmax*(1-exp(-x/tau)),
method.args = list(start=c(tau=0.2,Vmax=2)),
se=FALSE)
print(d)
#works

请注意,收敛问题没有简单的一刀切解决方案。有时 minpack 可以提供帮助,但通常它只会让您不适合 nls有助于抛出错误。

关于r - 如何在 geom_smooth 中使用方法 ="nlsLM"(在 minpack.lm 包中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45971661/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com