Søren Hauberg wrote:
Hi,
Does anybody know how I can test wether or not some
samples are
normaly distributed? I tried graphical methods, such as
looking at
histograms and qqplots, but I don't trust my own
judgement enough to
use graphical methods.
/Søren
Here is how I did it:
You warp it by the normal curve so that 'normal' data
will produce a streight line.
Then you check how streight your line is with the cor()
function..
A cor=1 is perfect fit.
A cor =.5 is there is a 50% chance it is from a normal
distribution. etc.
The number of data points is also important. etc.
So if you get cor>.9 you can be happy.
## Copyright (C) 2005 doug
##
## This program is free software; you can redistribute it
and/or modify
## it under the terms of the GNU General Public License
as published by
## the Free Software Foundation; either version 2 of the
License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will
be useful,
## but WITHOUT ANY WARRANTY; without even the implied
warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General
Public License
## along with this program; if not, write to the Free
Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston,
MA 02111-1307 USA
## nt(y)
## This is a normality test ie. is the data in y a sample
from a normaly distributed
## population? If this graph is a streight line then it
is.
## Author: Doug Stewart
##
## 2005-02-10 doug
## * Initial revision
function [ ret ] = nt (y)
y1=sort(y);
n=length(y);
for k=1:n
q1(k)=k/(n+1)
end
y3=normal_inv(q1);
## now find the streight line that fits through the curve
[p yf]=polyfit(y3,y1',1);
p
##p(2) is the y crossing and is the sample mean
##p(1) is the slope and is the sample standard deveation
std
w3=p(2)+p(1).*y3;
plot(y3,y1,y3,w3)
## now test how good the fit was
## it should be greater than ? .997
cor(y1,w3)
endfunction