r - qqplot + stat_smooth 错误

标签 r ggplot2 curve-fitting nls

我正在尝试绘制我的值并使用 nls 模型将它们与曲线拟合。但是我收到一条错误消息,指出我的变量没有起始值。

conc <- c(1.83, 3.66, 7.32, 14.65, 29.30, 58.59, 117.19, 468.75, 937.5, 1875, 3750)  
avg <- c(0.02, 0.03, 0.05, 0.09, 0.23, 0.40, 0.60, 0.79, 0.98, 0.82, 1)

DataSet <- data.frame(conc, avg)

ggplot(DataSet, aes(x = conc, y = avg)) + 
  geom_point() +
  scale_x_log10() + 
  stat_smooth(aes(x=conc, y = avg), method = "nls", 
              formula = "avg~Emax*(conc^Hill)/((EC50^Hill)+(conc^Hill))",
              method.args=list(start=c(Emax = 1, EC50 = 100, Hill = 2)),
              se = FALSE)

# Warning message:
# Computation failed in `stat_smooth()`:
# parameters without starting value in 'data': avg, conc 

最佳答案

您需要调整公式中的 x,因为 scale_x_log10() 已用于轴。因此 log10 的倒数(例如 ^10)应该用于公式中的 x

解决方案如下:

library(ggplot2)

ggplot(DataSet, aes(x = conc, y = avg)) + 
  geom_point() +
  scale_x_log10() +
  stat_smooth(method = "nls", 
              formula = y~Emax*((10^x)^Hill)/((EC50^Hill)+((10^x)^Hill)),
              method.args=list(start=c(Emax = 1, EC50 = 100, Hill = 2)),
              se = FALSE)

enter image description here

关于r - qqplot + stat_smooth 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51350033/

相关文章:

r - 从程序加载数据

删除整个数据框中的句点/点

r - sweave 和 ggplot2 : no pdfs generated at all

python - scipy.optimize.curvefit() - 数组不能包含 infs 或 NaNs

r - 如何使用 sliderInput 值来选择列并使用它来更改 map R?

r - 使用 ggplot 绘制时间标签覆盖率

r - ggplot2 scale_color_manual 显示图例中的所有值

python - 将闭合曲线拟合到一组点

MATLAB 曲线拟合,指数与线性

r - 更改 R 中大型矩阵中的值 block