-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add plot recipe for fit result #180
base: master
Are you sure you want to change the base?
Conversation
We could maybe do this. I'm not sure I understand the prediction part. |
The confidence interval is likely to contain the true mean. The prediction interval is likely to contain any new observation. |
function margin_error(model::Function, x, fit::LsqFitResult, alpha=0.05; purpose=:confidence) | ||
g = p -> ForwardDiff.gradient(p -> model(x, p), fit.param) | ||
c = g(fit.param)' * estimate_covar(fit) * g(fit.param) | ||
if purpose === :prediction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this was in the original formulation on stackexchange, but where does the 1 come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My statistics textbook has a derivation for this, but it's sadly in Swedish. I'll see later today if I can find a good reference. Essentially the difference between prediction and confidence coincidentally comes down to 1 dof.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. You can post the picture of the Swedish text, I'll be able to read it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the derivation in Seber, G.A.F & Wild, C.J 1989: Statistical inference (My textbook only had it for the linear case). My statistics isn't quite strong enough that I could convert this directly to working code, but I think it contains the source of the 1
.
Intuitively, your next value is likely to land in an interval that is the confidence interval plus one "standard deviation" to either side, because that's where it's likely to land given the position of the true mean is inside the confidence interval. I hope this makes sense, otherwise it might be an idea to hold off on this part of the PR.
Yeah, I like it. Just want to understand the prediction part first, I've never used that myself :) |
(might close #139)
Implements a plot recipe for fit results. Uses the delta method (as described here) to form confidence and prediction bands.
My statistics is shaky, it's been a couple of years, so this might be a terrible way to do this. Which is why I'm asking for input before I go through the trouble of writing docs and tests.
Is this desirable?
: