######################################################## # This function takes data, and pos (marker positions) # log-likelihood function is maximized over delta and lambda. # nlminb is used for maximization. # It returns max(log-likelihood), mle of delta, mle of lambda, and # message from nlminb function mle.null<-function(data, pos) { profile <- nlminb(start = c(0.5, 0), mloglik.theta.null, data = data, pos = pos, lower = c(0.001, - Inf), upper = c(0.999, Inf)) #see below for the definition of mloglik.theta #leta=log(1/lambda) loglik.null <- - profile$objective #log-likelihood theta <- profile$parameters #optimized theta value messages <- profile$message deltahat.null <- theta[1] letahat.null <- theta[2] lambdahat.null <- 1/exp(letahat.null) return(list(loglik.null = loglik.null, deltahat.null = deltahat.null, lambdahat.null = lambdahat.null, messages = messages)) } ######################################################## # This function computes (-(log-likelihood)) under the null hypo, # which is exactly same as what mloglik.null does. # It is just modified to be used as an object function of nlminb. mloglik.theta.null<- function(theta,data,pos) { return (mloglik.null(leta=theta[2],delta=theta[1],data=data,pos=pos)) } ######## Examples ###################################### pro<-dget("pro.data") thy<-dget("thy.data") fjp<-dget("fjp.data") pro.mle.null<-mle.null(data=pro$data, pos=pro$pos) thy.mle.null<-mle.null(data=thy$data, pos=thy$pos) fjp.mle.null<-mle.null(data=fjp$data, pos=fjp$pos) ########################################################