Question
3. Consider a modified version of the PLolya urn model in Problem 2 where we put the observed ball back into the urn together with
3. Consider a modified version of the PLolya urn model in Problem 2 where we put the observed ball
back into the urn together with a new ball of the other color. For instance, suppose we randomly
sample a ball from the urn and observe that it is red. We now put the red ball back to the urn
together with a new blue ball.
(a) Write an R function PolyaUrn v2(n.steps, urn = c("red","blue")) that works for this new
sampling scheme. The input and output of the function should be the same as in Problem 2.
Hints: When updating urn in the for loop, you should probably consider using conditional
expressions.
(b) Run PolyaUrn v2(n.steps = 200) once and plot the sample path of p.red. In the plot, make
sure to
set the y-axis limit to c(0,1);
properly label the axes;
add a horizontal reference line at 0.5 (abline(h = 0.5)).
(c) Repeat PolyaUrn v2(n.steps = 200) 300 times and graph all sample paths in a single plot.
Briefly comment on the difference between this graph and the one in 2(c).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started