10-17-2016 07:36 PM
This is my first semester of stats and, consequently, using SAS. So, I'm sorry for the entry-level question to all you programmers. Our professor's philosophy is basically "struggle until you figure it out", which is getting incredibly frustrating.
So here's my problem. I need to run a Monte Carlo Simulation where I calculate the sample mean, followed by the population mean, then calculate a 95% confidence interval for each observation, then determine how many times the population mean falls into the 95% confidence interval.
We were able to come around to the confidence intervals, although I know this is NOT the preferred, streamlined way of doing so. But the Proc Univariate statements give us the upper/lower bounds of the confidence intervals. So now I need the code to calculate each individual confidence interval and then give me the count of how many times the real population mean falls into the confidence interval?
1) is there a way to get proc univariate to give me both the upper and lower confidence intervals in a single line? I basically want to define:
xbar-1.96*sqrt(4/10)<mu<xbar+1.96*sqrt(4/10) and get the upper/lower bounds of the confidence interval in one function if possible.
2) how can I set the data to look at every individual simulation's confidence interval and delete those that *don't* include the number 5 (my calculated population mean)? I know you can do When = and if statements, but I just can't seem to get anything to work properly. The only thing I could get out of my professor was "I would use an 'includes' statement" (great, thanks for teaching us that, bro.)
I know this is super basic crap, and you guys aren't in the business of teaching people SAS flat out, but if you can point me to some useful resources or useful board posts, that would be very helpful. No one in this class has experience with this stuff and while we understand the underlying math, getting SAS to spit out the same info seems next to impossible at this point.
We are about at the end of our rope with this. Thanks so much for your help in advance!
do i=1 to 100000;
do k=1 to n;
proc univariate data=hw3prob1 cibasic(alpha=.05); var mu1;
proc univariate data=hw3prob1 cibasic(alpha=.05); var mu2;
if mu1<4.43 then delete;
if mu1>6.68 then delete;
proc freq; table mu1;
10-18-2016 12:08 AM
I feel like you may be missing some of the key ideas for Monte Carlo simulation. When you talk about an individual, what exactly are you referring to?
Technically, look at PROC MEANS for the statistics. Or use an output dataset from PROC UNIVARIATE.
A good reference paper for simulations is this one:
Proc means data=hw3prob1 n mean std UCLm lclm NWAY STACKODS; class K; var x; ods output summary=Sim_summary_results; run;
Look at the Sim_Summary_results dataset.
I'm also surprised that a first level stats course is teaching simulation. But I'm guessing this is intended to teach you the CLT.
10-18-2016 11:23 AM
Use the link that KSharp provides. Also, you don't need to simulate a normal variate by using the sum of six uniform variates. SAS provides the RAND("Normal") function for generating a random variate from the standard normal distribution. If you want a nonstandard distribution, include the mean and stddev as additional arguments, like this:
x = rand("Normal", 10, 2); /* population mean=10; popul stddev=2 */
Need further help from the community? Please ask a new question.