diff --git a/selectiveCI/R/pointEstimates.R b/selectiveCI/R/pointEstimates.R index 34d7ccc..23c91f5 100644 --- a/selectiveCI/R/pointEstimates.R +++ b/selectiveCI/R/pointEstimates.R @@ -1,12 +1,47 @@ -ConditionalPointML <- function(x,sigsq,cutoff) { +ConditionalPointML <- function(x,cutoff,sigsq,init.mu=NA,max.iter=1000,tol=10^-5) { + comp.power <- function(mu,sig,cutoff) 1-pnorm(cutoff,mean=mu,sd=sig)+pnorm(-cutoff,mean=mu,sd=sig) + phi <- function(c) dnorm(c,mean=muhat,sd=sig) + + comp.grad <- function(x,mu,sig,cutoff) { + Qc <- comp.power(mu,sig,cutoff) + (x-mu)/sig^2 - (phi(cutoff)-phi(-cutoff))/Qc + } + comp.hess <- function(x,mu,sig,cutoff) { + Qc <- comp.power(mu,sig,cutoff) + hess <- Qc*(phi(cutoff)*(cutoff-mu)/sig^2+phi(-cutoff)*(cutoff+mu)/sig^2) + + (phi(cutoff)-phi(-cutoff))^2 + hess <- -hess/Qc^2 + hess <- hess-1/sig^2 + return(hess) + } + + ## If x is a vector then replace x with the mean and the variance with the variance of the mean + x <- mean(x) + sig <- sqrt(sigsq/length(x)) + if(abs(x)