I have a response variable y ranging from 0 to 7. The data nicely show a S-shaped curve and I would like to fit a logistic growth model. The potentially explanatory variables are time t (continuous) and Condition C (categorical, 3 levels). The data are from a designed experiment, therefore I have the random effect block B (categorical, 5 levels). As the same spots were measured more than once, I group the Blocks in the time steps (t|B) and I include the interaction between Block and Condition as a further random effect (t|B:C).

As I do not have binomial data, my approach would be to transform the response variable y with the limit K = 7:

y' = log(K/y - 1) = a + bx

which then can be modeled linearly in the form:

model <- glmer(P ~ t*C + (t|B) + (t|B:C), data=data)

and can then (hopefully) be reduced using anova(model0, model1), etc.

My problem now is that for P=0 K/P is not defined and for P=7 log(0) is of course also not defined. I cannot set K just a little big higher than 7, since the value of the log would decrease to very negative values. I could set my values for P from 1-8 instead of 0-7 but I guess values of the logistic regression will always be between 0 and K.

Is there another way to fit a logistic model to my data?

EDIT (sorry, not allowed to comment):

The goal: My dependent variable y evolves over time. I want to see differences between conditions C.

To fit a nls model I imagine it should somehow look like this:

model.nls <- nls(y ~ K / (1 + exp(-(A - b*t))), 
     start=startlist, data=data, trace=T)

Do I have to fit a separate model for each level of my condition C? How do I test for differences between conditions?

And how do I include my random effects (with grouping)?


closed as off-topic by mkt, Michael Chernick, Frans Rodenburg, Robert Long, Peter Flom Jul 19 at 12:07

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – Michael Chernick, Peter Flom
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ I don't think you should call this logistic regression. Can't you use nlme with a logistic function? What is your actual goal in fitting the model? $\endgroup$ – Roland Mar 16 '17 at 7:09
  • 1
    $\begingroup$ You can use nlme from package nlme to fit a non-linear mixed effects model. $\endgroup$ – Roland Mar 16 '17 at 12:17
  • $\begingroup$ So then I think I should fit this model: 'model <- nlme(model = y ~ 7 / (1 + A * exp(b*(t))), fixed = A + b ~ C,random = A + b ~ t|B,start = c(1,-2), data=data)'. This results in the error message 'Error in contr.treatment(n = 0L) : not enough degrees of freedom to define contrasts'. B has 5 levels (4df), C has 3 levels (2df) and t is continuous, y as well so I don't understand the error message. Can you help? $\endgroup$ – mela Mar 17 '17 at 8:21

This is not logistic regression, but nonlinear regression with a logistic growth function. Since you also want mixed effects, it is a nlme (nonlinear mixed effects) model. It can be fit with for instance the nlmer function from the R package lme4. Some code (untried since you didn't post data)

startvec <- with(yourdf, c(K=max(y), xmid=mean(t), scal=sd(t))) # not sure this is best start values
mod.nlmer <- nlmer( y ~ SSlogis(t, K, xmid, scal) ~ (t|B) + (t|B:C), data=yourdf, start=startvec)

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