WBETASTAT Mean and variance for the Beta distribution. CALL: [m,v] = wbetastat(df1,df2) m, v = the mean and variance, respectively a, b = parameters of the Beta distribution Mean (m) and variance (v) for the Beta distribution is m = a/(a+b) and v = a*b/(a+b)^2/(a+b+1) if a>0, b>0 See also wbetapdf
Check if all input arguments are either scalar or of common size. | |
Display message and abort function. | |
Not-a-Number. | |
Display warning message; disable or enable warning messages. |
001 function [m,v]= wbetastat(a,c); 002 %WBETASTAT Mean and variance for the Beta distribution. 003 % 004 % CALL: [m,v] = wbetastat(df1,df2) 005 % 006 % m, v = the mean and variance, respectively 007 % a, b = parameters of the Beta distribution 008 % 009 % Mean (m) and variance (v) for the Beta distribution is 010 % 011 % m = a/(a+b) and v = a*b/(a+b)^2/(a+b+1) if a>0, b>0 012 % 013 % See also wbetapdf 014 015 016 % Reference: Cohen & Whittle, (1988) "Parameter Estimation in Reliability 017 % and Life Span Models", Marcel Dekker. 018 019 020 % Tested on; Matlab 5.3 021 % History: 022 % by pab 23.10.2000 023 024 error(nargchk(2,2,nargin)) 025 [errorcode, a, c] = comnsize(a,c); 026 if errorcode > 0 027 error('a and b must be of common size or scalar.'); 028 end 029 030 031 % Initialize Mean and Variance to zero. 032 m = zeros(size(a)); 033 v = zeros(size(a)); 034 035 ok = (a > 0 & c > 0 ); 036 k = find(ok); 037 if any(k) 038 m(k) = a(k)./(a(k)+c(k)); 039 v(k) = m(k).*c(k)./(a(k)+c(k))./(a(k)+c(k)+1); 040 end 041 042 k1 = find(~ok); 043 if any(k1) 044 warning('a and b should be positive') 045 tmp = NaN; 046 v(k1) = tmp(ones(size(k1))); 047 m(k) = v(k1); 048 end 049 050 051
Comments or corrections to the WAFO group