Operations Research topics: SAS/OR,
SAS Optimization, and SAS Simulation Studio

Proc OptModel Help on Maximize Correlation

Accepted Solution Solved
Reply
Contributor
Posts: 21
Accepted Solution

Proc OptModel Help on Maximize Correlation

Hi guys,

Need your help. i am trying to maximize two variables' (dep and org*s) correlaton by changing the var (0<s<0.8). The below program (1st) works fine when i put [org*s] in the correlation formula. However, if i create a new variable, ads = org*s, the program doesn't work anymore. The reason i need to create a new variable ads is that there will be more calculations involved and i don't want to write an extreme long function in max procesure. i need to break out the long function to several pieces. i remember the old Proc NLP can do it.

This may be a very naiive question but do need your help. thx. Here are the two programs. Again, the 2nd doesn't work and i don't know how to fix it.

Thanks again!

Fisher

data cor;

input org dep;

cards;

11785895 7.42

2335492 7.58

2345245 7.58

2392912 7.53

12755890 7.63

2918402 7.67

2773183 7.68

2824198 7.65

12263433 7.53

;

run;

* program 1 that works;

proc optmodel;

set w;

number org{w};

number ads{w};

number dep{w};

var s{w} >= 0 <= .8 init 1;

read data cor into w = [_n_] org dep;

max correlation = (10*sum{i in w}((org*s)*dep) - (sum{i in w}((org*s))) * (sum{i in w}(dep)))

     / (sqrt(10*sum{i in w}((org*s)^2) - (sum{i in w}((org*s)))^2) * sqrt(10*sum{i in w}(dep^2) - (sum{i in w}(dep))^2));

solve;

print s correlation;

quit;

* program 2 that doesn't work;


proc optmodel;
set w;
number org{w};
number ads{w};
number dep{w};
var s{w} >= 0 <= .8 init 1;
read data cor into w = [_n_] org dep;

    for {i in w} ads = org * s;

max correlation = (10*sum{i in w}(ads*dep) - (sum{i in w}(ads)) * (sum{i in w}(dep)))
     / (sqrt(10*sum{i in w}(ads^2) - (sum{i in w}(ads))^2) * sqrt(10*sum{i in w}(dep^2) - (sum{i in w}(dep))^2));
solve;
print s correlation;
quit;


Accepted Solutions
Solution
‎03-26-2012 01:01 PM
SAS Employee
Posts: 448

Re: Proc OptModel Help on Maximize Correlation

In program 2, you have declared ads as a numeric parameter, so the resulting objective is constant.  Instead, you should declare ads as an implicit variable (and omit the FOR loop) as follows:

impvar ads {i in w} = org * s;

View solution in original post


All Replies
Solution
‎03-26-2012 01:01 PM
SAS Employee
Posts: 448

Re: Proc OptModel Help on Maximize Correlation

In program 2, you have declared ads as a numeric parameter, so the resulting objective is constant.  Instead, you should declare ads as an implicit variable (and omit the FOR loop) as follows:

impvar ads {i in w} = org * s;

Contributor
Posts: 21

Proc OptModel Help on Maximize Correlation

Thanks a lot RobPratt. It really helps. i may need to bother you again when i have more questions (high chanceSmiley Happy)

Fisher

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 452 views
  • 0 likes
  • 2 in conversation