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...
There are four blue balls, three red balls, three yellow balls, and two green balls in...
There are four blue balls, three red balls, three yellow balls, and two green balls in a basket. a.) With your eyes closed, you reach into the basket and choose a single ball. What is the probability that it is blue? b.) Now instead you chose balls and replace them until a red ball appears. What is the probability a red ball appears for the first time on the 10th draw? c.) Now you choose balls and replace them until...
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...
Conditional Probability Problem: An urn contains 5 red balls, 4 green balls, and 4 yellow balls...
Conditional Probability Problem: An urn contains 5 red balls, 4 green balls, and 4 yellow balls for a total of 13 balls. If 5 balls are randomly selected without replacement, what is the probability of selecting at least two red balls given that at least one yellow ball is selected? Please show all steps.
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:
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT