I want a plot a similar graph copied from the publication. The graph is % Survival (on y-axis) and time (on x-axis)
My Objective Graph
Here is my data and script:
dat <- read.table(text= "G Time Survival
1 0 93
1 3 90
1 9 2
1 15 1
1 20 0
1 25 0
1 30 1
1 35 0
1 40 0
1 45 0
1 55 0
1 65 0
2 0 100
2 3 100
2 9 100
2 15 98
2 20 99
2 25 98
2 30 97
2 35 97
2 40 95
2 45 76
2 55 72
2 65 66
3 0 97
3 3 94
3 9 80
3 15 26
3 20 20
3 25 0
3 30 0
3 35 0
3 40 1
3 45 0
3 55 0
3 65 0
4 0 94
4 3 81
4 9 35
4 15 19
4 20 5
4 25 2
4 30 0
4 35 0
4 40 0
4 45 1
4 55 0
4 65 0
5 0 96
5 3 96
5 9 97
5 15 96
5 20 93
5 25 95
5 30 89
5 35 99
5 40 92
5 45 87
5 55 63
5 65 63
6 0 95
6 3 94
6 9 99
6 15 92
6 20 81
6 25 80
6 30 64
6 35 41
6 40 48
6 45 12
6 55 22
6 65 19
7 0 97
7 3 96
7 9 92
7 15 92
7 20 94
7 25 79
7 30 74
7 35 56
7 40 50
7 45 20
7 55 2
7 65 0
8 0 95
8 3 84
8 9 13
8 15 10
8 20 3
8 25 6
8 30 7
8 35 4
8 40 0
8 45 0
8 55 0
8 65 0", header = TRUE)
attach(dat)
library(ggplot2)
ggplot(data=dat) +
geom_point(mapping=aes(x=Time,y=Survival)) +
facet_wrap(~ G, nrow=2)
ggplot(data=dat) +
geom_point(mapping=aes(x=Time,y=Survival)) +
geom_smooth(mapping = aes(x=Time,y=Survival),method="glm", family = binomial, se = FALSE, fill=NA) +
facet_wrap(~ G, nrow=2)
This results in the following graph:
So, Friends, please help me to fit the logistic regression model like the one in the first picture.
geom_smooth(method="nls", formula = y ~ 100 / (1 + exp(-a* (x - b))), se = FALSE, fill=NA, method.args=list(start = c(a=-0.05, b=50)))
. To see the parameters you can model outside of the figure:library(nlme) ; m = nlsList(Survival ~ 100 / (1 + exp(-a* (Time - b)))|G, data = dat, start = c(a=-0.05, b=50), na.action=na.omit) ; coef(m)