From: michael partensky on
Hi.
I wonder if anybody knows a function similar to qqnorm(data) from *R*,
producing a normal scores plot, or some related tools in M. for testing
normality of data?

Thanks
Michael Partenskii


From: Ray Koopman on
On Feb 2, 12:28 am, michael partensky <parten...(a)gmail.com> wrote:
> Hi.
> I wonder if anybody knows a function similar to qqnorm(data) from *R*,
> producing a normal scores plot, or some related tools in M. for testing
> normality of data?
>
> Thanks
> Michael Partenskii

qqnorm[y_] := Block[
{n = Length@y, m = Mean@y, s = StandardDeviation@y, x},
x = InverseErf[Range[1-n,n-1,2]/n]*Sqrt[2.];
ListPlot[Transpose@{x,Sort@y},
PlotRange->All, Frame->True, Axes->None, AspectRatio->1,
Prolog->Line[{{x[[1]],x[[1]]*s+m},{x[[-1]],x[[-1]]*s+m}}],
FrameLabel->{"Theoretical Standard Normal Quantiles",
"Observed Quantiles"}]]

From: michael partensky on
Thanks, Ray.
Michael Partenskii

On Tue, Feb 2, 2010 at 6:54 AM, Ray Koopman <koopman(a)sfu.ca> wrote:

> On Feb 2, 12:28 am, michael partensky <parten...(a)gmail.com> wrote:
> > Hi.
> > I wonder if anybody knows a function similar to qqnorm(data) from *R*,
> > producing a normal scores plot, or some related tools in M. for testing
> > normality of data?
> >
> > Thanks
> > Michael Partenskii
>
> qqnorm[y_] := Block[
> {n = Length@y, m = Mean@y, s = StandardDeviation@y, x},
> x = InverseErf[Range[1-n,n-1,2]/n]*Sqrt[2.];
> ListPlot[Transpose@{x,Sort@y},
> PlotRange->All, Frame->True, Axes->None, AspectRatio->1,
> Prolog->Line[{{x[[1]],x[[1]]*s+m},{x[[-1]],x[[-1]]*s+m}}],
> FrameLabel->{"Theoretical Standard Normal Quantiles",
> "Observed Quantiles"}]]
>
>


From: Ray Koopman on
Here, prompted by off-line conversations, is an improved version of
qqnorm:

qqnorm2[data_] := Block[{n, y,y1,y2,y3, x,x1,x2,x3, b,a},
n = Length(a)data; y = Sort(a)data; {y1,y2,y3} = Quartiles@y;
x = InverseErf[Range[1-n,n-1,2]/(n+.33(n-1.25)^-.1)]*Sqrt[2.];
{x1,x2,x3} = Quartiles@x; b = (y3-y1)/(x3-x1); a = y1 - b*x1;
ListPlot[Transpose@{x,y}, PlotRange->All, Frame->True, Axes->None,
AspectRatio->((Last(a)y-First@y)/(y3-y1))/((Last(a)x-First@x)/(x3-x1)),
Prolog->Line[{#,#*b+a}&/@{First@x,Last@x}],
FrameLabel->{"Standard Normal","Observed Data"}]]

The most notable changes are that the reference line is now drawn so
that it passes through the joint first and third quartile points, and
the aspect ratio now varies so that the visual slope of the reference
line is always approximately 1. Also, the normal scores are now a
better approximation of the expected order statstics.

On Feb 2, 3:48 am, Ray Koopman <koop...(a)sfu.ca> wrote:
> On Feb 2, 12:28 am, michael partensky <parten...(a)gmail.com> wrote:
>> Hi.
>> I wonder if anybody knows a function similar to qqnorm(data) from
>> *R*, producing a normal scores plot, or some related tools in M.
>> for testing normality of data?
>>
>> Thanks
>> Michael Partenskii
>
> qqnorm[y_] := Block[
> {n = Length@y, m = Mean@y, s = StandardDeviation@y, x},
> x = InverseErf[Range[1-n,n-1,2]/n]*Sqrt[2.];
> ListPlot[Transpose@{x,Sort@y},
> PlotRange->All, Frame->True, Axes->None, AspectRatio->1,
> Prolog->Line[{{x[[1]],x[[1]]*s+m},{x[[-1]],x[[-1]]*s+m}}],
> FrameLabel->{"Theoretical Standard Normal Quantiles",
> "Observed Quantiles"}]]

From: michael partensky on
Thanks, Ray.
Michael

On Fri, Feb 5, 2010 at 3:24 AM, Ray Koopman <koopman(a)sfu.ca> wrote:

> Here, prompted by off-line conversations, is an improved version of
> qqnorm:
>
> qqnorm2[data_] := Block[{n, y,y1,y2,y3, x,x1,x2,x3, b,a},
> n = Length(a)data; y = Sort(a)data; {y1,y2,y3} = Quartiles@y;
> x = InverseErf[Range[1-n,n-1,2]/(n+.33(n-1.25)^-.1)]*Sqrt[2.];
> {x1,x2,x3} = Quartiles@x; b = (y3-y1)/(x3-x1); a = y1 - b*x1;
> ListPlot[Transpose@{x,y}, PlotRange->All, Frame->True, Axes->None,
> AspectRatio->((Last(a)y-First@y)/(y3-y1))/((Last(a)x-First@x)/(x3-x1)),
> Prolog->Line[{#,#*b+a}&/@{First@x,Last@x}],
> FrameLabel->{"Standard Normal","Observed Data"}]]
>
> The most notable changes are that the reference line is now drawn so
> that it passes through the joint first and third quartile points, and
> the aspect ratio now varies so that the visual slope of the reference
> line is always approximately 1. Also, the normal scores are now a
> better approximation of the expected order statstics.
>
> On Feb 2, 3:48 am, Ray Koopman <koop...(a)sfu.ca> wrote:
> > On Feb 2, 12:28 am, michael partensky <parten...(a)gmail.com> wrote:
> >> Hi.
> >> I wonder if anybody knows a function similar to qqnorm(data) from
> >> *R*, producing a normal scores plot, or some related tools in M.
> >> for testing normality of data?
> >>
> >> Thanks
> >> Michael Partenskii
> >
> > qqnorm[y_] := Block[
> > {n = Length@y, m = Mean@y, s = StandardDeviation@y, x},
> > x = InverseErf[Range[1-n,n-1,2]/n]*Sqrt[2.];
> > ListPlot[Transpose@{x,Sort@y},
> > PlotRange->All, Frame->True, Axes->None, AspectRatio->1,
> > Prolog->Line[{{x[[1]],x[[1]]*s+m},{x[[-1]],x[[-1]]*s+m}}],
> > FrameLabel->{"Theoretical Standard Normal Quantiles",
> > "Observed Quantiles"}]]
>
>