필터 지우기
필터 지우기

Generating random numbers with mean and std dev specified

조회 수: 1 (최근 30일)
Lorraine Williams
Lorraine Williams 2015년 10월 24일
댓글: Star Strider 2015년 10월 24일
Hi
I have a simple linear regression model y=10+25x+Ɛ where the random error term is normally and independently distributed with mean zero and standard deviation 2.
I have to generate 8 of these E values.
If I were to generate 5 random numbers between 4 an 7 (for example), then I'd usually use this: - x=4+(7-4)*rand(1,5); (i.e.,) vector=min+(max-min)*rand(r,c)
With this in mind, I was using the following, but the values aren't between -2 and 2:
E=-2+(2+2)*randn(1,8)
Can anybody point me in the right direction?
Thanks

답변 (1개)

dpb
dpb 2015년 10월 24일
The statistics for a normal are the mean and standard deviation, not the range of the observations as for a uniform, say. In fact, the standard normal variate is over range [-inf inf].
You state the desired error term is N(0,2) so the realization would be E = MEAN + STDev*randn(m,n), or in your specific case
E=2*randn(1,8);
since desired MEAN=0;
Your code above generates an approximation to N(-2,4) instead of N(0,2)
  댓글 수: 2
Lorraine Williams
Lorraine Williams 2015년 10월 24일
Thank you. When I run E=2*randn(1,8), am I supposed to get random numbers between -2 and +2?
Star Strider
Star Strider 2015년 10월 24일
No. There is a 68% probability that they will be on the interval (-2,+2). They could theoretically be ±Inf.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Regression에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by