<?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 Re: Proc nlmixed: about bernoulli distribution in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651790#M31295</link>
    <description>&lt;P&gt;This is going to sound amazingly obtuse, but just for sanity's sake, could you define d1 as d1 = d-1 and run this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc nlmixed data=nn;
parms mu 0.9 sigma 1 gamma0 0.5 gamma1 -0.5 ;  
bounds 0 &amp;lt; sigma;
d1=d - 1: 
sqrt2pi = sqrt(2*constant('pi'));
eta = exp((gamma0 + gamma1*y)) / (1 + exp((gamma0 + gamma1 * y)));

f1 = -log(sigma) - log(sqrt2pi*y) - (log(y)-mu)**2  / (2*sigma**2);
f2 = (eta**d1 )* ((1 - eta)**d1); /*d is binary variable, 1 or 2*/

ll= log (f1 * f2);
model y~general(ll);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Plugging in your starting values, I don't get anything odd to cause this to fail, so maybe the indicator variable is the source.&lt;/P&gt;
&lt;P&gt;This is mystifying me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SteveDenham&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 29 May 2020 17:26:59 GMT</pubDate>
    <dc:creator>SteveDenham</dc:creator>
    <dc:date>2020-05-29T17:26:59Z</dc:date>
    <item>
      <title>Proc nlmixed: about bernoulli distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651700#M31281</link>
      <description>&lt;PRE&gt;proc nlmixed data=lab5;
parms mu 0.9 sigma 1 gamma0 0.5 gamma1 -0.5 ;  
bounds 0 &amp;lt; sigma; 
sqrt2pi = sqrt(2*constant('pi'));
eta = exp((gamma0 + gamma1*y)) / (1 + exp((gamma0 + gamma1 * y)));

f1 = -log(sigma) - log(sqrt2pi*y) - (log(y)-mu)**2  / (2*sigma**2);
f2 = (eta**(d=1) )* ((1 - eta)**(d=2)); /*d is binary variable, 1 or 2*/

ll= log (f1 * f2);
model y~general(ll);
run;
&lt;/PRE&gt;
&lt;P&gt;i want to calculate the parameters for joint distribution.&lt;/P&gt;
&lt;P&gt;f(y,d) = f(y)f(d|y)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;f(y) follows a normal distribution, f(d|y) follow Bernoulli distribution. Then I wrote the syntax above.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;however, there was no results and&amp;nbsp;&lt;STRONG&gt;NOTE: Execution error for observation 1.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is there anyone know the problem and how to deal with it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2020 13:02:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651700#M31281</guid>
      <dc:creator>Jie111</dc:creator>
      <dc:date>2020-05-29T13:02:13Z</dc:date>
    </item>
    <item>
      <title>Re: Proc nlmixed: about bernoulli distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651722#M31285</link>
      <description>&lt;P&gt;I don't see anything that jumps out at me about the syntax, so it might be that your data has something unusual in it.&amp;nbsp; Since the error shows at the first observation, could you post that first record so we could see if something goes to zero, such that the log does not exist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SteveDenham&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2020 13:58:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651722#M31285</guid>
      <dc:creator>SteveDenham</dc:creator>
      <dc:date>2020-05-29T13:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: Proc nlmixed: about bernoulli distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651726#M31286</link>
      <description>&lt;P&gt;Thanks for the reply. I attached the dataset as follows:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jie111_0-1590760943227.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/40146i4A8DA9D47686D7BD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Jie111_0-1590760943227.png" alt="Jie111_0-1590760943227.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2020 14:03:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651726#M31286</guid>
      <dc:creator>Jie111</dc:creator>
      <dc:date>2020-05-29T14:03:25Z</dc:date>
    </item>
    <item>
      <title>Re: Proc nlmixed: about bernoulli distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651734#M31287</link>
      <description>&lt;P&gt;You have some observations with d=0.&amp;nbsp; I think those would result in f2=1, rather than either eta or 1-eta.&amp;nbsp; I don't know if this is what causes the error message, but it seems to me that it results in an incorrect value for f(d|y), which is a problem in itself.&amp;nbsp; What happens if you exclude the observations where d=0?&amp;nbsp; That may not be interesting, but it would let you know if that is a problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SteveDenham&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2020 14:18:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651734#M31287</guid>
      <dc:creator>SteveDenham</dc:creator>
      <dc:date>2020-05-29T14:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: Proc nlmixed: about bernoulli distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651737#M31288</link>
      <description>&lt;P&gt;I did the analyses with deleting those with d=0. however, the Note Execution error for observation 1 is still there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data nn;
set lab5;
if d=0 then delete;
run;

proc nlmixed data=nn;
parms mu 0.9 sigma 1 gamma0 0.5 gamma1 -0.5 ;  
bounds 0 &amp;lt; sigma; 
sqrt2pi = sqrt(2*constant('pi'));
eta = exp((gamma0 + gamma1*y)) / (1 + exp((gamma0 + gamma1 * y)));

f1 = -log(sigma) - log(sqrt2pi*y) - (log(y)-mu)**2  / (2*sigma**2);
f2 = (eta**(d=1) )* ((1 - eta)**(d=2)); /*d is binary variable, 1 or 2*/

