2

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

enter image description here

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:

enter image description here

So, Friends, please help me to fit the logistic regression model like the one in the first picture.

4
  • 1
    You data sample gives percentage survival by time. Do you have the underlying data on the individuals that your summary data were derived from? If so, you should model those data using an appropriate survival model. The survival model will give you a survival curve that you can plot.
    – eipi10
    Commented Jun 16, 2017 at 18:58
  • Might be best to think about how to model your data before plotting it; are you sure you should be using logistic regression? One possible alternative, is to use the logistic function, where parameters are estimated using nls. So change the smooth to 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)
    – user20650
    Commented Jun 16, 2017 at 21:03
  • Dear Friend, thank you very much for the answer. Yes data from each time point is the mean of two replication. I have the underlying data. But I want to use the logistic function, so I will try to use the code hereby and get back to you, if i need any help. So kind of you. Thanks a lot
    – Prasad
    Commented Jun 17, 2017 at 11:05
  • Dear stackoverflow.com/users/2250190/user20650, your solution to my answer was very helpful. Thank you.
    – Prasad
    Commented Jun 20, 2017 at 8:53

1 Answer 1

1

Do you want to fit an actual model, or do you want to produce a curved line like in the example image? If it's the latter, you could use "loess", a piecewise linear model, in the geom_smooth() argument.

1
  • 1
    Thanks for your answer. I used geom_smooth(), but I dont want the line fitted with 'loess'. I want to fit a actual model.
    – Prasad
    Commented Jun 17, 2017 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.