dpritchard / frair

Tools for Functional Response Analysis
8 stars 3 forks source link

A residuals method for objects of `frfit` #41

Open dpritchard opened 6 years ago

dpritchard commented 6 years ago

At their core, objects produced by frair_fit are named lists (of class ‘frfit’ and ‘list’). It sounds like you want to operate on the underlying bbmle object, in which case you should try:

residuals(frair_fit$fit) 

This is a general rule of thumb if you want to operate directly on the underlying model.

This specific example (extracting residuals) might not work because FRAIR does not fit models using the formula interface, which BBMLE (seems to) require for it’s residuals method. This is fair enough (from BBMLE’s perspective) as it has no knowledge of the underlying objective function (it is only ever passed the negative log-likihood functions to optimise).

We could develop a residuals method for a ‘frfit’ object… In the mean time you might need to DIY your own approach. This shouldn’t be hard, here is an example:

data(gammarus)
fit <- frair_fit(eaten~density, data=gammarus, 
                response='rogersII', start=list(a = 1.2, h = 0.015), 
                fixed=list(T=40/24))
predictions <- rogersII(X = gammarus$density, as.list(coef(fit)))
resids <- gammarus$eaten-predictions