data have1;
input bucket$ probability ;
cards;
first 0.0025
second 0.37
third 0.53
fourth 0.89
;
run;
data have2;
input bucket$ z;
cards;
first -2.81
second -0.60
third -0.15
fourth 0.69
;
run;
Hi Everyone,
I have 2 data sets as above. I want to calculate a value(v) as
v = cdf('normal', z+c)
where z = z-value from table have2
c = constant which we will start with 1 and continuously changing it to get the minimum sum of squares difference of V and probability( from table have1).
We are interested in getting the value of C (initially equals 1) such that (V - probability)^2 is minimised.
If you have SAS/OR ,could try the following code . or calling @RobPratt
Or if you have SAS/IML ,could try many optimize function like CALL NLPNRA () ,CALL NLPLM() .
@Rick_SAS wrote may blogs about it.
data have1;
input bucket$ probability ;
cards;
first 0.0025
second 0.37
third 0.53
fourth 0.89
;
run;
data have2;
input bucket$ z;
cards;
first -2.81
second -0.60
third -0.15
fourth 0.69
;
run;
proc optmodel;
set <str> B;
num p{B} ;
num z{B};
read data have1 into B=[bucket] p=probability;
read data have2 into B=[bucket] z=z;
var c ;
min min=sum{i in B} (cdf('normal', z[i]+c)-p[i])**2;
solve ;
print c.sol;
quit;
Looks correct to me. I have only two suggestions.
1. Change the second READ DATA statement as follows:
read data have2 into [bucket] z;
The index set B has already been populated from the previous READ DATA statement, and z=z is redundant.
2. Use the INIT option to initialize c, as requested by the user:
var c init 1;
OK. Here is. The same result with SAS/OR .
data have1;
input bucket$ probability ;
cards;
first 0.0025
second 0.37
third 0.53
fourth 0.89
;
run;
proc sort data=have1;by bucket;run;
data have2;
input bucket$ z;
cards;
first -2.81
second -0.60
third -0.15
fourth 0.69
;
run;
proc sort data=have2;by bucket;run;
data want;
merge have1 have2;
by bucket;
run;
proc nlin data=want;
parms c 1;
mean=cdf('normal', z+c);
model probability=mean;
run;
Registration is open! SAS is returning 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. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.