Reputation: 1
proc iml;
call randseed(4545); * initialize the stream (like streaminit);
x = J(5000,1,.); * pre-allocate space for random numbers;
call randgen(x,'normal',0,1); * fill x with N(0,1) deviates;
y = y + (x**2 - 3*x**3 + 5x < 1);
p = y / 5000; * MEAN acts on each matrix column;
se = sqrt(y*(1-y)/5000); * VAR, but not STD or STDERR, also acts on columns;
print "IML STEP: estimated probability is" p
"with standard error" se; * use PRINT, not PUT;
I'm trying to use monte carlo integration with proc iml to estimate the probability that x**2 - 3*x**3 + 5x is less than 1. What am I doing wrong? Do loops are not allowed by the way.
Upvotes: 0
Views: 386
Reputation: 12465
Lots of things wrong here. AS Rick says, this has the feel of a homework problem, so I won't post the solution. Here are some things to think about.
5x
is not a valid operation.Upvotes: 1
Reputation: 1210
This is probably a homework problem, so I am not going to give the complete answer. However, my first hint is to think about what Y is supposed to be. It is supposed to be an indicator variable (0/1) that indicates whether a randomly chosen observation falls within a certain region of the plane.
My second hint is to remember that you cannot use an undefined variable on the right hand side of an expression, so 'y + (f(x)<1)' is not a valid vector expression. Good luck!
Upvotes: 0