Question

In: Statistics and Probability

A binomial random variable with parameters n and p represents the number of successes in n...

A binomial random variable with parameters n and p represents the number of successes in n independent trials. We can obtain a binomial random variable by generating n uniform random numbers 1 2 n U ,U ,...,U and letting X be the number of i U that are less than or equal to p. (a) Write a MATLAB function to implement this algorithm and name the function gsbinrnd. You may use the for loop to generate random numbers. (b) Use the function you have written to generate a set of random variables that are distributed according to the binomial distribution. You may use the following parameters n = 6 and p = 0.5. (c) Plot the histogram for the binomial random variables generated.

Solutions

Expert Solution

a) MATLAB function to generate Binomial rv

Save this in a file called gsbinrnd.m

b) In another file write the following to call the above function to generate some variables

get the following output

c) plot the histogram

output

all code in text format

%% The following code is for the function to be saved in a file named gsbinrnd.m

function X= gsbinrnd(n,p)
%Initialize the value of X
X=0;
%using for loop generate n random numbers
for i = 1:n
%generate uniform random number in (0,1) using rand()
if rand(1,1)<=p
%if the uniform random number is less than p then increment X
X=X+1;
end;
end;
end

%%%Following code is for the main program%%%%%%%

rand('state',0);
%set the values of n and p
n=6;
p=0.5;
%number of random numbers to be generated
r=100;
%initialize Y to hold RVs
Y=[];
%generate r number of Binomial RV
for i=1:r
%call the function gsbinrnd(n,p)
Y=[Y;gsbinrnd(n,p)];
end
fprintf('\nBinomial RV for n=%.0f and p=%.2f are \n\t',n,p);
fprintf('%.0f,',Y);
%plot the histogram
%get the histogram frequencies for each bin
hist(Y,6);
title(sprintf('Distribution of Binomial RV for n=%.0f,p=%.2f',n,p));
xlabel('Binomial RV');
ylabel('Frequency');


Related Solutions

A random variable Y whose distribution is binomial with parameters are n = 500 and p=...
A random variable Y whose distribution is binomial with parameters are n = 500 and p= 0.400, and here Y suggests the number of desired outcomes of the random experiment and n-Y is the number of undesired outcomes obtained from a random experiment of n independent trials. On this random experiment   p̂ sample proportion is found as Y/n. (Round your answers to 3 decimal places in all parts.) a)What is the expected value of this statistic? b)Between what limits will...
Let X be a binomial random variable with parameters n = 5 and p = 0.6....
Let X be a binomial random variable with parameters n = 5 and p = 0.6. a) What is P(X ≥ 1)? b) What is the mean of X? c) What is the standard deviation of X? (Show work)
(a) Let X be a binomial random variable with parameters (n, p). Let Y be a...
(a) Let X be a binomial random variable with parameters (n, p). Let Y be a binomial random variable with parameters (m, p). What is the pdf of the random variable Z=X+Y? (b) Let X and Y be indpenednet random variables. Let Z=X+Y. What is the moment generating function for Z in terms of those for X and Y? Confirm your answer to the previous problem (a) via moment generating functions.
The p.d.f of the binomial distribution random variable X with parameters n and p is f(x)...
The p.d.f of the binomial distribution random variable X with parameters n and p is f(x) = n x p x (1 − p) n−x x = 0, 1, 2, ..., n 0 Otherwise Show that a) Pn x=0 f(x) = 1 [10 Marks] b) the MGF of X is given by [(1 − p) + pet ] n . Hence or otherwise show that E[X]=np and var(X)=np(1-p).
Suppose that X is a binomial random variable with parameters n=20 and p=0.7. Choose a wrong...
Suppose that X is a binomial random variable with parameters n=20 and p=0.7. Choose a wrong statement about the random variable X. a. The maximum possible value of X is 20. b. The minimum possible value of X is 0. c. The variance of X is 4.2. d. The expected value of X is 14. e. Pr(X = 19)+ Pr(X = 1)= 1
Let X denote a random variable that follows a binomial distribution with parameters n=5, p=0.3
Let X denote a random variable that follows a binomial distribution with parameters n=5, p=0.3, and Y denote a random variable that has a Poisson distribution with parameter λ = 6. Additionally, assume that X and Y are independent random variables. (a) What are the possible values for (X, Y ) pairs. (b) Derive the joint probability distribution function for X and Y. Make sure to explain your steps. (c) Using the joint pdf function of X and Y, form...
Let X denote a random variable that follows a binomial distribution with parameters n=5, p=0.3, and...
Let X denote a random variable that follows a binomial distribution with parameters n=5, p=0.3, and Y denote a random variable that has a Poisson distribution with parameter λ = 6. Additionally, assume that X and Y are independent random variables. What are the possible values for (X, Y ) pairs. Derive the joint probability distribution function for X and Y. Make sure to explain your steps. Using the joint pdf function of X and Y, form the summation /integration...
Let X denote a random variable that follows a binomial distribution with parameters n=5, p=0.3, and...
Let X denote a random variable that follows a binomial distribution with parameters n=5, p=0.3, and Y denote a random variable that has a Poisson distribution with parameter λ = 6. Additionally, assume that X and Y are independent random variables. What are the possible values for (X, Y ) pairs. Derive the joint probability distribution function for X and Y. Make sure to explain your steps. Using the joint pdf function of X and Y, form the summation /integration...
Suppose that x is a binomial random variable with n = 5, p = .66, and...
Suppose that x is a binomial random variable with n = 5, p = .66, and q = .34. (b) For each value of x, calculate p(x). (Round final answers to 4 decimal places.) p(0) = p(1)= p(2)= p(3)= p(4)= p(5) (c) Find P(x = 3). (Round final answer to 4 decimal places.) (d) Find P(x ≤ 3). (Do not round intermediate calculations. Round final answer to 4 decimal places.) (e) Find P(x < 3). (Do not round intermediate calculations....
Let N be a binomial random variable with n = 2 trials and success probability p...
Let N be a binomial random variable with n = 2 trials and success probability p = 0.5. Let X and Y be uniform random variables on [0, 1] and that X, Y, N are mutually independent. Find the probability density function for Z = NXY . Hint: Find P(Z ≤ z) for z ∈ [0, 1] by conditioning on the value of N ∈ {0, 1, 2}.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT