<< Chapter < Page Chapter >> Page >

cdbn.m Plots a continuous graph of a distribution function of a simple random variable (or simple approximation).

% CDBN file cdbn.m Continuous graph of distribution function % Version of 1/29/97% Plots continuous graph of dbn function FX from % distribution of simple rv (or simple approximation)xc = input('Enter row matrix of VALUES '); pc = input('Enter row matrix of PROBABILITIES ');m = length(xc); FX = cumsum(pc);xt = [xc(1)-0.01 xc xc(m)+0.01];FX = [0 FX FX(m)]; % Artificial extension of range and domainplot(xt,FX) % Plot of continuous graph gridxlabel('t') ylabel('u = F(t)')title('Distribution Function')
Got questions? Get instant answers now!

simple.m Calculates basic quantites for simple random variables from the distribution, input as row matrices X and P X .

% SIMPLE file simple.m Calculates basic quantites for simple rv % Version of 6/18/95X = input('Enter row matrix of X-values '); PX = input('Enter row matrix PX of X probabilities ');n = length(X); % dimension of X EX = dot(X,PX) % E[X]EX2 = dot(X.^2,PX) % E[X^2] VX = EX2 - EX^2 % Var[X]disp(' ') disp('Use row matrices X and PX for further calculations')
Got questions? Get instant answers now!

jddbn.m Representation of joint distribution function for simple pair by obtaining the value of F X Y at the lower left hand corners of each grid cell.

% JDDBN file jddbn.m Joint distribution function % Version of 10/7/96% Joint discrete distribution function for % joint matrix P (arranged as on the plane).% Values at lower left hand corners of grid cells P = input('Enter joint probability matrix (as on the plane) ');FXY = flipud(cumsum(flipud(P))); FXY = cumsum(FXY')';disp('To view corner values for joint dbn function, call for FXY')
Got questions? Get instant answers now!

jsimple.m Calculates basic quantities for a joint simple pair { X , Y } from the joint distrsibution X , Y , P as in jcalc. Calculated quantities include means, variances, covariance, regression line, and regression curve (conditional expectation E [ Y | X = t ] ).

% JSIMPLE file jsimple.m Calculates basic quantities for joint simple rv % Version of 5/25/95% The joint probabilities are arranged as on the plane % (the top row corresponds to the largest value of Y)P = input('Enter JOINT PROBABILITIES (as on the plane) '); X = input('Enter row matrix of VALUES of X ');Y = input('Enter row matrix of VALUES of Y '); disp(' ')PX = sum(P); % marginal distribution for X PY = fliplr(sum(P')); % marginal distribution for YXDBN = [X; PX]';YDBN = [Y; PY]';PT = idbn(PX,PY); D = total(abs(P - PT)); % test for differenceif D>1e-8 % to prevent roundoff error masking zero disp('{X,Y} is NOT independent')else disp('{X,Y} is independent')end disp(' ')[t,u] = meshgrid(X,fliplr(Y));EX = total(t.*P) % E[X] EY = total(u.*P) % E[Y]EX2 = total((t.^2).*P) % E[X^2] EY2 = total((u.^2).*P) % E[Y^2]EXY = total(t.*u.*P) % E[XY] VX = EX2 - EX^2 % Var[X]VY = EY2 - EY^2 % Var[Y] cv = EXY - EX*EY; % Cov[X,Y]= E[XY] - E[X]E[Y] if abs(cv)>1e-9 % to prevent roundoff error masking zero CV = cvelse CV = 0end a = CV/VX % regression line of Y on X isb = EY - a*EX % u = at + b R = CV/sqrt(VX*VY); % correlation coefficient rhodisp(['The regression line of Y on X is: u = ',num2str(a),'t + ',num2str(b),])disp(['The correlation coefficient is: rho = ',num2str(R),])disp(' ') eYx = sum(u.*P)./PX;EYX = [X;eYx]';disp('Marginal dbns are in X, PX, Y, PY; to view, call XDBN, YDBN') disp('E[Y|X = x]is in eYx; to view, call for EYX') disp('Use array operations on matrices X, Y, PX, PY, t, u, and P')
Got questions? Get instant answers now!

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Applied probability. OpenStax CNX. Aug 31, 2009 Download for free at http://cnx.org/content/col10708/1.6
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Applied probability' conversation and receive update notifications?

Ask