【问题标题】:fit a scatter plot with Weibull curve with ggplot2用 ggplot2 拟合带有 Weibull 曲线的散点图
【发布时间】:2021-12-11 11:03:18
【问题描述】:

我不确定这是否是重复的问题。但我真的希望能从这里得到帮助。

我想绘制如下图所示的图表,拟合 2 参数 Weibull 曲线。 x 轴为days,y 轴为biomaker level,截止值为 0.5。

what i want

这是一个示例数据。

`biomaker level`    days    result
1.5515  81  Positive
0.712   5   Positive
1.831   15  Positive
1.738   30  Positive
1.519   9   Positive
1.2145  21  Positive
2.2085  19  Positive
2.15    18  Positive
2.1845  20  Positive
2.248   18  Positive
2.098   14  Positive
2.2645  36  Positive
2.273   55  Positive
2.213   9   Positive
2.2515  15  Positive
2.245   14  Positive
1.894   68  Positive
2.265   25  Positive
2.2305  25  Positive
1.7955  84  Positive
1.649   85  Positive
1.4635  16  Positive
1.3775  98  Positive
1.008   114 Positive
1.44    35  Positive
0.1845  2   Negative

我试过这个solution 但我不知道初始值是什么。似乎this 是可能的,但是“127”是什么意思: nls(y~127*dweibull(x,shape,scale), start=c(shape=3,scale=100))?如何从我的数据中获取此常量?

【问题讨论】:

    标签: r ggplot2 weibull


    【解决方案1】:

    在那个问题中,127y 的总和。但在一些回复中,它说这种方法存在一些问题并提供了一种权宜之计。有两种方式,SSweibulldweibull

    1。 SSweibull

    df1 <- df1 %>% arrange(days)
    x <- df1$days
    y <- df1$biomaker.level
    yy <- cumsum(y) #max(yy) = 46.0095 ~ 46
    nls(yy ~ SSweibull(x, Asym, Drop, lrc, pwr))
    
    Nonlinear regression model
      model: yy ~ SSweibull(x, Asym, Drop, lrc, pwr)
       data: parent.frame()
      Asym   Drop    lrc    pwr 
    41.698 44.194 -5.675  1.783 
     residual sum-of-squares: 154.5
    
    Number of iterations to convergence: 10 
    Achieved convergence tolerance: 8.941e-06
    
    plot(yy ~ x)
    curve(SSweibull(x, 41.698, 44.194, -5.675, 1.783), add = TRUE)
    

    2。 dweibull

    nls(y ~ 46 * dweibull(x, shape, scale), start = c(shape = 3, scale = 20))
    
    Nonlinear regression model
      model: y ~ 46 * dweibull(x, shape, scale)
       data: parent.frame()
     shape  scale 
     2.375 23.378 
     residual sum-of-squares: 27.93
    
    Number of iterations to convergence: 9 
    Achieved convergence tolerance: 4.33e-06
    
    plot(y ~ x)
    curve(46 * dweibull(x, 2.375, 23.378), add = TRUE)
    

    【讨论】:

    • 我可以再问几个问题吗? 1. 为什么先执行 nls 而不是 dweibull 来生成形状和比例? 2. 46,shape=3,scale=20从何而来?
    • @NgWingKwan 当您将nls 的结果与绘制图形的代码进行比较时,会预先执行nls 以获取参数。
    • 如果我的真实 df 有 ~4k 记录,它会“46”改变吗?
    • @NgWingKwan 46 在我的代码中和 127 在其他代码中,它是 y 的总和。
    • 如何用 dweibull 确定 nls 中的“start = c(shape = 3, scale = 20)”?
    猜你喜欢
    • 1970-01-01
    • 2019-11-06
    • 1970-01-01
    • 2012-11-25
    • 1970-01-01
    • 1970-01-01
    • 2016-02-12
    • 1970-01-01
    • 2019-02-16
    相关资源
    最近更新 更多