Page 1 of 1

PLEASE DO WITH R

Posted: Wed Apr 27, 2022 3:15 pm
by answerhappygod
PLEASE DO WITH R
Please Do With R 1
Please Do With R 1 (92.62 KiB) Viewed 58 times
Write an R function which estimates an integral for any given function(f(x)). Your function has to have two more options which are "var.reduc" which takes a boolean (True or False). "type" which takes a string from user as "Antithetic" or "Control". If user specifies "var.reduc" = FALSE, your function has to estimate the integral for that given function with classical monte carlo integration method only, then returns the estimated integral value and its variance. However, if user specifies "var.reduc" = TRUE, your function again has to calculate monte carlo integration again, but this time it also has to run a variance reduction algorithm specified in the "type" object. User should define this type object according to which variance reduction technique user want to apply. THEN, IT RETURNS THE VALUES FOR CLASSICAL MONTE CARLO INTEGRATION AND THE ESTIMATION FOR VARIANCE REDUCTION ALGORITHM (BASED ON THE SPECIFIED "TYPE"). ALSO, IT HAS TO RETURN THE VARIANCES OF THOSE TWO (MC INTEGRAL & SPECIFIED VAR.REDUC METHOD). Of course you have to consider the case that the user wants to use Control Variates method, he/she has to use another correlated function to find o* and estimate the result for the integral, so please make sure that your function can also take another function for that purpose. In control variates case, if correlation between f(x) and g(x) is smaller than 0.5, you should give warning as "correlation smaller than 0.5. You should try another f.cont function!!!". If correlation between f(x) and g(x) is bigger than 0.5, you should print the correlation between them. You should also ask the user if they want to print plot of the fucntion or not. Optionally, your function should be able to print the graph. When your function is ready, please try it with any function you want and check if it is working properly. (Hint: minimum range, maximum range, graph, var.reduc, type, f, and g should be user 8 defined.)