我想通過散點圖數據繪製邏輯趨勢線,但是,我不知道該如何繼續。我搜索了網絡,發現需要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)
感謝所有幫助
從看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
感謝您的回覆。但是,你的答案令我感到困惑。第一部分確實繪製了一個圖表,但它並沒有覆蓋這個散點圖上。你的答案的第二部分適合模型,但不適合任何東西? – FlyingDutch
你寫道你想要擬合曲線,但需要估計參數。上面評論中的非線性模型估計這些。初始函數f和plot用於查找nlsLM函數的啓動參數。要做最後的情節,你可以在模型上使用預測,類似於你做線性迴歸時擬合線的方式。 – user2957945