Question

In: Statistics and Probability

What is the code for running the Monte Carlo integration technique for the integral of the...

What is the code for running the Monte Carlo integration technique for the integral of the standard normal distribution at 2? Please include a graph of sample size vs relative error in the solution.

Solutions

Expert Solution

The following is the R-code for the MonteCarlo Integration:

#Code for MC Integration for a Single Instance

Nsim <- 100 #Number of simulations

x <- rnorm(Nsim) #Drawing a random sample

mc_value <- mean(x<=2) #Value of MC Estimator

pnorm(2) #Actual Value

#Code for MC Integration for Increasing Sample Sizes

Nsim <- 10^4

x <- rnorm(Nsim)

mc_valuearray <- cumsum(x<=2)/(1:Nsim) #Array of MC estimates


rel_error <- (mc_valuearray-pnorm(2))/pnorm(2)

plot(1:Nsim,rel_error,type="l",main="Relative Error vs Sample Size",xlab="Sample Size",ylab="Relative Error")

Important Note:

Here inputing "x<=2" in the R console returns a logical array containing TRUEs and FALSEs. As you may know, R treats TRUE as a 1 and FALSE as a 0, and they can be mathematically added. So, the commands "mean" and "cumsum" can be applied to logical arrays.

Here is the plot:


Related Solutions

Write a matlab program that determines the value of pi using the monte carlo technique. do...
Write a matlab program that determines the value of pi using the monte carlo technique. do this for a loop of multiple fixed points. (i.e 100-10000) Plot the computed value of pi and the difference from the true value as this number increases. Time the execution of your code for various numbers of points, and plot the precision vs the computational cost.
Running a Monte Carlo simulation to calculate the probability that the daily return from S&P will...
Running a Monte Carlo simulation to calculate the probability that the daily return from S&P will be > 5%. We will assume that the historical S&P daily return follows a normal distribution with an average daily return of 0.03 (%) and a standard deviation of 0.97 (%). To begin we will generate 100 random samples from the normal distribution. For the generated samples we will calculate the mean, standard deviation, and probability of occurrence where the simulation result is greater...
Make a program in C++ and write explanations. Monte-Carlo methods Calculating pi with Monte-Carlo method is...
Make a program in C++ and write explanations. Monte-Carlo methods Calculating pi with Monte-Carlo method is NOT allowed.
Perform Monte Carlo integration using R statistical programming to estimate the value of π. Generate N...
Perform Monte Carlo integration using R statistical programming to estimate the value of π. Generate N pairs of uniform random numbers (x,y), where x ∼ U(0,1)and y ∼ U(0,1) and each (x,y) pair represents a point in the unit square. To obtain an estimate of π count the fraction of points that fall inside the unit quarter circle and multiply by 4. Note that the fraction of points that fall inside the quarter circle should tend to the ratio between...
Under what conditions is it necessary to use Monte Carlo analysis in the study of a...
Under what conditions is it necessary to use Monte Carlo analysis in the study of a queuing system?
Describe the steps needed to perform the Monte Carlo Simulation.
Describe the steps needed to perform the Monte Carlo Simulation.
What is Monte Carlo simulation? What principles underlie its use, and what steps are followed in...
What is Monte Carlo simulation? What principles underlie its use, and what steps are followed in applying it? Be detailed and give an example.
Explain Monte Carlo Sampling? Under what circumstances, can it be used? Elaborate on the application and...
Explain Monte Carlo Sampling? Under what circumstances, can it be used? Elaborate on the application and limitations related to this sampling?
Describe the purpose of Monte Carlo simulations. How can these be used in designs?
Describe the purpose of Monte Carlo simulations. How can these be used in designs?
in Matlab, Use the Monte Carlo analysis to compute the area of a circle with radius...
in Matlab, Use the Monte Carlo analysis to compute the area of a circle with radius 1. print out your code, at least one figure on which the circle and ‘dart hits’ are shown, and numerical results for N=10, 100,1000. For each N, repeat the calculation at least 5times.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT