Plot the cumulative probability distribution (CDF) of Y versus minutes.
2 views (last 30 days)
Show older comments
- From this plot, one should be able to estimate P[Y ≤ y], the probability that the total medication administration time is less than or equal to some time period y (in minutes). To obtain this CDF you will need to determine the number of total medication administration times that fall into each 1-minute interval. The percentage of these times would then represent the estimated probability of Y being in that interval. A key to being able to generate the data for this plot is to determine how many 1-minute intervals you will need. Insert axes labels and a title. Format the plot. (You may want to consider a pause commend after the CDF plot to allow you to edit/format the plot. Hitting any key would then allow for the next plot to appear.)
REST OF PROBLEM BELOW
%(1. Generate 1000 random values of X1. Use the rand
% function to create values from a uniform distribution
% ranging from 2 ≤ X1 ≤ 6.
clearvars
X1= rand(1,1000)
(2+rand(1,1000)*4)
% 2. Generate 1000 values of X2 using the approach from
% page 61 of the Lecture Notes (Chapter 6, Example 6) where λ = 0.125.
X2=(-log(1-rand(1,1000)))/(.125)
% 3. Generate 1000 values of X3 using the randn function,
% which generates random values from the Z distribution (the standardized Gaussian).
% Adjust each outcome so that it has a Gaussian distribution
% with µ = 10 (minutes) and σ = 3 (minutes) by first multiplying
% all the z-values by 3 and then adding 10. Because the possibility
% exists of generating some small negative values
% (a true Gaussian distribution extends from -∞ to +∞),
% in your code, "truncate" the values generated by ensuring
% that any negative values are set to zero.
X3=10 + sqrt(3) * randn(1000)
if X3<0, X3=0
end
% 4. Generate 1000 values of X4. First, you will need
% to perform some hand calculations to derive a mathematical
% expression that you can then code into your MATLAB program.
% The steps are as follows:
% Derive the PDF for X4 using, for example,
% the Theorem 6.2 More general version on the bottom of page 59
% and top of page 60 of the Lecture Notes.
% From this PDF, derive the CDF of X4 as we learned to do in class.
% Following the procedure related to Example 6
% in Chapter 6 (page 61) of the Lecture Notes (see Step 2 above),
% you need to equate u, which is equal to rand(1), to this CDF.
% Solve for X4 in your MATLAB code.
X4=sqrt(64*rand(1))
% 5. Generate 1000 values of X5 using the same approach used in Step 2,
% but with λ = 0.1.
X5=(-log(1-rand(1,1000)))/(.1)
% 6. Generate 1000 values of CT (management%s "critical time”)
% using the same approach as Step 3, but with management%s values
% of µ = 30 minutes and σ = 5. (Remember to truncate if necessary.)
CT = 30 + sqrt(5) * randn(1000)
if X3<0, X3=0
end
% 7. Define the random variable Y = X1 + X2 + X3 + X4 + X5
% (all these variables should be in units of minutes).
Y = X1 + X2 + X3 + X4 + X5
% Y,X1, X2, X3, X4, X5 ARE IN UNITS OF MINUTES
% 8. a) Define an array that will be incremented in units of one minute.
%
% b) Define an array that computes the cumulative frequency of total
% medication administration times (Y) which are less than or equal to the
% time in minutes specified by the minutes array.
%
% c) Define an array that computes the cumulative probability of
% getting a total medication administration time that is less than or
% equal to the time specified in the minutes array.
% Note: The first value in each of these arrays should be zero.
s=0;
q=0;
for L=1:1000
if Y(L)< CT(L);
s=s+1;
else
q=q+1;
end
end
xcumFreq = zeros(size(Y));
for i=1:numel(Y)
cumFreq(i) = sum(Y(L)<= CT(L));
end
xcumprob = zeros(size(Y));
for i=1:numel(Y)
cumprob(i) = sum(Y(L)<= CT(L));
end
probability of y = (sum of Y)/1000
% 9. Compute the minimum, maximum, mean, and standard deviation of
% Y (using the min, max, mean, and std MATLAB functions).
min(Y)
max(Y)
mean(Y)
std(Y)
5 Comments
Aritra
on 20 Mar 2023
As per my understanding you are trying to plot the cumulative probability distribution(CDF).
To solve this, you can make use of the “cdfplot” function. The “cdfplot(x)” function creates an empirical cumulative distribution function plot for the data in x. For a value t in x, the empirical cdf F(t) is the proportion of the values in x less than or equal to t.
For detail, please see the “Compare Empirical cdf to Theoretical cdf” Example in MathWorks documentation on: https://www.mathworks.com/help/stats/cdfplot.html
Answers (0)
See Also
Categories
Find more on Random Number Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!