Jonathan A
Jonathan A

Reputation: 101

SAS help optimising a linear equation with restrictions

I'd like to be able to solve the following type of problem:

given observed data x(1)....x(n) and a known fixed 'target' b, solve for parameters a0, a1, & a2, which minimise:

b-[a0+a1*x(i)+a1*x(i)^2]*x(i), i=1 to n.

with the restriction that the sum of the [a0+a1*x(i)+a1*x(i)^2] terms equals n, i.e. the mean of [a0+a1*x(i)+a1*x(i)^2] equals 1

I've tried PROC MODEL and PROC NLIN in SAS v9.4 but with no luck. Those modules allow for restrictions on individual parameters, but that is not needed here (a0, a1 & a2 can take any values). Perhaps PROC IML can solve this sort of constrained problem....?

Any help gratefully received!

Upvotes: 3

Views: 253

Answers (1)

Stu Sztukowski
Stu Sztukowski

Reputation: 12909

PROC OPTMODEL is what you're looking for. This will let you add as complex of constraints as you'd like. I'm not entirely sure if this is the exact solution you're looking for without any data to go on.

%let target = 0;

/* Generate data */
data have;
    do i = 1 to 100;
        x = rand('normal');
        output;
    end;
run;

proc optmodel;
    set OBS;
    num x{OBS};

    read data have into OBS = [i]
        x
    ;

    var a0, a1;
    
    con restrict: sum {i in OBS} (a0 * a1*x[i] + a1*x[i]**2) = sum{i in OBS} 1;

    min objective = sum {i in OBS} (&target. - (a0 + a1*x[i] + a1*x[i]**2)*x[i]);

    solve;

    print a0 a1;
quit;

Upvotes: 2

Related Questions