I started by creating a sample of 500 evenly distributed random numbers between 0 and 1, using the following code:
set.seed(1234) X<-runif(500, min=0, max=1)
Now I need to write psuedocode, which generates 10,000 N = 500 samples for MC simulation, calculates the average of my newly created X, and stores the iteration number and average in the result object. I have never done this, and so far I have this:
n.iter <-(10000*500) results <- matrix (0, n.iter, 4)
Finally, once this is done, I have to run it, then get the median value, average value and min / max of the accumulated sample and save them in a data frame called MC.table. (Also note that above, I have no idea why there is a โ4โ in the matrix code --- I worked on the previous examples). Any advice or help would be greatly appreciated.
EDIT: I have an example that might work, but I really don't understand what is happening to it, so please clarify its applicability for this:
Ni <- 10000 n <- 500 c <- 0 for (i in n){ for (j in 1:Ni){ c <- c+ 1 d <- data.frame (x= , y= ) results [c,1] <- c results [c,2] <- j results [c,3] <- i results [c,4] <- something( d$x, d$y) rm (d) } }
If you can even take the time to explain what this means, it will help me! Thanks!