########################################################################
# Logit function
#
# Return the logit of a functon or its inverse.
logit <- function(x) log(x/(1-x))
expit <- function(x) exp(x)/(1 + exp(x))
#################################
# One Dimensional Optimization
#
# Perform an initial search inside a grid of points before performing
# standard optimization routine.
#
# param res Number of subdivisions.
# param ... See basic function optimize
goptimize <- function(fn, interval, res = 20, ...){
igrid <- seq(interval[1],interval[2], len = res)
id <- which.min(sapply(igrid,fn))
if(id == 1) bnd0 <- igrid[1:2]
else if(id == res) bnd0 <- igrid[c(res-1,res)]
else bnd0 <- igrid[c(id-1,id)]
return(optimize(fn, bnd0, ...))
}
############################################
#
#
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.