SAS中文论坛

标题: 请教:随机数函数normal [打印本页]

作者: shiyiming    时间: 2008-10-26 16:13
标题: 请教:随机数函数normal
请教:
如何用随机数函数normal(seed)产生均值为100,方差为30的正态随机数1000个?
作者: shiyiming    时间: 2008-10-27 01:36
标题: Re: 请教:随机数函数normal
use [i:ibc5xlui]100+30*normal(seed)[/i:ibc5xlui] for 1000 times.
or [i:ibc5xlui]x=repeat(0,1000,1); call randgen(x, 'normal', 100, 30);[/i:ibc5xlui] in PROC IML
作者: shiyiming    时间: 2008-10-27 11:27
标题: Re: 请教:随机数函数normal
谢谢您的回复.您给的答案是一个比一个专业的吧.
能提供一个call randgen的完整的语句吗?
作者: shiyiming    时间: 2008-10-27 23:59
标题: Re: 请教:随机数函数normal
maybe something like this,
[code:1oe65j9r]
proc iml;
x=repeat(0,1000,1);
call randgen(x, 'normal', 100, 30);
create mydataset from x;
append from x;
quit;
[/code:1oe65j9r]
作者: shiyiming    时间: 2008-10-28 11:38
标题: Re: 请教:随机数函数normal
like this
data a;
             drop i
        do i=1 to 1000;
                x=100+30*normal(seed);
                output;
        end;
run;
作者: shiyiming    时间: 2008-10-28 16:16
标题: Re: 请教:随机数函数normal
urchin and qing12bo, thanks  <!-- s:D --><img src="{SMILIES_PATH}/icon_biggrin.gif" alt=":D" title="Very Happy" /><!-- s:D -->
作者: shiyiming    时间: 2008-10-28 17:55
标题: Re: 请教:随机数函数normal
I think you should change the 30 as sqrt(30), the parameters for the function above is the STD , instead of variance
作者: shiyiming    时间: 2008-10-28 21:09
标题: Re: 请教:随机数函数normal
to horse1:
'the parameters for the function above is the STD , instead of variance'
------------------------------------------------------------------------
Are both STD and variance distribution shape paremeters?
How to pick one for the function when both of them are?  

&quot;CALL RANDGEN( result, distname&lt;, parm1&gt;&lt;, parm2&gt;&lt;, parm3&gt;);
result is a preallocated matrix that is to be filled with random samples from the specified distribution.
distname is the name of the distribution that is to be sampled.
parm1 -3 is a distribution shape parameter. &quot;
作者: shiyiming    时间: 2008-10-29 10:21
标题: Re: 请教:随机数函数normal
No, I means that if you use &quot;100+30*normal(seed)&quot; or &quot;call randgen(x,'normal',100,30)&quot;;  the result you obtain is a set of data with mean=100 and variance=900.

you want to get a dataset with the variance=30, right?
作者: shiyiming    时间: 2008-10-29 10:31
标题: Re: 请教:随机数函数normal
Yes, that's right. I want to get a dataset with the variance=30.
And maybe I should put my question in another way: how do you know &quot;100+30*normal(seed)&quot; or &quot;call randgen(x,'normal',100,30)&quot; results in a set of data with mean=100 and variance=900.

Well, I may just test it  <!-- s:lol: --><img src="{SMILIES_PATH}/icon_lol.gif" alt=":lol:" title="Laughing" /><!-- s:lol: -->
作者: shiyiming    时间: 2008-10-29 16:16
标题: Re: 请教:随机数函数normal
use the means procedure, and have a look at the value of STD, which is sqrt(variance).
作者: shiyiming    时间: 2008-10-29 18:01
标题: Re: 请教:随机数函数normal
Yes, horse1, after the dataset being created, we can proc means it for STD value.
How about before the dataset being created, how did you know it is sqrt(30) for the 'call randgen', beforehand?
作者: shiyiming    时间: 2008-10-30 13:28
标题: Re: 请教:随机数函数normal
晕,SAS帮助里面关于call randgen的参数写得很清楚啊,关于正态分布的第二个参数是标准差而不是方差。
作者: shiyiming    时间: 2008-10-30 16:45
标题: Re: 请教:随机数函数normal
晕,的确是写了.
Table 20.2: Parameter Assignments for Distributions里面有. <!-- s:lol: --><img src="{SMILIES_PATH}/icon_lol.gif" alt=":lol:" title="Laughing" /><!-- s:lol: -->
作者: shiyiming    时间: 2008-10-30 16:53
标题: Re: 请教:随机数函数normal
data a;
retain seed 0 ;
do i =1 to 1000;
call rannor(seed,x);
output;
end;
proc print;
run;
作者: shiyiming    时间: 2008-10-30 19:34
标题: Re: 请教:随机数函数normal
to einstein_817:
不对,你那个程序用proc means算出来的均值和方差不对.




欢迎光临 SAS中文论坛 (https://mysas.net/forum/) Powered by Discuz! X3.2