<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic ERROR in using NLPNRA and PROC IML for MLE of custom function in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ERROR-in-using-NLPNRA-and-PROC-IML-for-MLE-of-custom-function/m-p/926351#M6204</link>
    <description>&lt;P&gt;Dear community,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am trying to follow&amp;nbsp;&lt;/SPAN&gt;&lt;A href="http://blogs.sas.com/content/iml/2011/10/12/maximum-likelihood-estimation-in-sasiml/" target="_self" rel="nofollow noreferrer"&gt;Rick Wicklin's example of using NLPNRA with PROC IML for maximum likelihood estimation&lt;/A&gt;&lt;SPAN&gt;. Unfortunately, I am encountering an error with NLPNRA.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am trying to use this script to find the MLE of a two parameter, two variable custome probability mass function:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;/*Define Density Function*/&lt;BR /&gt;&lt;BR /&gt;data multivariate_data;&lt;BR /&gt;call streaminit(5);&lt;BR /&gt;%let theta1 = 5;&lt;BR /&gt;%Let theta2 = 3;&lt;BR /&gt;	array Xi[2];&lt;BR /&gt;    do i = 1 to 1000;&lt;BR /&gt;        do j=1 to 2;&lt;BR /&gt;        Xi[j]= rand('Bernoulli',.5);&lt;BR /&gt;        end;&lt;BR /&gt;  	N=exp(&amp;amp;theta1*(Xi[1]+Xi[2])+&amp;amp;theta2*Xi[1]*Xi[2]); /*numerator of density function*/&lt;BR /&gt;  	D=(1+2*exp(&amp;amp;theta1)+exp(2*&amp;amp;theta1+&amp;amp;theta2)); /*denominator of density function*/&lt;BR /&gt;  	P=N/D;&lt;BR /&gt;        output;&lt;BR /&gt;        &lt;BR /&gt;    end;&lt;BR /&gt;    drop i j;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc print data= multivariate_data;&lt;BR /&gt;var P;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc iml;&lt;BR /&gt;use multivariate_data;&lt;BR /&gt;read all var {"Xi1","Xi2"} into x;&lt;BR /&gt;close multivariate_data;&lt;BR /&gt;/* write the log-likelihood function the distribution of interest */&lt;BR /&gt;start LogLik(param) global (x);&lt;BR /&gt;   theta1 = param[1];&lt;BR /&gt;   theta2 = param[2];&lt;BR /&gt;   n = nrow(x);&lt;BR /&gt;   return ( theta1*(sum(Xi1)+sum(Xi2)) + theta2*sum(Xi1)*sum(Xi2)-n*log(1+2*exp(theta1)+exp(2*theta1+theta2)) );&lt;BR /&gt;finish LogLik;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;p = {2 4};/* initial guess for solution */&lt;BR /&gt;con = {., .}; /* Upper bounds for parameters (if any) */&lt;BR /&gt;optn = {1,  /* find max of function       */&lt;BR /&gt;        3}; /* print a lot of output      */&lt;BR /&gt;call nlpnra(rc,xres,"LogLik",p,optn,con);&lt;BR /&gt;&lt;BR /&gt;However, after running this code I receive an error code following the nlpnra call that says error in argument BLC. After reviewing the documentation I thought that&lt;BR /&gt;BLC was an option argument so I am confused as to why I am receiving this error. Anyt help would be much appreciated.&lt;BR /&gt;Thanks!&lt;/PRE&gt;</description>
    <pubDate>Mon, 29 Apr 2024 17:42:04 GMT</pubDate>
    <dc:creator>roystriker77r</dc:creator>
    <dc:date>2024-04-29T17:42:04Z</dc:date>
    <item>
      <title>ERROR in using NLPNRA and PROC IML for MLE of custom function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ERROR-in-using-NLPNRA-and-PROC-IML-for-MLE-of-custom-function/m-p/926351#M6204</link>
      <description>&lt;P&gt;Dear community,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am trying to follow&amp;nbsp;&lt;/SPAN&gt;&lt;A href="http://blogs.sas.com/content/iml/2011/10/12/maximum-likelihood-estimation-in-sasiml/" target="_self" rel="nofollow noreferrer"&gt;Rick Wicklin's example of using NLPNRA with PROC IML for maximum likelihood estimation&lt;/A&gt;&lt;SPAN&gt;. Unfortunately, I am encountering an error with NLPNRA.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am trying to use this script to find the MLE of a two parameter, two variable custome probability mass function:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;/*Define Density Function*/&lt;BR /&gt;&lt;BR /&gt;data multivariate_data;&lt;BR /&gt;call streaminit(5);&lt;BR /&gt;%let theta1 = 5;&lt;BR /&gt;%Let theta2 = 3;&lt;BR /&gt;	array Xi[2];&lt;BR /&gt;    do i = 1 to 1000;&lt;BR /&gt;        do j=1 to 2;&lt;BR /&gt;        Xi[j]= rand('Bernoulli',.5);&lt;BR /&gt;        end;&lt;BR /&gt;  	N=exp(&amp;amp;theta1*(Xi[1]+Xi[2])+&amp;amp;theta2*Xi[1]*Xi[2]); /*numerator of density function*/&lt;BR /&gt;  	D=(1+2*exp(&amp;amp;theta1)+exp(2*&amp;amp;theta1+&amp;amp;theta2)); /*denominator of density function*/&lt;BR /&gt;  	P=N/D;&lt;BR /&gt;        output;&lt;BR /&gt;        &lt;BR /&gt;    end;&lt;BR /&gt;    drop i j;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc print data= multivariate_data;&lt;BR /&gt;var P;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc iml;&lt;BR /&gt;use multivariate_data;&lt;BR /&gt;read all var {"Xi1","Xi2"} into x;&lt;BR /&gt;close multivariate_data;&lt;BR /&gt;/* write the log-likelihood function the distribution of interest */&lt;BR /&gt;start LogLik(param) global (x);&lt;BR /&gt;   theta1 = param[1];&lt;BR /&gt;   theta2 = param[2];&lt;BR /&gt;   n = nrow(x);&lt;BR /&gt;   return ( theta1*(sum(Xi1)+sum(Xi2)) + theta2*sum(Xi1)*sum(Xi2)-n*log(1+2*exp(theta1)+exp(2*theta1+theta2)) );&lt;BR /&gt;finish LogLik;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;p = {2 4};/* initial guess for solution */&lt;BR /&gt;con = {., .}; /* Upper bounds for parameters (if any) */&lt;BR /&gt;optn = {1,  /* find max of function       */&lt;BR /&gt;        3}; /* print a lot of output      */&lt;BR /&gt;call nlpnra(rc,xres,"LogLik",p,optn,con);&lt;BR /&gt;&lt;BR /&gt;However, after running this code I receive an error code following the nlpnra call that says error in argument BLC. After reviewing the documentation I thought that&lt;BR /&gt;BLC was an option argument so I am confused as to why I am receiving this error. Anyt help would be much appreciated.&lt;BR /&gt;Thanks!&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Apr 2024 17:42:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ERROR-in-using-NLPNRA-and-PROC-IML-for-MLE-of-custom-function/m-p/926351#M6204</guid>
      <dc:creator>roystriker77r</dc:creator>
      <dc:date>2024-04-29T17:42:04Z</dc:date>
    </item>
    <item>
      <title>Error in using NLPNRA and PROC IML for MLE of a custom function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ERROR-in-using-NLPNRA-and-PROC-IML-for-MLE-of-custom-function/m-p/926383#M6206</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Dear community,&amp;nbsp; I am trying to follow&amp;nbsp;Rick Wicklin's example of using NLPNRA with PROC IML for maximum likelihood estimation. Unfortunately, I am encountering an error with NLPNRA. I am trying to use this script to find the MLE of a two parameter, two variable custome probability mass function:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;/*Define Density Function*/&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;data multivariate_data;&lt;/DIV&gt;&lt;DIV&gt;call streaminit(5);&lt;/DIV&gt;&lt;DIV&gt;%let theta1 = 5;&lt;/DIV&gt;&lt;DIV&gt;%Let theta3 = 3;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;array Xi[2];&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; do i = 1 to 1000;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; do j=1 to 2;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Xi[j]= rand('Bernoulli',.5);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; N=exp(&amp;amp;theta1*(Xi[1]+Xi[2])+&amp;amp;theta3*Xi[1]*Xi[2]);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; D=(1+2*exp(&amp;amp;theta1)+exp(2*&amp;amp;theta1+&amp;amp;theta3));&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; P=N/D;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; output;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; end;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; drop i j;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc print data= multivariate_data;&lt;/DIV&gt;&lt;DIV&gt;var P;&lt;/DIV&gt;&lt;DIV&gt;RUN;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc iml;&lt;/DIV&gt;&lt;DIV&gt;use multivariate_data;&lt;/DIV&gt;&lt;DIV&gt;read all var {"Xi1","Xi2"} into x;&lt;/DIV&gt;&lt;DIV&gt;close multivariate_data;&lt;/DIV&gt;&lt;DIV&gt;/* write the log-likelihood function the distribution of interest */&lt;/DIV&gt;&lt;DIV&gt;start LogLik(param) global (x);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;theta1 = param[1];&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;theta3 = param[2];&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;n = nrow(x);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;return ( theta1*(sum(Xi1)+sum(Xi2)) + theta3*sum(Xi1)*sum(Xi2)-n*log(1+2*exp(theta1)+exp(2*theta1+theta3)) );&lt;/DIV&gt;&lt;DIV&gt;finish LogLik;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;p = {2 4};/* initial guess for solution */&lt;/DIV&gt;&lt;DIV&gt;con = {., .}; /* Upper bounds for parameters (if any) */&lt;/DIV&gt;&lt;DIV&gt;optn = {1,&amp;nbsp; /* find max of function&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;*/&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3}; /* print a lot of output&amp;nbsp; &amp;nbsp; &amp;nbsp; */&lt;/DIV&gt;&lt;DIV&gt;call nlpnra(rc,xres,"LogLik",p,optn,con);&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;However, after running this code I receive an error code following the nlpnra call that says error in argument BLC. After reviewing the documentation I thought that BLC was an option argument so I am confused as to why I am receiving this error. Anyt help would be much appreciated. Thanks!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2024 19:45:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ERROR-in-using-NLPNRA-and-PROC-IML-for-MLE-of-custom-function/m-p/926383#M6206</guid>
      <dc:creator>roystriker77r</dc:creator>
      <dc:date>2024-04-29T19:45:24Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR in using NLPNRA and PROC IML for MLE of custom function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ERROR-in-using-NLPNRA-and-PROC-IML-for-MLE-of-custom-function/m-p/926386#M6205</link>
      <description>&lt;P&gt;Yes, the BLC parameter is optional, and you opted to specify it by using the CON argument. But the CON argument is not the correct format. If you don't want a constrained optimization, then omit the CON argument. Otherwise, specify it correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't know what distribution you are trying to fit, but I want to point out that your input data set only has three unique pieces of information:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;When (x1,x2)=(0,0), the&amp;nbsp;value P(x1,x2)=2.259E-6&lt;/LI&gt;
&lt;LI&gt;When (x1,x2)=(1,1), the&amp;nbsp;value P(x1,x2)=0.999&lt;/LI&gt;
&lt;LI&gt;When (x1,x2)=(1,0) or (0,1), the&amp;nbsp;value P(x1,x2)=0.00033&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;I also do not think you can perform an optimization in this function because it is unbounded. For example, look at the cross section for theta1=3 as you let theta2 vary:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* visualize the LL when theta1=3 */
theta1 = 3;
theta2 = T( do(0,8,0.1) );
LL = j(nrow(theta2), 1);
do i = 1 to nrow(theta2);
   LL[i] = LogLik( theta1 || theta2[i] );
end;
title "LL(3, theta2)";
call series(theta2, LL) grid={x y};
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Rick_SAS_0-1714420779568.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96028iDA7433DAC8E1394F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Rick_SAS_0-1714420779568.png" alt="Rick_SAS_0-1714420779568.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;As you can see, the objective function does not have a maximum. I suggest you check the computations that you used to construct the LogLik function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2024 20:00:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ERROR-in-using-NLPNRA-and-PROC-IML-for-MLE-of-custom-function/m-p/926386#M6205</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2024-04-29T20:00:31Z</dc:date>
    </item>
  </channel>
</rss>

