How to sample from a weibull distribution using the metropolis-hasting ('mhsample') function in matlab.

5 visualizzazioni (ultimi 30 giorni)
Hello, I was wondering how to select the parameters such as 'pdf','proprnd','proppdf' and start so as to feed the function "mhsample" in matlab. There are an example in the help section of matlab but it is for generating samples for a normal distribution (check this link: https://www.mathworks.com/help/stats/mhsample.html). I have written a code following the example of the normal distribution but it returns an error named "START is not in the domain of the target or proposal distribution."
This is the code.
NF1_data =[ 206300,119700,116800,135400,128200,156400,150800,132400,115900,172400, 105300, 136400,252000,255600,79900, 197500]
%NF1_min and NF1_max are the minimum and maximum values of the aforementioned %vector respectively.
A=168927; B=3.27415;
rng default % For reproducibility
delta = [NF1_min,NF1_max]; % parameter for the domain
pdf = @(x) wblpdf(x,A,B); % target distribution (intended distribution to approximate)
proppdf = @(x,y) unifpdf(y-x,NF1_min,NF1_max); % proposed distribution todraw % samples
proprnd = @(x) x + rand*NF1_max - NF1_min;
nsamples = 15000; % number of samples to generate.
opt1 = 'symmetric'; % draws nsamples random samples %from a target distribution.
logic_v = 0; % logic value 1 true/ 0 false.
start = NF1_min;
% x vector of samples generated by the metropolis-hasting alg.
x = mhsample(start,nsamples,'pdf',pdf,'proprnd',proprnd,'proppdf',proppdf );
%plot
xx = linspace(NF1_min,NF1_max,nsamples); yy=pdf(xx);
figure;
hold on
h = histogram(x,round(sqrt(numel(x))),'Normalization','pdf');
h1 = plot(xx,yy);
hold off
In addition, some of the option in reference to the function "mhsample", there are an option to exchange 'pdf' and 'proppdf' for 'logpdf' and 'logproppdf so I wonder when and what are the advantages to make that change.
I hope someone can help me with that. Cheers.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by