double truncated data sample
2 views (last 30 days)
Show older comments
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
Answers (1)
Jeff Miller
on 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 Comments
Jeff Miller
on 8 Feb 2021
Sorry, I guess I don't understand what you want. Maybe a numerical example would help?
See Also
Categories
Find more on Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!