0

I have two functions

funk1 <- (t,a,b,c) { a* exp(-k*t)* b* exp(-c*t) }
funk2 <- (t,a,b,c) { (A*t^k +a)* b* exp(-c*t) }

where, k and A are known.
I am trying to estimate parameters a,b,c by fitting these two functions funk1 & funk2 simultaneously to two different data-sets Y1 & Y2 respectively.

Y1 <- seq(5*10^7, 1*10^7, -2*10^5)
Y2 <- seq(0.01, 0.85, 0.0042)

I am using Optim to fit the models by maximising joint likelihood. But the parameter values I am getting are pretty un-realistic. (I think optimiser wandering in wrong directions and finding local maxima and I can't use a gradient function.)

I wish to use nls() to fit these two functions to respective data-sets, 'simultaneoulsy'. I am not sure how to do it?

Thanks in advance.

VitalSigns
  • 83
  • 2
  • 10
  • You should add more detail about how you are calling the functions in `Optim` and preferably use a **small** example to highlight the error. – Pierre L Aug 18 '16 at 17:30
  • 1
    @PierreLafortune - But I want to use nls() rather than optim. So the question is about nls(). Still, In optim I feed a function which calculates log-likelihood by least-squares method and I asked it to return -log-lik since optim by default minimises the function. I am not getting any error in optim, its just that the values that I get are un-physiological (yes, I am fitting some biological data). I am getting almost a log fold higher estimates than the expected values for one of the parameters. – VitalSigns Aug 18 '16 at 17:43
  • 1
    You haven't provided `k` or `A`. Or the actual expression you used. So if your error is typographical or structural, there is no way someone can help you. I am asking you to add more detail to your question. – Pierre L Aug 18 '16 at 17:46
  • And further to Lafortune's remark: what do you mean by simultaneously? – renato vitolo Aug 18 '16 at 18:36
  • @PierreLafortune Oh sorry for that. k=0.01 and A=1000. I understood what you were saying, but the problem is, I have simplified my functions here, since I just wanted to find if there is a method for fitting 2 datasets to 2 different models sharing all the parameters, simultaneously. I have never used nls() and I am a newbie to R. If you are interested in looking at my original functions and their optimization I can definitely provide you more details. But right now I am interested to know if nls() can be used in my situation. Sorry for any miscommunication. – VitalSigns Aug 19 '16 at 10:19
  • @renatovitolo By simultaneously I mean that finding unique values for parameters that satisfy both the model-fits. Since, my 2 functions share all of their parameters it can be easily done in optim to find their joint-likelihood by feeding product of their SSRs (least sqaure method). But since I havent use nls() before I am not sure how to do that using nls. – VitalSigns Aug 19 '16 at 10:24
  • This is an interesting problem and I now begin to understand what you aim to do. However, your example above is not yet reproducible. So if I get it right, `funk1` and `funk2` are marginal likelihoods, sharing a common 4D parameter `a,b,c,t`, for a joint probability distribution that you wish to fit to 2 datasets. Problem is, I don't see the coordinates of `Y1` and `Y2` in the expressions of `funk1` and `funk2`: where are the datapoints? – renato vitolo Aug 19 '16 at 12:16
  • Wait a second: perhaps `t` is the observation of `Y1` and `Y2` where you evaluate the likelihoods? – renato vitolo Aug 19 '16 at 12:17
  • @renatovitolo yes, t represents time which is an independent variable for observations in Y1 and Y2. Sorry for my clumsiness! I should have explained the problem better... – VitalSigns Aug 19 '16 at 13:56
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/121356/discussion-between-renato-vitolo-and-vitalsigns). – renato vitolo Aug 19 '16 at 14:10
  • @renato vitolo : not cool man! – VitalSigns Aug 20 '16 at 05:12
  • After 1.5 hrs chatting I still haven't got a working reproducible example out of you: not cool indeed. I suggest you carefully reformulate your problem here, making sure that whatever you post works straight away on anybody's PC: see here for instructions http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – renato vitolo Aug 20 '16 at 08:54

0 Answers0