小编Ell*_*len的帖子

在ggplot中存在非线性回归问题

attenuation = data.frame(km =      
c(0,0,0.4,0.4,0.8,0.8,1.2,1.2,1.6,1.6,2,2,2.4,2.4,2.8,2.8,3.2,3.2,3.6,3.6,4, 
4,4.4,4.4,4.8,4.8,5.2,5.2,5.6,5.6,6,6,6.4,6.4,6.8,6.8,7.2,7.2,7.6,7.6,8,8, 
11.7,11.7,13,13), edna = c(76000,20000,0,0,6000,0,0,6880,10700,0,6000,
0,0,0,0,0,0,6000,0,0,0,0,0,0,0,0,6310,0,6000,6000,0,0,0,0,0,
0,0,0,0,0,0,6000,0,0,0,0))

#This worked great for a linear regression
ggplot(attenuation, aes(x = km, y = edna)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
xlab("Distance from Cage (km)") +
ylab("eDNA concentration (gene sequence/Liter)")
Run Code Online (Sandbox Code Playgroud)

但是线性回归似乎不太适合(r平方= 0.09)。因此,我想尝试其他方法。我还尝试了拟合度较差的其他一些回归,因此我想尝试一个非线性回归。

我研究了有关堆栈溢出的问题,并尝试了多种不同的选择,但是没有任何效果。我在下面提供的选项最有意义-但我想知道公式是否错误?还是需要修改开始列表?

就上下文而言,我试图探索河流距离与浓度之间的关系。

#This is not working for a nonlinear regression
ggplot(attenuation, aes(x = km, y = edna))+ 
geom_point() + 
stat_smooth(method = 'nls', formula = 'y~a*x^b', method.args=list (start = 
list(a = 1,b=1), se=FALSE))
Run Code Online (Sandbox Code Playgroud)

当我在以上计算中为nls运行代码时,我从r得到以下错误 …

r ggplot2

3
推荐指数
1
解决办法
618
查看次数

标签 统计

ggplot2 ×1

r ×1