#' Probit estimation
#'
#' This function estimates a tobit model for a lieft censoring at 0. Its arguments are a vector for the dependent variable (y) and a matrix for the explanatory variables (X).
#'
#' It uses the low memory BFGS algorithm from the optim function. The starting values are the coefficients of a linear model and 1 for the sd.
#' @examples
#' set.seed(1)
#' X=matrix(rnorm(20),ncol=2)
#' y=pmax(X %*% c(2,1) +rnorm(10),0)
#' mytobit(X = X,y = y)
myprobit<- function(X,y){
X=cbind(rep(1,nrow(X)),X)
res <- optim(
par=c(coef( lm(y~.,data=as.data.frame(cbind(y,X[,-1]))) ) ,1),
fn=loglik_probit,
X=X,
y=y,
method = "BFGS",
control = list(fnscale = -1), #maxmization
# lower=c(rep(-Inf,ncol(X)-1),1e-10)
)
res$fitted.val <- pnorm(X %*% res$par[-length(res$par)]) %>%
round(digits=2)
return(res)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.