I would like to fit multiple curves at once, and compare them statistically, in terms of their 3 estimated parameters – asymptote, slope and x0. Here is an idealized image of the data to be modeled:
Most searchable pages turn up methods to fit a single curve, as seen here: http://kyrcha.info/2012/07/08/tutorials-fitting-a-sigmoid-function-in-r/ and here http://rstudio-pubs-static.s3.amazonaws.com/7812_5327615eb0044cf29420b955ddaa6173.html
In my case, I would like to test (statistically) the effect of changing variable levels on the three parameters of the sigmoid. That is, when I’m fitting this model:
model <- nls(y ~ asym / (1 + exp( -slope * (x – x0) ) ), start = c(…), data = my_data)
I would like to add interactions of two factors (say, “factorA”, and “factorB”) with each of the asym, slope and x0 terms, the way we can do with lm()
or glm()
, as in the following:
model_int <- nls(y ~ asym*factorA / (1 + exp( -(slope*factorA) * (x – (x0*factorA) ) ), start = c(…), data = my_data)
That way, I can see if those three parameters are statistically different across the different levels of factorA (and potentially multiple other factors, as you can see from the image). For example, we can see that "Condition" has an effect on the asymptote of the curves.
I have done this previously with dummy coding each level of each interacting variable, but that is not a way to directly test these variables, and is rather verbose as models go. It looks like this:
model_dummy <- nls(y ~ (asym+ asym.L1 * is.L1 + asym.l2*is.L2) /
(1 + exp( -slope * (x – (x0 + x0.L1 * is.L1 + x0.L2 * is.L2) ) ) ),
start = c(…), data = my_data)
As you might guess, this method has obvious drawbacks in terms of tidyness and lack of interpretability.
Does anybody know how to fit a set of sigmoids where the parameters interact with variables in the data set to produce curves of slightly different shapes?