investr icon indicating copy to clipboard operation
investr copied to clipboard

Support nls models with more than 1 predictor variable and use 2nd order instead of 1st order Taylor approx

Open tomwenseleers opened this issue 6 years ago • 4 comments

I was currently fitting nls models with more than 1 predictor variable - basically, a model with reponse written in function of concentration using a smooth approximation of a three-phase linear model (as given here https://math.stackexchange.com/questions/2692572/smooth-approximation-of-three-phased-linear-models/2696609#2696609) but in addition to that I also have three further additively acting covariates in the nls model which I want to control for. Investr right now can't deal with these kinds of models since nls models with >1 predictor variable are not supported. Would you see any possibility by any chance to also support these kinds of models? Can the delta method together with symbolic differentiation not be used for any number of predictor variables (as in https://www.rdocumentation.org/packages/alr3/versions/1.1.12/topics/delta.method ?), and can the inverse predictions not be produced by setting the additional covariates to particular values (e.g. their mean value?) ? I also have weights in my model btw, but I posted this as another feature request...

tomwenseleers avatar Mar 28 '18 10:03 tomwenseleers

Also just noticed this function https://www.rdocumentation.org/packages/propagate/versions/1.0-5/topics/predictNLS which apparently provides confidence and prediction intervals for nls models using a second order Taylor approximation, https://rmazing.wordpress.com/2013/08/26/predictnls-part-2-taylor-approximation-confidence-intervals-for-nls-models/ https://www.google.be/url?sa=t&rct=j&q=&esrc=s&source=web&cd=9&ved=2ahUKEwjH96uj947aAhUOLFAKHYtVBLUQFjAIegQIABBZ&url=http%3A%2F%2Faustralianantarcticdatacentre.github.io%2FGentleR%2F2014-11-13%2Fnls-vb.docx&usg=AOvVaw2YFbQhRn7O0VRjMsOvBxnO and also supports multiple predictors. Would it not be better to use that one also in investr?

tomwenseleers avatar Mar 28 '18 11:03 tomwenseleers

Extending to multiple predictors should be pretty straight forward. I'll try to work on this over the next couple of week and push an update as soon as I can. Rather than relying on an additional package, I would probably just extend the prediction function in investr ot allow for prediction intervals, etc. via the delta method.

bgreenwell avatar Mar 28 '18 13:03 bgreenwell

Cool - many thanks for that! If you would be interested in also supporting 2nd order Taylor approximations as opposed to just 1st order for nls models you could always lift some code from the propagate package, if you would like to avoid extra dependencies...

tomwenseleers avatar Mar 28 '18 13:03 tomwenseleers

I don't see that being an issue, but as a last resort, that is probably what I would do (but, of course, also citing the propogate package as the source of the code)!

bgreenwell avatar Mar 28 '18 13:03 bgreenwell