Question: Loop and If 1. Write an R code to define a function which keeps drawing a random number from N(0,1) until the number is positive.
Loop and If
1. Write an R code to define a function which keeps drawing a random number from N(0,1) until the number is positive. Use rnorm() and while() to answer this question.
You are generating a random draw from a truncated normal distribution. 2. Write an R code to repeat the previous function for 100 times. Use for() to answer this question.
3. Take the sample mean of 100 values you have generated. (It should be near 0.7979.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
