Home > wafo > wstats > wnormplot.m

# wnormplot

## PURPOSE

Plots data on a Normal distribution paper

## SYNOPSIS

wnormplot(x,nr1,nr2,df);

## DESCRIPTION

```  WNORMPLOT Plots data on a Normal distribution paper

CALL:  wnormplot(x,nr1,nr2,df)

x      = a vector with data, or a matrix with data from
several groups, one group per column.
nr1    = plot parameter;
if 1, estimated lines will be drawn (default).
nr2    = plot parameter;
if 1, percentiles will be drawn (default).
df     = degrees of freedom in the t-distribution.
df = inf    : normal distribution paper will be used (default),
0 < df < inf: approximation of t-distribution will be used.

Example:
R=wnormrnd(0,1,100,2);
wnormplot(R)```

## CROSS-REFERENCE INFORMATION

This function calls:
 figtext Places text in figure window. axis Control axis scaling and appearance. erf Error function. erfinv Inverse error function. error Display message and abort function. hold Hold current graph. ishold Return hold state. mean Average or mean value. num2str Convert number to string. (Fast version) plot Linear plot. set Set object properties. title Graph title. ylabel Y-axis label.
This function is called by:
 Chapter2 % CHAPTER2 Modelling random loads and stochastic waves Chapter3 % CHAPTER3 Demonstrates distributions of wave characteristics Chapter4 % CHAPTER4 contains the commands used in Chapter 4 of the tutorial Chapter5 % CHAPTER5 contains the commands used in Chapter 5 of the tutorial dist2dfit Parameter estimates for DIST2D data. itmkurs_lab1 Script to computer exercises 1

## SOURCE CODE

```001 function wnormplot(x,nr1,nr2,df);
002 % WNORMPLOT Plots data on a Normal distribution paper
003 %
004 % CALL:  wnormplot(x,nr1,nr2,df)
005 %
006 %   x      = a vector with data, or a matrix with data from
007 %            several groups, one group per column.
008 %   nr1    = plot parameter;
009 %            if 1, estimated lines will be drawn (default).
010 %   nr2    = plot parameter;
011 %            if 1, percentiles will be drawn (default).
012 %   df     = degrees of freedom in the t-distribution.
013 %            df = inf    : normal distribution paper will be used (default),
014 %            0 < df < inf: approximation of t-distribution will be used.
015 %
016 % Example:
017 %   R=wnormrnd(0,1,100,2);
018 %   wnormplot(R)
019
020 % Tested on: Matlab 5.3
021 % History:
022 % revised pab 24.10.2000
023 %  - removed tdistr
024 %  - added checks on df and ishold as well as nargchk
026 % Revised by jr 22.12.1999
027
028 error(nargchk(1,4,nargin))
029 if nargin<4|isempty(df),  df=inf;end
030 if (df<=0 | (df~=round(df) & df<inf))
031   error('df must be postive integer')
032 end
033 tdistr=(df<inf);
034
035 if (nargin<3)|isempty(nr2),  nr2=1;end
036 if (nargin<2)|isempty(nr1),  nr1=1;end
037
038 ih = ishold;
039
040 if size(x,1)==1
041   x=x';
042 end
043
044 [n,m]=size(x);
045 x=sort(x);
046 X=((1:n)'-1/2)/n;
047 Y=sqrt(2)*erfinv(2*X-1);
048
049 if tdistr
050   g1=1/4*(Y.^3+Y);
051   g2=1/96*(5*Y.^5+16*Y.^3+3*Y);
052   g3=1/384*(3*Y.^7+19*Y.^5+17*Y.^3-15*Y);
053   g4=1/92160*(79*Y.^9+776*Y.^7+1482*Y.^5-1920*Y.^3-945*Y);
054   Z=Y+g1./df+g2./df^2+g3./df^3+g4./df^4;
055   Y=Z;
056 end
057
058 linregx=Y;
059 SXX=sum((linregx-mean(linregx)).^2);
060 Phi1=0.5*(1+erf(1/sqrt(2)));
061 lambda975=sqrt(2)*erfinv(2*(.975)-1);
062
063 levels=[ .5 .7 .9 .95 .98 .99 .995 .999 .9999];
064 levels=[1-fliplr(levels(2:9)) levels];
065 lev=sqrt(2)*erfinv(2*levels-1);
066
067 data=zeros(2,m);
068 mx=zeros(1,m);
069 sx=zeros(1,m);
070 for i=1:m
071   linregy=x(:,i);
072   SXY=(linregx-mean(linregx))'*(linregy-mean(linregy));
073   b=SXY/SXX;
074   a=mean(linregy)-b*mean(linregx);
075   mx(i)=a;
076   sx(i)=b;
077   data(1,i)=mx(i);
078   data(2,i)=sx(i)^2;
079   plot(x(:,i),Y,'b.','markersize',12);
080   hold on
081   if nr1
082     plot([x(1,i) x(n,i)],[(x(1,i)-mx(i))/sx(i) (x(n,i)-mx(i))/sx(i)],'r--')
083   end
084 end
085
086 span=max(max(x))-min(min(x));
087 xx1=min(min(x))-0.1*span;
088 xx2=max(max(x))+0.1*span;
089
090 axis([xx1 xx2 -4 4])
091 if ~tdistr
092   title('Normal Probability Plot')
093   ylabel('Quantiles of standard normal')
094 else
095   title('Student probability t-plot')
096   ylabel('Quantiles of Student t')
097 end
098
099 if nr2
100   ax=axis;
101   plot([ax(1) ax(2)],[lev; lev],'k');
102   for l=1:length(levels)
103     h=figtext(1.01,lev(l),[num2str(levels(l)*100) '%'],'norm','data');
104     set(h,'FontSize',10,'FontAngle','Italic')
105   end
106 end
107
108 if ~ih, hold off,end
109
110
111
112
113```

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group

Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003