Turn on suggestions

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

Showing results for

- Home
- /
- Programming
- /
- Programming
- /
- Re: how to write code for 1 parameter logistic model

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 05-09-2020 04:20 PM
(860 views)

Hello SAS expert,

I have a test contains 150 items, item difficulty parameter for each item is as attached. Suppose I now have candidate whose ability level is 0, I named it theta=0. Now on **each of the item**, I need to calculate the probability of this candidate correctly answer on each of the time, how should I edit the following **macro sas** code to make it work?

proc import datafile="\bpar.csv" dbms=csv out=bpar replace; run;

%macro f1;

do i=1 to 150; /*from item 1 to item 150*/

prob &i= exp(theta-bpar&i)/(1+exp(theta-bpar&i); /*1 parameter logistic regression model*/

end;

%mend;

%f1;

8 REPLIES 8

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

- There's a lot of confusion here, so much that I don't even understand the question.

The formula you show is NOT a Logistic Regression formula as far as I can see (unless it is some algebraic manipulation of a Logistic Regression formula that I am not familiar with). A true logistic regression has an intercept and a slope, and the slope must be multiplied by an x-variable, and I don't see that in your formula. (You can see the proper formula to predict the probability of Y=1 at Wikipedia and many many web pages.) So I have no idea ahow to proceed here. We would furthermore need to know the slope and intercept even if we had the proper formula. So I have no idea how to proceed here.

So I advise you to phrase the problem more clearly, look up the proper formula, determine the intercept and slope in your logistic model, and then we might be able to move forward.

Also, your macro appears to be data set code, but it's not called within a data set, and then there are syntax errors as well. And it's not obvious why you need a macro anyway.

--

Paige Miller

Paige Miller

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

Thank you for your response!

In the field of measurement, the model is called Rasch model, which is similar to 1 parameter logistic regression model. This one parameter is called item difficulty. If I want to know the probability of a examinee with a certain ability level get item i correct, it write as,

prob (i)=exp(theta-bpar(i))/(1+(exp(theta-bpar(i)))

where theta denote a certain ability level, bpar is the difficulty parameter of item i

Now I have 150 items in a test, the "bpar.csv" as in the attachment are the item difficulty for those 150 items. Now suppose I have a examinee with ability level theta=0, I want to know the probability of this examinee get each item correct, how should I wrote that in a SAS macro?

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

So where do we get the value of the parameter bpar? You say your .csv file contains difficulty, not bpar. Your code also seems to indicate bpar(i), that there are many values of bpar.

--

Paige Miller

Paige Miller

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

in the "bpar.csv", there is a variable named bpar. There are 150 items in total, so there are 150 bpar values.

Corresponding to each bpar value, there is one probability. so I need to write a macro that can compute 150 probabilities.

I know my code is not correct, so I am asking for help.

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

FYI, variable "bpar" in the "bpar.csv" is the item difficulty parameter.

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

@superbug wrote:

Now I have 150 items in a test, the "bpar.csv" as in the attachment are the item difficulty for those 150 items. Now suppose I have a examinee with ability level theta=0, I want to know the probability of this examinee get each item correct, how should I wrote that in a SAS macro?

Part of the problem we are having is that I still don't think I have understood the problem, and you have not yet explained it clearly. So now you state "Now suppose I have a examinee with ability level theta=0" ... okay, I see that bpar is in the CSV file, but theta is not in the CSV file. If we have a formula that has theta in it, we need to know theta for each examinee; and your words imply that theta is zero for one specific examinee.

--

Paige Miller

Paige Miller

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

Assuming your formula is what you want and theta =0, your formula simplifies to:

`prob &i= exp(-bpar&i)/(1+exp(-bpar&i); /*1 parameter logistic regression model*/`

For completeness sake, let's say you want to make theta adjustable, so we can include it in the formula and set it to 0.

```
*want is the final output data set with the probabilities;
data want;
*bpar is the input data set you read in;
set bpar;
*set theta to 0 throughout the process;
theta = 0;
*calculate your probability - will operate on each line of your data;
prob = exp(theta-bpar)/(1+exp(theta - bpar));
*end data step;
run;
*print first 5 results to the results output page;
proc print data=want (obs=5);
run;
```

You DO NOT need a macro. A SAS data step automatically loops over each row and applies the formula to your data set. The code above will do the calculations and put it in a data set called WANT. It will display the first 5 records to the results window due to the PROC PRINT.

@superbug wrote:

Hello SAS expert,

I have a test contains 150 items, item difficulty parameter for each item is as attached. Suppose I now have candidate whose ability level is 0, I named it theta=0. Now on

each of the item, I need to calculate the probability of this candidate correctly answer on each of the time, how should I edit the followingmacro sascode to make it work?

proc import datafile="\bpar.csv" dbms=csv out=bpar replace; run;

%macro f1;

do i=1 to 150; /*from item 1 to item 150*/

prob &i= exp(theta-bpar&i)/(1+exp(theta-bpar&i); /*1 parameter logistic regression model*/

end;

%mend;

%f1;

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

Thanks much for your code and detailed explanation!

I tried the code you suggested and it worked.

My eventual goal is do some iteration using theta=[-20, 20], then stop at certain criteria. That's a very complex process for me. I thought about asking the question from simple step, then go further, but that caused confusion.When you get time, could you please go to the following link to read the **lasted post** and help? Again, thanks a bunch!

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. **Registration is now open through August 30th**. Visit the SAS Hackathon homepage.

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.