Question

Build a function in R that computes the probability of : a vector of length 4...

Build a function in R that computes the probability of : a vector of length 4 that represents the number of balls of each of 4 colors (red, blue, green, yellow), and a vector of length 4 that represents the number of each ball chosen.

Homework Answers

Answer #1

prob=function (x)
{ if(length(x)==4){
x/sum(x)
}
}
X=c(10,12,14,13)
prob(X)

[1] 0.2040816 0.2448980 0.2857143 0.2653061

prob=function (x,col=NULL)
{ if(length(x)==4){
if(class(col)=="NULL") col=1:4
x[col]/sum(x)
}
}
X=c(10,12,14,13)
# Here color are coded with 1,2,3,4

#red=1, blue=2, green=3, yellow=4 and number of balls are 10,12,14,13

prob(X,col=1)#for first color
[1] 0.2040816
prob(X,col=2)#for second color
[1] 0.244898
prob(X,col=3:4)# for third and fourth color
[1] 0.2857143 0.2653061
prob(X) # for probability of a first to fourth color
[1] 0.2040816 0.2448980 0.2857143 0.2653061

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Bag 1 contains six red balls, seven blue balls, and three green balls. Bag 2 contains...
Bag 1 contains six red balls, seven blue balls, and three green balls. Bag 2 contains eight red balls, eight blue balls, and two green balls. Bag 3 contains two red balls, nine blue balls, and eight green balls. Bag 4 contains four red balls, seven blue balls, and no green balls. Bag 1 is chosen with a probability of 0.15, bag 2 with a probability of 0.20, bag 3 with a probability of 0.35, and bag 4 with a...
Box 1 contains 4 red balls, 5 green balls and 1 yellow ball. Box 2 contains...
Box 1 contains 4 red balls, 5 green balls and 1 yellow ball. Box 2 contains 3 red balls, 5 green balls and 2 yellow balls. Box 3 contains 2 red balls, 5 green balls and 3 yellow balls. Box 4 contains 1 red ball, 5 green balls and 4 yellow balls. Which of the following variables have a binomial distribution? (I) Randomly select three balls from Box 1 with replacement. X = number of red balls selected (II) Randomly...
Moments and Function Generator of Moments An urn contains 4 red balls, 3 blue, 2 green...
Moments and Function Generator of Moments An urn contains 4 red balls, 3 blue, 2 green and one yellow. Three balls are obtained from this sample (without replacement). Let X be the random variable that represents the number of red balls that are extracted. a) Find the probability function of the random variable X b) Find the first moment of the random variable c) Find the second moment of the random variable d) Find the third moment of the random...
An urn contains five blue, six green and seven red balls. You choose five balls at...
An urn contains five blue, six green and seven red balls. You choose five balls at random from the urn, without replacement (so you do not put a ball back in the urn after you pick it), what is the probability that you chose at least one ball of each color?(Hint: Consider the events: B, G, and R, denoting respectively that there are no blue, no green and no red balls chosen.)
In an urn, there are 20 balls of four colors: red, black, yellow and blue. For...
In an urn, there are 20 balls of four colors: red, black, yellow and blue. For each color, there are 5 balls and they are numbered from 1 to 5. 1) If one ball is randomly drawn from the urn, what is the probability that the randomly selected ball is red or blue? 2) If one ball is randomly drawn from the urn, what is the probability that the randomly selected ball is numbered 1 or blue?
A bag contains 4 red balls and 5 green balls. If 4 balls are taken from...
A bag contains 4 red balls and 5 green balls. If 4 balls are taken from the bag without replacement, find the probability that i) 2 red balls and 2 green balls are chosen ii) the first two balls are red and the second two balls are green iii) the colors of the four balls alternate
Q2) Box1: 6 green balls, 2 red balls, 6 blue balls Box2: 1 green balls, 4...
Q2) Box1: 6 green balls, 2 red balls, 6 blue balls Box2: 1 green balls, 4 red balls, 8 blue balls Experiment: Select one of the two boxes with uniform random probability, and draw two balls from the selected box. Record the box number as the r.v. i, and the colors of the two balls as b1, b2. Compute P(b1 = green| i=1 ) [Round to 3 digits after decimal point]
Question 5 (1 point) Box1: 5 green balls, 4 red balls, 5 blue balls Box2: 0...
Question 5 (1 point) Box1: 5 green balls, 4 red balls, 5 blue balls Box2: 0 green balls, 4 red balls, 7 blue balls Experiment: Select one of the two boxes with uniform random probability, and draw two balls from the selected box. Record the box number as the r.v. i, and the colors of the two balls as b1, b2. Compute P(b1 = green ) [Round to 3 digits after decimal point] Your Answer:
An urn has 15 white balls, 13 green balls, 10 yellow balls, and 12 red balls....
An urn has 15 white balls, 13 green balls, 10 yellow balls, and 12 red balls. Determine the probability that it will come out: a. A red ball b. A green ball c. A white ball d. A red ball and a yellow ball e. A ball that is not green Calculate the probability that the number 89 will come out when taking a ball from a bag with 120 balls numbered from 1 to 120. Calculate the probability that...
Suppose that: Urn U1 contains 3 blue balls and six red balls, and Urn U2 contains...
Suppose that: Urn U1 contains 3 blue balls and six red balls, and Urn U2 contains 5 blue ball and 4 red balls Suppose we draw one ball at random from each urn. If the two balls drawn have different colors, what is the probability that the blue ball came from urn U1?