I am getting different results (close but not exact the same) from R GLM and manual solving logistic regression optimization. Could anyone tell me where is the problem?
BFGS does not converge? Numerical problem with finite precision?
Thanks
# logistic regression without intercept
fit=glm(factor(vs) ~ hp+wt-1, mtcars, family=binomial())
# manually write logistic loss and use BFGS to solve
x=as.matrix(mtcars[,c(4,6)])
y=ifelse(mtcars$vs==1,1,-1)
lossLogistic <- function(w){
L=log(1+exp(-y*(x %*% w)))
return(sum(L))
}
opt=optim(c(1,1),lossLogistic, method="BFGS")

optim? – Matthew Drury Aug 14 '16 at 01:51optimdoes not converge? – Haitao Du Aug 14 '16 at 02:09glmis tighter than that foroptim. – Matthew Drury Aug 14 '16 at 02:15control = list(maxit = 1e8, abstol=1e-8, reltol=1e-8)still not help. – Haitao Du Aug 14 '16 at 02:19mtcars$hpis several hundred, may be afterexp, there are problems... – Haitao Du Aug 14 '16 at 02:59nlmis returning another similar but not exact the same value. – Haitao Du Aug 14 '16 at 03:36