Skip to content

Instantly share code, notes, and snippets.

@Guibrich
Created May 31, 2013 23:21
Show Gist options
  • Save Guibrich/5688600 to your computer and use it in GitHub Desktop.
Save Guibrich/5688600 to your computer and use it in GitHub Desktop.
# Lik
lik.logit <- function(init,y,x)
{
x = as.matrix(x)
cste<- rep(1,length(x[,1]))
x <- cbind(cste,x) # Matrix of predictors
d <- init[1:ncol(x) ] # Number of parameters
xd<- x%*%d # Produit matriciel
sum( y*log(1+exp(-xd)) + (1-y)*log(1+exp(xd)))
}
fit.logis <-function(y,x)
{
init=c(0,1)
logit.opt <- optim(init,lik.logit,y=y,x=x,hessian = T)
coef.est <- logit.opt$par
varcov = solve(logit.opt$hessian)
et.est = sqrt(diag(varcov))
res<-data.frame(cbind(round(coef.est,3), round(et.est,3))) # Estimation des coefs + ecarts-type
rownames(res)<-letters[1:length(coef.est)]
colnames(res)<-c("coef.est", "std.err")
return(res)
}
Test = fit.logis(y=don$GROUPE,x=don$TAILLE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment