Skip to content
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

How does one put trendlines with confidence intervals on plots? #340

Closed
mkborregaard opened this issue Jun 17, 2016 · 14 comments
Closed

How does one put trendlines with confidence intervals on plots? #340

mkborregaard opened this issue Jun 17, 2016 · 14 comments

Comments

@mkborregaard
Copy link
Member

Hi,
I cannot seem to find in the documentation how one would put trendlines/smoothers in plots. In theory it might be possible to pass a fit object from a GLM with a recipe, but has it been implemented? Also, it would be even more awesome if it could put confidence intervals (e.g. as a grey/coloured box like ggplot2 in R does) automatically on the plot.

Thanks!

@tbreloff
Copy link
Member

'smooth = true' right now should give you a linear regression line.
Non-linear smoothing and confidence intervals are certainly possible to be
part of the smooth attribute... I'm open to suggestions as to what the call
should look like.

On Friday, June 17, 2016, mkborregaard [email protected] wrote:

Hi,
I cannot seem to find in the documentation how one would put
trendlines/smoothers in plots. In theory it might be possible to pass a fit
object from a GLM with a recipe, but has it been implemented? Also, it
would be even more awesome if it could put confidence intervals (e.g. as a
grey/coloured box like ggplot2 in R does) automatically on the plot.

Thanks!


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#340, or mute the thread
https://github.com/notifications/unsubscribe/AA492pYQDD5ChSLA-khpNeFAYf-ZE-7Rks5qMmdNgaJpZM4I4LeN
.

@mkborregaard
Copy link
Member Author

Awesome, I will give that a think. What about smooth being an object, initialised with Smooth() that could have a formula kwarg or accept a fitted object from e.g. a glm - confidence intervals could be set by a kwarg too. This is not too dissimilar to how ggplot2 in R does it: http://docs.ggplot2.org/0.9.3.1/stat_smooth.html

@mkborregaard
Copy link
Member Author

What I mean is, maybe a smoother should be just another object type to add to the plot, with the same status as a line or points. And that smoother could be defined in different ways (formulas, a fit object, or a default formula), which would make it intuitive and fit well with the philosophy of Plots (I think).

@ChrisRackauckas
Copy link
Member

To fit within the philosophy of Plots, whoever has smoother packages should just make a type recipe for the smooth data type, and a series recipe with essentially just makes their type from the input data and plots it.

Here are some candidate packages I could find:

Loess.jl
KernSmooth.jl
SmoothingKernals.jl
Dierckx.jl
GLM.jl

Should open up issues and suggest a type recipe (with a link pointing to the ecosystem page to show what that would entail).

@mkborregaard
Copy link
Member Author

I see the logic there. Still, I would find it convenient if Plots provided trendlines out of the box, while still having the possibility of using objects from smoother packages via a plot recipe. (Note - using those objects to plot a smoother is perhaps tricky, i.e. it is a requirement for most plot types that the object has a single dependent and a single independent variable.)

It would really be convenient with an in-Plots version of a smoother. I think the interface could work nicely and intuitively with a magic argument smooth that set smoother-specific variables, e.g. the color and width of the line and confidence intervals, the formula to use etc. The downside is that this requires Plots to include functions for doing the smoother. Gadfly uses Loess.jl, but IMHO a linear model is a better default.

@ChrisRackauckas
Copy link
Member

Someone could gather a bunch of series recipes for this in a SmoothPlots package, kind of like what Tom has going on for StatPlots

@Evizero
Copy link
Member

Evizero commented Aug 10, 2016

why not use the StatPlots package as a home for this?

@ChrisRackauckas
Copy link
Member

Yeah, that's probably a better idea.

@ChrisRackauckas
Copy link
Member

Well, depending on what functions are used it could add more dependencies. How lean should StatPlots be?

@mkborregaard
Copy link
Member Author

mkborregaard commented Aug 10, 2016

I agree - this would work well as part of the StatPlots package. I hope that shouldn't be too lean - would be nice with a powerful package for statistical plots.

@tbreloff
Copy link
Member

@ChrisRackauckas reminded me of this issue. You can now plot objects from the KernelDensity package (using StatPlots). This doesn't get you all the way of nonlinear smoothers built in to Plots. I'm open to API ideas that are loaded when StatPlots is loaded, however I don't plan on offering nonlinear smoothers in core Plots.

@mkborregaard
Copy link
Member Author

mkborregaard commented Aug 11, 2016

But what about basic linear models (including polynomials)? I find that is used a lot more than moving average smoothers for most applications. I know you have single-order linear models implemented with smooth=true, so could that functionality be expanded, e.g. en StatPlots?

@tbreloff
Copy link
Member

I could see big expansion through StatPlots... just not in Plots. Like I said, I could use help in design. Give me some commands that you wish existed, along with desired output, and we can try to make it happen.

@mkborregaard
Copy link
Member Author

As agreed here, the way is to go through StatsPlots. E.g. JuliaPlots/StatsPlots.jl#293

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants