How do I create a random variable which follows the Rademacher Distribution?

조회 수: 11 (최근 30일)
Fox
Fox 2015년 12월 21일
댓글: Fox 2015년 12월 21일
Hello I want to make a form of wild bootstrap of a residual from a regression. I have to multiply my residual with a random variable which follows the rademacher distribution. => How can I create such a random variable?
Can somebody help me to solve this problem ?

채택된 답변

James Tursa
James Tursa 2015년 12월 21일
편집: James Tursa 2015년 12월 21일
One way:
n = number of samples; % <-- The number of samples you want
mp = [-1 1]; % <-- The two values you want as outputs
x = mp((rand(1,n)<.5)+1); % <-- Randomly pick one of the two values for n samples.
Another way:
x = (rand(1,n)<.5)*2 - 1;

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by