Explore BrainMass

Polya urn simulation via R

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

I need help in two probability problems using R program. Thanks so much!
1. Simulation of an expectation. Design a simulation exercise in R to approximate the value of E ( X^X)
when X has a U [0,1] distribution. Plot the value of the approximation as the sample size goes from 1 to
10,000. Use the Notebook feature in RStudio to create an HTML file for your answer.

2. Simulation of a Polya Urn. Put a = 10 white balls and b = 20 blue balls in an urn. Then, randomly draw
a ball from the urn, and replace it along with another ball of the same color, repeat.
a) Write an R program to simulate Rn, the proportion of white balls in the urn after n draws from the urn,
for any integer n.
b) Plot the histogram of Rn for n = 1,000.
c) Simulate Rn 10,000 times.
d) Overlay the histogram with a line graph of the appropriate limiting distribution. Use the Notebook
feature in RStudio to create an HTML file for your answer.

© BrainMass Inc. brainmass.com October 16, 2018, 5:53 am ad1c9bdddf - https://brainmass.com/math/probability/polya-urn-simulation-via-r-567308

Solution Preview

1. The code is given below. We simply sample from a uniform with the given sample size to estimate E(X^X). The last line should give you the plot you need.

means <- rep(NA, 10000)
for (sample_size in 1:10000) {
x <- runif(sample_size)
means[sample_size] <- mean(x^x)

2. Below we have the R ...

Solution Summary

The solution provides the full code for both questions, with an explanation of what the key components mean.