Random draws from conditional multinomial distribution
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Laura Freitas
am 26 Okt. 2021
Kommentiert: Laura Freitas
am 26 Okt. 2021
I have to simulate data for 100 agents over 10,000 time periods for a variable, x. The initial value of x at time 0 for all agents is 0. The distribution of
is a multinomial distribution, conditional on the past period's value,
. Basically,
can remain unchanged with probability 0.2, increase by 2571 with probability 0.5, increase by 2571*2 with probability 0.2, and increase by 2571*3 with probability 0.1, at any period.
can never be lower than
. How do I generate random values for this distribution?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/778978/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/778983/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/778988/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/778993/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/778998/image.png)
I have tried:
x = mnrnd()
command, but I can't fit it to these specifications. Any help would be greatly appreciated!
0 Kommentare
Akzeptierte Antwort
Alan Stevens
am 26 Okt. 2021
Something like
u = rand(1)
if u<0.2
d = 0;
elseif u<0.7
d = 2571;
elseif u<0.9
d = 2571^2;
else
d = 2571^3;
end
x(t) = x(t-1) + d;
(the last line assumes t is an integer).
5 Kommentare
Alan Stevens
am 26 Okt. 2021
function xnew = fn(x,t)
u = rand;
if u<0.2
d = 0;
elseif u<0.7
d = 2571;
elseif u<0.9
d = 2571^2;
else
d = 2571^3;
end
x(t) = x(t-1) + d;
end
Note that functions go at the end of a script.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Financial Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!