'How can I specify an interaction term in a non linear regression using the SSasymp function in R?

How can I specify an interaction term -in lm as x:z- in a non linear regression using the SSasymp function? And random effects -in lm as (1|z)-?

This is my model with one predictor only:

library(nlme)
nlme(y ~ SSasymp(x, Asym, R0, lrc),
        data = na.omit(df),
        fixed = Asym + R0 + lrc ~ 1,
        random = Asym ~ 1|z,
        start = c(Asym = 1.1, R0 = 2.0, lrc = 4.9))

I understand that in the model above I have x as a fixed effect, and random intercept for z.

However, how do I specify an interaction between x and z? That is, the equivalent of what in lm we would do by x*z or by x + z + x:z?



Solution 1:[1]

(Not necessarily an answer but seems too long for a comment.)

I'm still not sure this makes sense to me. Let's consider a simplified version of the question. Suppose you wanted to fit an exponential decay model (y ~ a*exp(-b*x), but you wanted to include "an interaction between x and z". This would most naturally be formulated as "a change in the (exponential) slope with respect to x as z changes"; you could write this out as

nls(y ~ a*exp(-b*x),
    params = list(a ~ 1, b ~ z),
    ...)

(or the equivalent for nlme, which would involve fixed = list(a ~ 1, b ~ z), as well as a random= component). Expanding this specification out, this would be equivalent to replacing b by beta0 + beta1*z, or:

y ~ a*exp(-(beta0 + beta1*z)*x)
  ~ a*exp(-beta0*x + beta1*z*x)

In other words, interactions are usually expressed in terms of the effects of one covariate on the effects of another covariate, or variation in effective parameter values with respect to a covariate. If you want to include "an interaction between x and z" in your model, I think you need to be more specific: which of the parameters governing the pattern of y with respect to x varies with z? Most generally, you could write fixed = Asym + R0 + lrc ~ z, which would correspond to a model (ignoring the random effects)

y ~ (Asym1+Asym2*z)+((R01+R02*z)-(Asym1+Asym2*z))*exp(-exp(lrc1+lrc2*z)*input)

In other words, each of the parameters has been replaced by a linear function of z with corresponding linear parameters (foo1 (intercept), foo2 (slope)).

You could also write this out in the full form as given here, but estimation would probably be less efficient (and the formula would be harder to read).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ben Bolker