449792 (2) [Avatar] Offline
Hello All,

Can some kind person help me out and explain the following R code. i'm a bit lost. any help would be greatly appreciated.
thank you. I'm looking at the mkPredC function within in the function there is a pPosWv variable which goes as follows.

pPosWv<- (Tab[pos,]+1.0e-3*pPos/ (colSums(vTab)+1.0e-3)

Can someone please explain why for this variable we need to + 1.0e-3. Rather a simple question for most but like i said any help would be really appreciated.
john.mount (78) [Avatar] Offline
Sorry you are having trouble. Hopefully this will help.

The 1.0e-3 is what is called a "smoothing term." I am sorry it isn't named or explained in listing 6.4 on page 120 (where I assume the code snipped is from). The idea is named on page 136 in Listing 6.23 and then explained in a call-out titled "Smoothing" on page 137. So if you skip ahead to the call-out on page 137 things may make a bit more sense. Obviously I wish we had discussed this closer to the first use.

Very roughly the idea is (a+1.0e-3)/(b+1.0-3) is fairly close to a/b in most cases and is safe on additional corner cases (such as a=0 and b=0). So with smoothing present you don't have to check if such corner cases are possible are not (as you get nice uninformative ratios equal to 1 in that case). In a bit finer detail it also means "don't react as much when you have very little evidence" which is a good principle.
449792 (2) [Avatar] Offline
Hi John, Thank you for clearing that up and your swift response.