Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 10-03-2017 08:03 PM
(1272 views)

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.

10 REPLIES 10

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Your library likely has access to Rick Wicklin's book, Simulating Data with SAS.

You can also review his blog here :

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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"};

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

*> i have to use PROC IML due to the requirement.*

I don't understand. What requirement? Is this for a school assignment?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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 *θ*.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Here are a few hints on how to get the first program above to run.

- Check the number of DO and END statements as these need to balance.
- "TO YTEMP" in the DO loops is wrong. IML is expecting a scalar, but you are providing a matrix.
- You must create the matrix AVG before you try to assign its elements inside the loop.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

**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;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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:

- Read "How to compute p-values" to learn how to estimate a p-value when you have a test statistic and N values from the simulated chi-square distribution
- The blog at https://blogs.sas.com/content/iml has many simulation articles. If you go to your favorite search engine and type
*keywords*site:https://blogs.sas.com/content/iml then your search is restricted to only that site.

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.

SAS is headed **back** to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team.

**Interested in speaking?** Content from our attendees is one of the reasons that makes SAS Innovate such a special event!

Multiple Linear Regression in SAS

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.