NLS Regression in GGPlot2, Plotting y=Ax^b Trendline Error

冷暖自知 提交于 2019-12-11 16:18:47

问题


I'm attempting to fit a basic power trendline on a set of 3 data point, as you could do in Excel to mimic the y = Ax^b function. I have a very simple data set loaded into LCurve.data as follows:

MDPT = {4, 10.9, 51.6}

AUC = {287069.4, 272986.0, 172426.1}

fm0 <- nls(log(LCurve.data$AUC) ~ log(a) + b * log(LCurve.data$MDPT), data = LCurve.data, start = list (a = 1, b =1))
  ggplot(LCurve.data, aes(x=MDPT, y = AUC)) + geom_line() +
    geom_point() +
    stat_smooth(method = 'nls', formula = y ~ a * x ^ b, method.args = list(
      start=c(a = coef(fm0)[1], b = coef (fm0)[2]))) 

For some reason this code produces the following error.

Warning: Computation failed in stat_smooth(): singular gradient matrix at initial parameter estimates

The fm0 array has the correct values in the "a" and "b" fields, or coef(fm0)[1] and [2] respectively. I confirmed that with a print of the variable.

I cannot figure out why I am unable to graph the NLS trendline in stat_smooth though. Any ideas? I've been googling for almost 2 hours now and keep running into dead ends. Thanks!

来源:https://stackoverflow.com/questions/51864690/nls-regression-in-ggplot2-plotting-y-axb-trendline-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!