使用 ggplot2 拟合带有 Weibull 曲线的散点图
fit a scatter plot with Weibull curve with ggplot2
我不确定这是否是重复的问题。但我真的希望能从这里得到帮助。
我想绘制如下附件中的图形,拟合 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 but I don't know what the initial values are. It seems this 是可行的,但是“127”在以下方面是什么意思:
nls(y~127*dweibull(x,shape,scale), start=c(shape=3,scale=100))
?我怎样才能从我的数据中得到这个常量?
在那道题中,127
是y
的总和。但在一些回复中,它说该方法存在一些问题并提供了一种权宜之计。有两种方式,SSweibull
和dweibull
。
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)
我不确定这是否是重复的问题。但我真的希望能从这里得到帮助。
我想绘制如下附件中的图形,拟合 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 but I don't know what the initial values are. It seems this 是可行的,但是“127”在以下方面是什么意思:
nls(y~127*dweibull(x,shape,scale), start=c(shape=3,scale=100))
?我怎样才能从我的数据中得到这个常量?
在那道题中,127
是y
的总和。但在一些回复中,它说该方法存在一些问题并提供了一种权宜之计。有两种方式,SSweibull
和dweibull
。
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)