Qqnorm and qqplot

Is there an equivalent to R qqnorm and qqplot functions in some julia package?

There’s a gist here for how to do it with Gadfly https://gist.github.com/kleinschmidt/7ce8cec988a84ce73ba2

It would be fairly easy to make a recipe for this for StatPlots as well - we should definitely have that.

This should work with Plots:


using Distributions, RecipesBase

@recipe function f(h::QQPair)
    seriestype --> :scatter
    h.qx, h.qy
end

@userplot QQPlot
@recipe f(h::QQPlot) = qqbuild(h.args[1], h.args[2])
    
@userplot QQNorm
@recipe f(h::QQNorm) = qqbuild(Normal(), h.args[1])

Use like this:

x = rand(Normal(), 100)
y = rand(Cauchy(), 100)

using Plots
qqplot(x,y)
qqnorm(y)
1 Like

And now there’s a PR on StatPlots:
https://github.com/JuliaPlots/StatPlots.jl/pull/99
@harven there’s a request for comment on the pull request, if you like.

2 Likes

That’s great, thank you! I will have a look at the RFC soon.

What’s the current status? How can we use it?

The package StatsPlots has the qq plot function available.

3 Likes

Possibly so:

# Estimate distribution parameters:
mw = mean(fix_Acid)
StdAbw = std(fix_Acid)
# Create QQ plot:
qqplot(Normal(mw, StdAbw), fix_Acid, title = "QQ-Plot gebundene Säuren", ylabel = "Gehalt geb. Säuren")

Manual way with Plots:

using Distributions, Plots
function myqqplot(obs,F⁰,title)
    nobs=length(obs)
    sort!(obs)
    quantiles⁰ = [quantile(F⁰,i/nobs) for i in 1:nobs]
    # Note that only n-1 points may be plotted, as quantile(F⁰,1) may be inf
    plot(quantiles⁰, obs, seriestype=:scatter, xlabel="Theoretical Quantiles", ylabel = "Sample Quantiles", title=title, label="" )
    plot!(obs,obs,label="")
end
obs = rand(Normal(0,1),1000)
F⁰=Normal(0,1)
myqqplot(obs,F⁰,"Normal QQ-plot ")

qqplot

1 Like

And an updated link for Gadfly.

This is inbuilt in StatsPlots for more than a year: https://github.com/JuliaPlots/StatsPlots.jl#quantile-quantile-plots

2 Likes