Search code examples
rparametersnls

Joint estimation of parameters from two NLS-regressions


First of all, I am new to the board so excuse me if I am not writing this post in the most optimal way.

That aside, I am trying to run some models on optimal entry timing for successive product/service generations. The models are defined as follows: Models, where F(t) is: F(t), S1 is the cumulative sales of the first product generation, S2 is the cumulative sales of the second product generation, and Tau2 is the introduction timing of the second product generation. M1, M2, q_g and p_q are the parameters that need to be estimated.

In literature on the subject, it is assumed that q_g and p_g are the same across product generations meaning that q_g and p_g should be the same in the model for S1 and S2. This is where I have run into troubles.

So far, I have been able to estimate q_g and p_g individually for each generation by using nls. Please see below:

S1.cum.func <- nls(S1.cum ~ M1.cum * 
           ((1-exp(-(P.cum+Q.cum)*T))/((Q.cum/P.cum)*exp(-(P.cum+Q.cum)*T)+1)) #F1
          * ifelse(T2>0,(1-((1-exp(-(P.cum+Q.cum)*T2))/((Q.cum/P.cum)*exp(-(P.cum+Q.cum)*T2)+1))),One.vec)
          ,start=c(list(M1.cum=sum(S1.cum),P.cum=0.001,Q.cum=0.5))) #Start values 

S2.cum.func <- nls(S2.cum.new ~ (M2.cum + M1.cum*
                ((1-exp(-(P.cum2+Q.cum2)*T.new))/((Q.cum2/P.cum2)*exp(-(P.cum2+Q.cum2)*T.new)+1))) #F1(t)
               *((1-exp(-(P.cum2+Q.cum2)*T2.new))/((Q.cum2/P.cum2)*exp(-(P.cum2+Q.cum2)*T2.new)+1)) #F2(t-Tau2)
               ,start=c(list(M2.cum=1223000,P.cum2=0.001,Q.cum2=0.5)))

My question is - is there any way to run the regressions on S1 and S2 simultaneously so that a single set of the estimated parameters of q_g and p_q will describe both of the dependent variables as much as possible?

Thank you very much.


Solution

  • Here is an example where we run fo1 and fo2 separately and then combine them using separate a1 and a2 and common b. Next time please provide a complete example including all inputs so one can reproduce it using copy and paste.

    set.seed(123)
    
    # Separate nls runs
    
    x1 <- 1:10
    y1 <- 1 + 2 * x1 + rnorm(10)
    fo1 <- y1 ~ a1 + b1 * x1
    nls(fo1, start = list(a1 = 0, b1 = 0))
    
    x2 <- 11:20
    y2 <- 4 * 2 * x2 * rnorm(10)   
    fo2 <- y2 ~ a2 + b2 * x2       
    nls(fo2, start = list(a2 = 0, b2 = 0))
    
    # combined nls run with different a's and common b
    
    y12 <- c(y1, y2)
    fo12 <- y12 ~ c(a1 + b * x1, a2 + b * x2)   
    nls(fo12, start = list(a1 = 0, a2 = 0, b = 0))