Re: Re: indeterminate and infinity expressions
- To: mathgroup at smc.vnet.net
- Subject: [mg67699] Re: [mg67615] Re: indeterminate and infinity expressions
- From: Søren Merser <merser at image.dk>
- Date: Wed, 5 Jul 2006 04:17:30 -0400 (EDT)
- References: <e85es4$k8e$1@smc.vnet.net> <200607021027.GAA08948@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi First my most sincerly apologies for the typos! I was unsuccefully trying to make my problem clearer. I'll try to rephrase it: Want to calculate the residaul deviance according to the following formula: Some data: dep = {1, 0, 1, 0}; (* vector with fitted values *) yhat = {.012, .123, .23, .563}; (* vector with fitted values *) Problem: Sign[dep-yhat] Sqrt[dep Log[dep/yhat] + (dep-yhat) Log[(1-dep)/(1-yhat)]] My solution: expr1 = dep Log[dep/yhat] /. Indeterminate -> 0; expr2 = (1 - dep) Log[(1 - dep)/(1 - yhat)] /. Indeterminate -> 0; Sign[dep - yhat] Sqrt[2(expr1 + expr2)] Regards Soren ----- Original Message ----- From: "David W.Cantrell" <DWCantrell at sigmaxi.org> To: mathgroup at smc.vnet.net Subject: [mg67699] [mg67615] Re: indeterminate and infinity expressions > Søren_Merser <merser at image.dk> wrote: >> I need to evaluate the expression below: >> >> In[1]:= Log[(#/yhat)] + (1-#) Log[(1-#)/(1-yhat)] & /@ {0,1} /. >> yhat->123 Out[1]= {Indeterminate, -Infinity} > > First, Søren, if you really want others to help you, please be much more > careful in your posting. There were several errors. > > Evaluating your In[1], exactly as you gave it, returns > > {-Infinity, Indeterminate}, which is perfectly correct. > > Your claimed Out[1] had the list in the wrong order. > > But looking at your In[2], which is missing /. BTW, it seems that your > In[1] was missing an initial # and that yhat was to have been replaced > by .123, rather than 123 . > > To get what you want, use Limit. Here's my suggestion: > > In[8]:= Limit[x Log[(x/yhat)] + (1-x) Log[(1-x)/(1-yhat)], x->#] > & /@ {0,1} /. yhat -> .123 > > Out[8]= {0.131248,2.09557} > > David > >> Depending on the value of #, I get Infinity and Inderterminate results. >> >> To get the wanted answer I've to split the expression into two parts >> >> In[2]:= ans1 = # Log[#/yhat] & /@ {0, 1} yhat -> .123 >> Out[2]= {Indeterminate, 2.09557} >> >> In[3]:= ans2 = (1-#) Log[(1-#)/(1-yhat)] & /@ {0, 1} /. yhat -> .123 >> Out[3]= {0.131248, Indeterminate} >> >> In[4]:= Max[#] & /@ ({ans1, ans2} /. Indeterminate -> 0) >> Out[4]= {2.09557, 0.131248} >> >> Now, is there an easier way to do it? >> >> Regards Soren >
- References:
- Re: indeterminate and infinity expressions
- From: "David W.Cantrell" <DWCantrell@sigmaxi.org>
- Re: indeterminate and infinity expressions