【问题标题】:qqplot + stat_smooth errorqqplot + stat_smooth 错误
【发布时间】:2018-07-15 16:09:21
【问题描述】:

我正在尝试绘制我的值并使用 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 

【问题讨论】:

  • 如果您查看原始数据的散点图,您会看到 avg 1000 的两个数据点则不然似乎与其余数据处于平滑曲线上。验证这两个数据点的值可能值得您花时间。

标签: r ggplot2 curve-fitting nls


【解决方案1】:

您需要在公式中调整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)

【讨论】:

  • 谢谢!现在它起作用了!现在我真的为那个愚蠢的数学错误感到尴尬。
  • 不用担心。您可以通过单击答案框左侧的Tick 符号来接受答案,以便对未来的用户有所帮助。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-05
  • 2017-12-03
相关资源
最近更新 更多