如何使用method ="nlsLM" (在minpack.lm软件包中)在geom_smooth中 [英] how to use method="nlsLM" (in packages minpack.lm) in geom_smooth

查看:488
本文介绍了如何使用method ="nlsLM" (在minpack.lm软件包中)在geom_smooth中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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的软件包? 谢谢

I find the code here in this site, but I wonder how to change method="nls" to method = "nlsLM" in geom_smooth, as the original "nls" is really a big problem to me when setting the start values. Is there any ways to use packages from cran in the method of geom_smooth in ggplot2? Thanks

推荐答案

您似乎没有尝试任何操作.您可以简单地进行以下操作:

You don't seem to have tried anything. You can simply do the obvious:

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会引发错误.

Note that convergence problems do not have an easy one-size-fits-all solution. Sometimes minpack can help, but often it will simply give you a bad fit where nls helpfully throws an error.

这篇关于如何使用method ="nlsLM" (在minpack.lm软件包中)在geom_smooth中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