Write a java Binomial class to implement a Binomial random variable . Private in
ID: 3603245 • Letter: W
Question
Write a java Binomial class to implement a Binomial random variable. Private instance variables for the class should include:
double P - probability of a success in any one trial.
long N - number of independent trials.
long X - the number of successes in the N trials.
The class methods should include:
appropriate constructor(s).
appropriate get and set methods for the instance variables.
long randomX() - generates a new random value for X.
double mean() - calculates the mean of the random variable [= N*P].
double variance() - calculates the variance of random variable [= N*P*(1-P)].
double probX() - calculates the Binomial probability for the current X value.
Write a program that uses the Binomial class to solve the following problems:
1. For the Binomial distribution defined by P = 0.36 and N = 22:
a. Output P and N.
b. Generate a random value for X, and then output that value.
c. Output the mean of the distribution.
d. Output the variance of the distribution
2. For the Binomial distribution defined by P = 0.73 and N = 6, output the probability distribution of X. That is, for each value of X from 0 to 6, show the X-value together with the probability for that value. Output format should be:
X Pr(X)
0 ...
1 ...
... ...
6 ...
3. For the Binomial distribution defined by P = 0.32 and N = 12:
a. Generate 100 random variable values.
b. Calculate the average of these generated values [= (X1 + X2 + ... + X100)/100].
c. Calculate the theoretical mean of this probability distribution using the mean() method.
d. Compare the values obtained in 3b and 3c. How close are they? Why aren't the values identical?
Explanation / Answer
Binomial Experiment
LO 6.14: When appropriate, apply the binomial model to find probabilities.
Binomial experiments are random experiments that consist of a fixed number of repeated trials, like tossing a coin 10 times, randomly choosing 10 people, rolling a die 5 times, etc.
These trials, however, need to be independent in the sense that the outcome in one trial has no effect on the outcome in other trials.
In each of these repeated trials there is one outcome that is of interest to us (we call this outcome “success”), and each of the trials is identical in the sense that the probability that the trial will end in a “success” is the same in each of the trials.
So for example, if our experiment is tossing a coin 10 times, and we are interested in the outcome “heads” (our “success”), then this will be a binomial experiment, since the 10 trials are independent, and the probability of success is 1/2 in each of the 10 trials.
Let’s summarize and give more examples.
The requirements for a random experiment to be a binomial experiment are:
In binomial random experiments, the number of successes in n trials is random.
It can be as low as 0, if all the trials end up in failure, or as high as n, if all n trials end in success.
The random variable X that represents the number of successes in those n trials is called a binomial random variable, and is determined by the values of n and p. We say, “X is binomial with n = … and p = …”
EXAMPLE: Random Experiments (Binomial or Not?)
Let’s consider a few random experiments.
In each of them, we’ll decide whether the random variable is binomial. If it is, we’ll determine the values for n and p. If it isn’t, we’ll explain why not.
Example A:
A fair coin is flipped 20 times; X represents the number of heads.
X is binomial with n = 20 and p = 0.5.
Example B:
You roll a fair die 50 times; X is the number of times you get a six.
X is binomial with n = 50 and p = 1/6.
Example C:
Roll a fair die repeatedly; X is the number of rolls it takes to get a six.
X is not binomial, because the number of trials is not fixed.
Example D:
Draw 3 cards at random, one after the other, without replacement, from a set of 4 cards consisting of one club, one diamond, one heart, and one spade; X is the number of diamonds selected.
X is not binomial, because the selections are not independent. (The probability (p) of success is not constant, because it is affected by previous selections.)
Example E:
Draw 3 cards at random, one after the other, with replacement, from a set of 4 cards consisting of one club, one diamond, one heart, and one spade; X is the number of diamonds selected. Sampling with replacement ensures independence.
X is binomial with n = 3 and p = 1/4
Example F:
Approximately 1 in every 20 children has a certain disease. Let X be the number of children with the disease out of a random sample of 100 children. Although the children are sampled without replacement, it is assumed that we are sampling from such a vast population that the selections are virtually independent.
X is binomial with n = 100 and p = 1/20 = 0.05.
Example G:
The probability of having blood type B is 0.1. Choose 4 people at random; X is the number with blood type B.
X is binomial with n = 4 and p = 0.1.
Example H:
A student answers 10 quiz questions completely at random; the first five are true/false, the second five are multiple choice, with four options each. X represents the number of correct answers.
X is not binomial, because p changes from 1/2 to 1/4.
Comments:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.