2017-04-22 49 views
1

我想通过散点图数据绘制逻辑趋势线,但是,我不知道该如何继续。我搜索了网络,发现需要3个参数的函数,但我不知道如何找到这些参数。任何帮助将不胜感激。r通过散点图拟合逻辑曲线

数据:

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

感谢所有帮助

+0

从看https://en.wikipedia.org/wiki/Logistic_function,似乎这将是一个良好的开端。 (函数(L,k,x0,x)L /(1 + exp(-k *(x-x0)))的函数来看看函数的适当参数符号/形状。绘图(f(100,-0.01,300,1:600),type =“l”)'(不是非常结构化的方法!)。尝试拟合'minpack.lm :: nlsLM(y_L /(1 + exp(-k *(x_x0))),start_c(L = 100,k = -0.1,x0 = 300),data =虚拟)'。 [记得做'dummy $ x < - as.numeric(dummy $ x)',因为它当前是字符] – user2957945

+0

感谢您的回复。但是,你的答案令我感到困惑。第一部分确实绘制了一个图表,但它并没有覆盖这个散点图上。你的答案的第二部分适合模型,但不适合任何东西? – FlyingDutch

+0

你写道你想要拟合曲线,但需要估计参数。上面评论中的非线性模型估计这些。初始函数f和plot用于查找nlsLM函数的启动参数。要做最后的情节,你可以在模型上使用预测,类似于你做线性回归时拟合线的方式。 – user2957945

回答

1

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

+0

这看起来像一个简单的解决方案。但是,为什么x轴会发生变化?它可以像原始轴一样可视化,从0到800米运行? – FlyingDutch

+0

这是因为在生态毒理学中,x轴是产品的剂量并且通常用对数标度表示。所以x的日志比例是默认值。使用它在原始尺度上绘制它:'plot(mL,type =“all”,log ='')'并且查看'?plot.drc'以获得此方法的帮助。 – Gilles