Question
2. The PLolya urn model is a stochastic process with a self-reinforcing property sometimes expressed as the rich gets richer. At time 0, the urn
2. The PLolya urn model is a stochastic process with a self-reinforcing property sometimes expressed as the rich gets richer. At time 0, the urn has two colored balls, one red and one blue. In each time step, we randomly sample one ball from the urn and put back it to the urn together with a new ball of the same color. Of interest is the stochastic change in the proportion of red balls over time. (a) Write an R function PolyaUrn(n.steps, urn = c("red","blue")) where the input n.steps is the maximum time step, i.e. the number of times we draw a ball from the urn, and urn is the initial state of the urn. The function should output a vector p.red of length (n.steps+1), which is the proportion of red balls at the end of each time step, with p.red[1] = 0.5 representing the initial proportion of red balls at time 0. Hints: To get you started, here is an outline that you should probably follow: initialize p.red as a vector of length n.steps+1, with p.red[1] = 0.5. for (i in 2:(n.steps+1)){ draw one element from urn using sample(), representing the color of the new ball to be added to the urn update urn by combining urn with the new draw compute p.red[i] } return p.red (b) Run PolyaUrn(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. 1 (c) Repeat PolyaUrn(n.steps = 200) 300 times and graph all sample paths in a single plot. Feel free to use different colors to represent different runs in the plot, but you do not have to. 3. Consider a modified version of the PLolya urn model in Problem 2 where we put the observed ball
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