double truncated data sample

2 Ansichten (letzte 30 Tage)
Bashar AlHalaq
Bashar AlHalaq am 4 Feb. 2021
Kommentiert: Walter Roberson am 24 Feb. 2021
Hi,
I generate data x using the code :
clc;
clear;
eta=2;
beta=4;
theta=1;
T=1;
t1=0.1;
t2=0.9;
ni=[10 50 75 100 50];
for i=1:length(ni)
n=ni(i);
for t=1:T
x=generate_sample(n,eta,beta,theta);
f1=pdf_WP(sort(x),eta,beta,theta);
F=cdf_WP(sort(x),eta,beta,theta);
R_Real=1-F;
end
end
the function is:
function [x]=generate_sample(n,eta,beta,theta)
for i=1:n
u=rand;
x(i)=theta.*(1./eta.*(log(1/(1-u)))).^(1./beta);
end
How can I make doule truncate from t1 to t2 from x
with my best regurds

Antworten (1)

Jeff Miller
Jeff Miller am 4 Feb. 2021
This is pretty ugly, but I think will do what you asked for:
function [x]=generate_sample(n,eta,beta,theta,t1,t2)
% find the bounds on u corresponding to the desired
% bounds on t1 and t2
xFn = @(u) theta.*(1./eta.*(log(1/(1-u)))).^(1./beta);
u1 = fzero(@(x) xFn(x)-t1,[eps 1-eps]);
u2 = fzero(@(x) xFn(x)-t2,[eps 1-eps]);
for i=1:n
% Generate u's only within the bounds
u=u1 + (u2-u1)*rand;
x(i)=xFn(u);
end
end
  2 Kommentare
Bashar AlHalaq
Bashar AlHalaq am 8 Feb. 2021
Bearbeitet: Bashar AlHalaq am 24 Feb. 2021
thank you for response on my demand ,
but i neeed truncate the sample data range , the code above dont cutting the sample data range
with my best reguard.
Jeff Miller
Jeff Miller am 8 Feb. 2021
Sorry, I guess I don't understand what you want. Maybe a numerical example would help?

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by