I am a new user of SAS with no basic knowledge. I want to calculate the location parameter with respect to Chi-Square distribution using RANNOR in SAS/IML. However, I don't know how to write the programming. Can you help me?? It is very urgent as I am in my final semester of my postgraduate study. Appreciate your help so much.
Your library likely has access to Rick Wicklin's book, Simulating Data with SAS.
You can also review his blog here :
I am using Hodges-Lehmann estimator and want to test under Chi-Square (3df). The attached file is the formula of estimator and the distribution. Below is my programming and there are errors when I run it. May I know which parts should I change?
PROC IML;
**MATRIX CALLED GSMAT**;
START GBASMOD(Y,GSMAT) GLOBAL (NX,BOBS);
GSMAT = J(2, BOBS, 0);
F = 1;
M = 0;
DO I = 1 TO BOBS;
SAMP = NX[I];
L = M + SAMP;
TEMP = Y[F:L];
**GETTING GROUP MEDIANS**;
/*GSMAT[1,I] = HL – location estimator*/
H=(SAMP)*(SAMP+1)/2;
AVG=J(H,1,0);
K=0;
DO Z=1 TO SAMP;
DO J=1 TO SAMP;
IF Z<=J THEN DO;
K=K+1;
AVG[K,]=(TEMP[Z]+TEMP[J])/2;
END;
END;
GSMAT[1,I] = MEDIAN(AVG);
END;
****GENERATE DATA FOR CONDITIONS****;
*PRINT 'NSIM STAT PVAL ';
DO K = 1 TO 1000000;
IF F = 1 THEN TEMP=RANNOR(J(1000000,3,439839383));
NX[I] = TEMP[##,];
END;
RUN
PRINT 'NSIM STAT PVAL’;
NAMES1 = {"Estimate"};
I tried with another programming but there are errors. Can anyone help me to identify my mistakes?
PROC IML;
**HODGES-LEHMANN IN CHI-SQUARE DISTRIBUTION**;
SSEED=439839383;
N=1000000;
TEMP=RANNOR(J(N,3,SSEED));
YTEMP=TEMP[##2,+];
Y1=YTEMP[I];
Y2=YTEMP[J];
DO I=1 TO N;
DO J=1 TO N;
AVG=(Y1+Y2)/2;
HL=MEDIAN(AVG);
END;
RUN
PRINT 'RESULTS:';
NAMEHL = {"HL"};
END;
You seem to be asking two questions. The first is how to compute the Hodges-Lehmann estimator for a set of data. The second issue is that you seem to be trying to generate random variates from the chi-square distribution with 3 degrees of freedom by using random normal variates.
You don't need to generate normal variates to generate random values from the chi-square distribution. You can generate chi-square values directly from the RANDGEN function. I won't pursue this because you don't need random variates to compute the p-value for the H-L test. P-values are computed by using the CDF function to compute probabilities. Read the article "Four essential functions for statistical programmers" to understand the difference between PDF, CDF, quantiles, and random values.
As for computing the H-L estimator, you don't need PROC IML for this. You can use the HL option in the PROC NPAR1WAY procedure. The documentation has an example that shows how to generate the estimate and how to interpret the result. Follow that example to analyze your data.
Thank you so much for your reply. However, i have to use PROC IML due to the requirement. I manage to create another programming but i cant get the results from SAS. May i know which part is wrong?
PROC IML;
START MYFUNC(HL);
HL=MEDIAN(AVG);
FINISH;
SSEED=439839383;
N=1000000;
TEMP=RANNOR(J(N,3,SSEED));
YTEMP=TEMP[,##];
/*HODGES-LEHMANN estimator*/
K=0;
DO Z=1 TO YTEMP;
DO J=1 TO YTEMP;
IF Z<=J THEN DO;
K=K+1;
AVG[K,]=(YTEMP[Z]+YTEMP[J])/2;
END;
END;
CALL MYFUNC(HL);
PRINT HL;
> i have to use PROC IML due to the requirement.
I don't understand. What requirement? Is this for a school assignment?
Dear Sir,
Yes. It is the requirement of my assignment. Description of my assignment is "the value of θ are determined by calculating θ with one million observations that were simulated from Chi-Square (3df)".
Below are the steps for me to create the programming using PROC IML with N=1000000.
1. Generate 3 standard random variates (use RANNOR).
2. Square each variate.
3. Sum all three squared variates.
4. Use Hodges-Lehmann to calculate the value of θ.
Here are a few hints on how to get the first program above to run.
I am sorry to disturb everyone. I am a new user and I have zero knowledge on this software.
can i do this? i still can't get any results from SAS.
PROC IML;
START MYFUNC(HL);
HL=MEDIAN(AVG);
FINISH;
SSEED=439839383;
N=1000000;
TEMP=RANNOR(J(N,3,SSEED));
YTEMP=TEMP[,##];
/*HODGES-LEHMANN estimator*/
H=N*(N+1)/2;
AVG=J(H,1,0);
K=0;
DO Z=1 TO N;
DO J=1 TO N;
IF Z<=J THEN DO;
K=K+1;
AVG[K,]=(YTEMP[Z]+YTEMP[J])/2;
END;
END;
START HL;
CALL MYFUNC(HL);
RUN;
PRINT HL;
Yes, it can be done. It sounds ilke you are supposed to compute the test statistic and then estimate the p-value by using a Monte Carlo simulation from the chi-square distribution with 3 DoF. Here are some hints:
Here's what you should do:
A. Figure out how to calculate the H-L statistic for your data. THis is the "test statistic."
B. You've already generated N random observations from chi-square(3) distribution.
C. Use the formula in the "How to compute p-values..." article to estimate the p-value for your test statistic.
Good luck.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.