r通过散点图拟合逻辑曲线

时间:2017-04-22 17:52:45

标签: r plot

我想通过散点图数据绘制逻辑趋势线,但是,我不知道如何继续这个。我在网上搜索并找到了需要3个参数的函数,但我不知道如何找到它们。任何帮助将不胜感激。

数据:

    x          y
1    0 36.4161850
2    0 94.2196532
3    0 94.7976879
4    0 98.2658960
5    0 97.1098266
6  250 40.4624277
7  250 41.0404624
8  250 23.6994220
9  250 48.5549133
10 250 61.2716763
11 500  5.7803468
12 500  3.4682081
13 500  0.5780347
14 500  2.8901734
15 500  0.0000000
16 750  0.0000000
17 750  0.0000000
18 750  0.0000000
19 750  0.0000000
20 750  0.0000000

dummy <- structure(list(x = c("0", "0", "0", "0", "0", "250", "250", "250", 
"250", "250", "500", "500", "500", "500", "500", "750", "750", 
"750", "750", "750"), y = c(36.4161849710983, 94.2196531791908, 
94.7976878612717, 98.2658959537572, 97.1098265895954, 40.4624277456647, 
41.0404624277457, 23.6994219653179, 48.5549132947977, 61.271676300578, 
5.78034682080925, 3.46820809248555, 0.578034682080925, 2.89017341040462, 
0, 0, 0, 0, 0, 0)), reshapeLong = structure(list(varying = structure(list(
    Proportion = c("m0.perc", "m250.perc", "m500.perc", "m750.perc"
    )), .Names = "Proportion", v.names = "Proportion", times = c("m0.perc", 
"m250.perc", "m500.perc", "m750.perc")), v.names = "Proportion", 
    idvar = "id", timevar = "Distance"), .Names = c("varying", 
"v.names", "idvar", "timevar")), .Names = c("x", "y"), row.names = c(NA, 
-20L), class = "data.frame")

我的目标是通过散点图数据,从高处开始并结束低的逻辑曲线,如果您愿意,则使用镜像“S”。

plot(y~x, data = dummy)

enter image description here

感谢您的帮助

1 个答案:

答案 0 :(得分:3)

drc(对于剂量反应曲线)可能会有所帮助。

您可以使用3或4个参数估算连续数据的逻辑曲线。函数会自动为优化算法找到很好的起始值(例如,与nls相比)。它也有简单的绘图方法。

以下是3个参数(参数fct = L.3())的示例。第四个参数是较低的渐近线,固定为0.使用四个参数模型估计下渐近线。

> dummy$x <- as.numeric(dummy$x)
> 
> library("drc")
> mL <- drm(y ~ x, data = dummy, fct = L.3(), type = "continuous")
> summary(mL)

Model fitted: Logistic (ED50 as parameter) with lower limit fixed at 0 (3 parms)

Parameter estimates:

                Estimate Std. Error    t-value p-value
b:(Intercept)   0.013938   0.010315   1.351208  0.1943
d:(Intercept)  86.789553  10.417186   8.331382  0.0000
e:(Intercept) 248.714704  30.029077   8.282463  0.0000

Residual standard error:

 14.61229 (17 degrees of freedom)

> plot(mL, type = "all")
> 

enter image description here