BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
aoifeoneill
Fluorite | Level 6

Hi,

 

I would like to compare a number of models based on their log-likelihood values. The log-likelihood values are saved in one dataset as follows:

LogL.PNG

A difference of 0.01 between two log-likelihood values is considered to be the same model. I would also like to print the % or number of models that were the same and what observation number it was.

 

Does anyone know if this is possible? Any help with this would be greatly appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

Hi,

 

I think no need to compare each value with all the ramaining ones. First sort data based log_likelihood values then use the syntax. It will make the comparison easier.

 

proc sort data=have;

by  log_likelihood;

run;

 

data want;
set have;
diff = log_likelihood - lag(log_likelihood);
if _n_>1 then do;
if abs(diff)<=0.001 then observation=_n_;
end;
run;

View solution in original post

4 REPLIES 4
stat_sas
Ammonite | Level 13

Hi,

 

Something like this?

 

data want;
set have;
diff = log_likelihood - lag(log_likelihood);
if _n_>1 then do;
   if abs(diff)<=0.001 then observation=_n_;
end;
run;

aoifeoneill
Fluorite | Level 6

@stat_sas to determine the number of models that are the same do you not need to compare likelihood 1 with all other likelihood values, likelihood 2 with all other likelihood values, and so on. Not just the value directly following... maybe I need to loop this?

stat_sas
Ammonite | Level 13

Hi,

 

I think no need to compare each value with all the ramaining ones. First sort data based log_likelihood values then use the syntax. It will make the comparison easier.

 

proc sort data=have;

by  log_likelihood;

run;

 

data want;
set have;
diff = log_likelihood - lag(log_likelihood);
if _n_>1 then do;
if abs(diff)<=0.001 then observation=_n_;
end;
run;

aoifeoneill
Fluorite | Level 6
Yes of course, thanks @stat_sas !

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1464 views
  • 0 likes
  • 2 in conversation