Home > atmlab > randomize > randmvar_add_lognormal.m

randmvar_add_lognormal

PURPOSE ^

RANDMVAR_ADD_LOGNORMAL Random multivariate data with lognormal distribution

SYNOPSIS ^

function [P,C] = randmvar_add_lognormal(P,C,xm,si,Cm)

DESCRIPTION ^

 RANDMVAR_ADD_LOGNORMAL   Random multivariate data with lognormal distribution

   Prepares input to *randmvar* to include data with log-normal 
   distribution. The statistical properties are set by mean value and standard
   deviation for the natural logarithm of the data, and the covariance matrix 
   for the data variables to be included.

   Note: Mean and standard deviation are given for log(x). 

   Zero correlation to already included variables is assumed.

 FORMAT   [P,C] = randmvar_add_normal( P, C, xm, si, Cm )
        
 OUT   P       Description of probability distribution function. See 
               *randmvar* for format description.
       C       Correlation matrix. 
 IN    P       Description of probability distribution function for already 
               added variables.
       C       Correlation matrix for already added variables. 
       xm      Mean vector.
       si      Vector of standard deviations.
       C       Correlation matrix for variables to be added.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

randmvar_add_lognormal.m

SOURCE CODE ^

0001 % RANDMVAR_ADD_LOGNORMAL   Random multivariate data with lognormal distribution
0002 %
0003 %   Prepares input to *randmvar* to include data with log-normal
0004 %   distribution. The statistical properties are set by mean value and standard
0005 %   deviation for the natural logarithm of the data, and the covariance matrix
0006 %   for the data variables to be included.
0007 %
0008 %   Note: Mean and standard deviation are given for log(x).
0009 %
0010 %   Zero correlation to already included variables is assumed.
0011 %
0012 % FORMAT   [P,C] = randmvar_add_normal( P, C, xm, si, Cm )
0013 %
0014 % OUT   P       Description of probability distribution function. See
0015 %               *randmvar* for format description.
0016 %       C       Correlation matrix.
0017 % IN    P       Description of probability distribution function for already
0018 %               added variables.
0019 %       C       Correlation matrix for already added variables.
0020 %       xm      Mean vector.
0021 %       si      Vector of standard deviations.
0022 %       C       Correlation matrix for variables to be added.
0023 
0024 % 2005-05-21   Created by Patrick Eriksson.
0025 
0026 
0027 function [P,C] = randmvar_add_lognormal(P,C,xm,si,Cm)
0028 
0029 
0030 %= Check input
0031 %
0032 rqre_nargin( 5, nargin );
0033 %
0034 if ndims(C) > 2  |  size(C,1) ~= size(C,1) 
0035   error('Input argument *C* must be a square matrix.');
0036 end
0037 %
0038 if length(P) ~= size(C,1)
0039   error('Mismatch in size between *P* and *C*.');
0040 end
0041 %
0042 if ~isvector(xm)
0043   error('Input argument *xm* must be a vector.');
0044 end
0045 %
0046 if ~isvector(si)  |  length(xm) ~= length(si)
0047   error('Input argument *si* must be a vector with same length as *xm*.');
0048 end
0049 %
0050 if any( si <= 0 )
0051   error('All values of *si* must be >0.');
0052 end
0053 %
0054 if ndims(Cm) > 2  |  size(Cm,1) ~= size(Cm,1) 
0055   error('Input argument *Cm* must be a square matrix.');
0056 end
0057 %
0058 if length(xm) ~= size(Cm,1) 
0059   error('Mismatch in size between *xm* and *Cm*.');
0060 end
0061 
0062 
0063 np = length( P );
0064 nx = length( xm );
0065 
0066 P{np+nx} = [];
0067 
0068 
0069 %= Create sufficient wide normal CDF which is later converted to log-normal CDF
0070 %
0071 x = (-6:0.2:6)';
0072 y = cdf_normal(x);
0073 %
0074 y(1)   = 0;
0075 y(end) = 1;
0076 
0077 
0078 for i = 1 : nx
0079   %
0080   P{np+i}.cdf = [ exp(xm(i)+x*si(i)), y ];
0081   P{np+i}.imethod = 'spline';  
0082   %
0083 end
0084 
0085 C = covmat_append( C, Cm );
0086 
0087

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005