Reputation: 1152
I would like to plot a logistic trendline through the scatter plot data, however, I do not know how to go on about this. I searched the web and found functions that require 3 parameters, but I don't know how to find these. any help would be greatly appreciated.
The data:
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")
What I'm aiming for is a logistic curve that starts high and ends low, a mirrored "S" if you like, through the scatter plot data.
plot(y~x, data = dummy)
Thanks for any help
Upvotes: 3
Views: 7046
Reputation: 4370
Package drc
(for dose response curves) may be helpful.
You can estimate logistic curves for continuous data with 3 or 4 parameters.The function automatically find nice starting values for the optimisation alorithm (in contrast with nls
for example). It has also easy plotting methods.
Here is an example with 3 parameters (argument fct = L.3()
). The fourth parameter is the lower asymptote and is fixed to be 0. With a four parameters model the lower asymptote is estimated.
> 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")
>
Upvotes: 4