R/base_logLik.R

Defines functions .logLik

# calculate log likelihood for MOSAiCS

.logLik <- function( mosaicsEst, tagCount, pNfit, k=3, signalModel="2S" )
{              
    switch( signalModel,
        "1S" = {
            # one signal model
            
            pi0 <- mosaicsEst@pi0            
            fitMD <- .margDist_1S( mosaicsEst=mosaicsEst, 
                tagCount=tagCount, pNfit=pNfit, k=k )
            
            loglik <- sum( log( pi0 * fitMD$MDZ0 + ( 1 - pi0 ) * fitMD$MDZ1 ) )
        },
        "2S" = {
            # two signal model
            
            pi0 <- mosaicsEst@pi0
            p1 <- mosaicsEst@p1            
            fitMD <- .margDist_2S( mosaicsEst=mosaicsEst, 
                tagCount=tagCount, pNfit=pNfit, k=k )
                
            loglik <- sum( log( pi0 * fitMD$MDZ0 + 
            	( 1 - pi0 ) * ( fitMD$MDZ1 * p1 + fitMD$MDZ2 * (1-p1) ) ) )
        }
    )
    
    return(loglik)
}
dongjunchung/mosaics documentation built on March 1, 2020, 3:44 a.m.