Quartz | Level 8

## the code is working but the results do not make any sense

Hello

My code is supposed to simulate two samples from exponential distribution based on progressive type II. Then, I must modify the samples by truncating each one at a particular time and replacing the truncated values with new ones. The final samples  should be used to estimate the overlap function between the two samples. I have three truncation choices: after 30%, 80%, or 0% of the data.
My problem is that all results are almost identical. No matter if I do the truncation or not!!!
I also found that if I fix the percentage of the truncation and change the censoring scheme (i.e., to censor the data at the beginning, at the end, or in the middle(results remain unchanged) which also doesn't make any sense!!!
I would greatly appreciate any help in resolving this matter.

``````proc iml;

*Results for T1, T2 and T3 have striking similarities, I checked everything and don't know what is the problem,
Results for Ti, i=1,2,3 when changing the censoring scheme also produce stricking similarities!!!!
**********************************************************************************************************************;

seed=0;  NN=10000;*NN is the number of simulations;

theta1=1; theta2=5;

case=17; n1=80; m1=50; k=J(m1,1,0); K[m1]=n1-m1;		L=K;    	n2=n1;     m2=m1;
/**********************************************************************************************************************;

case=16; n1=80; m1=50; k=J(m1,1,0); K[1]=n1-m1;			L=K;    	n2=n1;     m2=m1;
case=17; n1=80; m1=50; k=J(m1,1,0); K[m1]=n1-m1;		L=K;    	n2=n1;     m2=m1;
case=18; n1=80; m1=50; k=J(m1,1,0); k[41:50]=3;			L=K;    	n2=n1;     m2=m1;

*/

***********************  		Exact OVL 		*******************************;

R=(theta1/theta2);
R_star=((m2-1)/m2)*R;

Exact_rho=2*sqrt(R_star)/(1+R_star);
Exact_lambda=(Exact_rho)**2;
Exact_delta=1-R_star**(1/(1-R_star))*abs(1-1/R_star);

******************************************************************************;
start Uniform_p(m,R)  global(seed);

** The Required Progressively Type-II from U(0,1);

V=J(m,1,0); U=J(m,1,0);W=J(m,1);

Call randseed(seed);
Call randgen(W, "Uniform");

Do i=1 to m;
Sum=0;
Do j=m-i+1 to m;
Sum=Sum+R[j];
End;
Sum=Sum+i;
V[i]=W[i]**(1/Sum);

End;

Do i=1 to m;
U[i]=1-prod ( V[m: (m-i+1)]   );
End;

Call sort (U);
return U;
Finish;

********************************************************************;

Do idx=1 to m-1;
If (( X[idx] < T) & (T <= X[idx+1] )) then j=idx;
End;

If X[m]>T then

Do;
W=Uniform_p(m-j,R);
X_m_j = T - theta*log(1-W);
Rm=n-m-sum(R[1:J]);
R2=J(m-j,1,0);R2[m-J]=Rm;
newR=R[1:j]//R2;
End;

else

Do;
j= m;
newR=R;
End;

return P1;
Finish;

********** Subroutine to compute the MLEs  **************;
*********************************************************;

start MLE(X,n,m,R,Rm,J);

Theta_MLE=( Rm*X[m]+X[+]+ sum( (R#X)[1:J] ) )/m;

return(Theta_MLE);
finish;

******************************************************************************************;

Do JJ=1 to NN;

**** Data set I;
***************;

X = - theta1 * log (1- uniform_p(m1,K));   * Create Progressive type II data;
*T1=X[ceil(0.3*m1)];     * Keep the top 80% and replace the remaining data using Adaptive module;
*T1=X[ceil(0.8*m1)];	* Keep the top 30% and replace the remaining data using Adaptive module;
T1=X[m1]+2;				* Do not truncate the data;

K=newK;		Km=K[m1];

**** Data set II;
****************;

Y = - theta2 * log (1- uniform_p(m2,L));
*T2=Y[ceil(0.3*m2)];
*T2=Y[ceil(0.8*m2)];
T2=Y[m2]+2;

L=newL;		Lm=L[m2];

*print J1 T1 J2 T2 k newk l newl;

*********************************************************************;

End;

** The estimated values of the OVL **;

****** Asymptotic Variance of the Overlape ********;

******   Asymptotic Bias of the Overlape   ********;

Do JJ=1 to NN;

end;

**** Interval estimation using Asymptotic technique ****;

Do JJ=1 to NN;

***************************		 		OVL1			*****************************;

*************************************************************************************;

***************************		 		OVL2			*****************************;

**************************************************************************************;

***************************		 		OVL3			******************************;

end;

***************** 						END Of Simulations	 					************************;
********************************************************************************************************;

****formating the output *******;

Bias=J(3,1);Length=J(3,1);coverage=J(3,1); Var=J(3,1,0);

Var[1,1]=Round(VarOVL1,0.0001 ); 	Var[2,1]=Round(VarOVL2,0.0001 );	Var[3,1]=Round(VarOVL3,0.0001 );

names={rho,lambda,delta};

print case R  n1 m1;
print names  bias  "    "   Var   "    " Length "    "   coverage  ;

quit;

``````

1 ACCEPTED SOLUTION

Accepted Solutions
Quartz | Level 8

## Re: the code is working but the results do not make any sense

I think I figure out what is wrong with the results. I am restricting the outcomes to 3 or 4 digits, since the outcomes are very close, this caused all results to be identical. I validated the outcomes with a mathematica code.

Thank you again for inspiring me Rick!!

5 REPLIES 5
Super User

## Re: the code is working but the results do not make any sense

Is there some specific reason you do not want to use Call Randgen with the Exponential distribution?

My IML is so rusty and limited I am not going to attempt to follow all that code but if I were given an instruction to generate samples from an exponential distribution Randgen with Exponential would be a strong starting point instead of trying rewrite the exponential code.

Quartz | Level 8

## Re: the code is working but the results do not make any sense

Hello ballardw

Thank you for your reply. I am simulating progressive type II data from exponential an not simple random sample from exponential.

SAS Super FREQ

## Re: the code is working but the results do not make any sense

Hi Salah,

I'm sorry to hear that you are still having problems. Personally, I find it difficult to debug other people's code when I do not know what they are doing or what the correct answer should be.

However, in my 30+ years as a programmer, I have adopted a few habits that serve me well when I program. I wrote down some of the tips in the context of optimization, but a few of the tips apply to simulation as well:

1. Start with a simple program. Completely debug it and ensure that it works before attempting anything complicated.

2. Break your big program into smaller function modules that you can create/debug/reuse.

3. Always test the program at each step of development. Don't wait until the program is completely written to test it.

4. Do not attempt a sample of size 10,000 until you have verified that the program works for much smaller sample sizes.

5. Do not attempt multiple truncation choices until you have verified that one works.

6. Are your two samples independent? If so, you can debug/validate each process one at a time.

I wish I could offer more helpful advice, but I think the best way for you to proceed is to implement a highly disciplined approach to writing the program.  Believe me, I have spent days trying to debug programs, so I know it is very frustrating. Sometimes I succeed only after I decide to rewrite portions of the code, testing as I go, until I discover my initial mistakes.

Best wishes!

Quartz | Level 8

## Re: the code is working but the results do not make any sense

Thank you Rick for the tips.

As a matter of fact, this is exactly what I have done.

Nevertheless, I will start again from scratch with fresh eye.

Quartz | Level 8

## Re: the code is working but the results do not make any sense

I think I figure out what is wrong with the results. I am restricting the outcomes to 3 or 4 digits, since the outcomes are very close, this caused all results to be identical. I validated the outcomes with a mathematica code.

Thank you again for inspiring me Rick!!

From The DO Loop