ll= log (f1 * f2);
model y~general(ll);
run;&lt;/PRE&gt;
&lt;P&gt;The new dataset:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jie111_0-1590762134595.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/40148iFD8B57BA0C45AB9D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Jie111_0-1590762134595.png" alt="Jie111_0-1590762134595.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2020 14:22:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651737#M31288</guid>
      <dc:creator>Jie111</dc:creator>
      <dc:date>2020-05-29T14:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: Proc nlmixed: about bernoulli distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651761#M31291</link>
      <description>&lt;P&gt;You might want to take a look at the joint modeling capabilities available in PROC GLIMMIX to see if this does what you want. See the example titled "Joint Modeling of Binary and Count Data" in the GLIMMIX documentation which illustrates this capability for data with a binary response and a count response.&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2020 15:25:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651761#M31291</guid>
      <dc:creator>StatDave</dc:creator>
      <dc:date>2020-05-29T15:25:25Z</dc:date>
    </item>
    <item>
      <title>Re: Proc nlmixed: about bernoulli distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651767#M31293</link>
      <description>Thanks for the reply. I would try it.</description>
      <pubDate>Fri, 29 May 2020 15:41:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651767#M31293</guid>
      <dc:creator>Jie111</dc:creator>
      <dc:date>2020-05-29T15:41:42Z</dc:date>
    </item>
    <item>
      <title>Re: Proc nlmixed: about bernoulli distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651790#M31295</link>
      <description>&lt;P&gt;This is going to sound amazingly obtuse, but just for sanity's sake, could you define d1 as d1 = d-1 and run this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc nlmixed data=nn;
parms mu 0.9 sigma 1 gamma0 0.5 gamma1 -0.5 ;  
bounds 0 &amp;lt; sigma;
d1=d - 1: 
sqrt2pi = sqrt(2*constant('pi'));
eta = exp((gamma0 + gamma1*y)) / (1 + exp((gamma0 + gamma1 * y)));

f1 = -log(sigma) - log(sqrt2pi*y) - (log(y)-mu)**2  / (2*sigma**2);
f2 = (eta**d1 )* ((1 - eta)**d1); /*d is binary variable, 1 or 2*/

ll= log (f1 * f2);
model y~general(ll);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Plugging in your starting values, I don't get anything odd to cause this to fail, so maybe the indicator variable is the source.&lt;/P&gt;
&lt;P&gt;This is mystifying me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SteveDenham&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2020 17:26:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651790#M31295</guid>
      <dc:creator>SteveDenham</dc:creator>
      <dc:date>2020-05-29T17:26:59Z</dc:date>
    </item>
    <item>
      <title>Re: Proc nlmixed: about bernoulli distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651805#M31297</link>
      <description>&lt;P&gt;Pay no attention to the previous post. Instead I tried to see what the assignment (d=1) or (d=2) was doing.&amp;nbsp; I got this after simplifying terms.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc nlmixed data=nn;
parms mu 0.9 sigma 1 gamma0 0.5 gamma1 -0.5 ;  
bounds 0 &amp;lt; sigma;
d1 = d -1
sqrt2pi = sqrt(2*constant('pi'));
eta = exp((gamma0 + gamma1*y)) / (1 + exp((gamma0 + gamma1 * y)));

f1 = -log(sigma) - log(sqrt2pi*y) - (log(y)-mu)**2  / (2*sigma**2);
if d1=0 then
f2 = eta: 
else if d1=1 then
f2= ( 1 - eta);


ll= log (f1 * f2);
model y~general(ll);
run&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since eta is a logit, I'm not real sure that the product is the log likelihood of the conditional probability.&amp;nbsp; I am sure I am missing something here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SteveDenham&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2020 17:56:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651805#M31297</guid>
      <dc:creator>SteveDenham</dc:creator>
      <dc:date>2020-05-29T17:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: Proc nlmixed: about bernoulli distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651813#M31299</link>
      <description>&lt;P&gt;Check your loglikelihood. You are using&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ll= log (f1 * f2);&lt;/PRE&gt;
&lt;P&gt;but f1 is negative.&lt;/P&gt;</description>
      <pubDate>Fri, 29 May 2020 18:03:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651813#M31299</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-05-29T18:03:12Z</dc:date>
    </item>
    <item>
      <title>Re: Proc nlmixed: about bernoulli distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651820#M31301</link>
      <description>&lt;P&gt;Yeah, you are right. I just noticed that the syntax for the log-normal distribution is wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks all of you a lot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;attached with the right syntax.&lt;/P&gt;
&lt;PRE&gt;data nn;
  set lab5;
  if d ne 0 then output;
run;

proc nlmixed data=lab5;
parms mu 0.9 sigma 1 gamma0 0.5 gamma1 -0.5 ;  
bounds 0 &amp;lt; sigma; 
sqrt2pi = sqrt(2*constant('pi'));

eta = exp((gamma0 + gamma1*y)) / (1 + exp((gamma0 + gamma1 * y)));

f1 = exp (- (log (y)-mu)**2 / (2*sigma**2) )/ sigma / sqrt2pi / y;
f2 = (eta**(d=1) )* ((1 - eta)**(d=2));

ll= log (f1 * f2);
model y~general(ll);
where d ne 0;
run;
&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 May 2020 18:16:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651820#M31301</guid>
      <dc:creator>Jie111</dc:creator>
      <dc:date>2020-05-29T18:16:30Z</dc:date>
    </item>
    <item>
      <title>Re: Proc nlmixed: about bernoulli distribution</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651821#M31302</link>
      <description>Really thanks for the reply. The syntax for f1 was wrong. I revised it and now it workes well.</description>
      <pubDate>Fri, 29 May 2020 18:17:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Proc-nlmixed-about-bernoulli-distribution/m-p/651821#M31302</guid>
      <dc:creator>Jie111</dc:creator>
      <dc:date>2020-05-29T18:17:30Z</dc:date>
    </item>
  </channel>
</rss>

