Hallo, I'm working with the mle function and I would like to ask you a couple of questions. My goal is to construct the historical value of v1(t), v2(t) and v3(t) using the maximum likelihood estimation. So, I need to optimize the following log-likelihood: sum(E1_f[t,]*(v1*teta1[] + v2*teta2[] + v3*teta3[]) - E_f[t,]*log(1 + exp(v1*teta1[] + v2*teta2[] + v3*teta3[]))) (E_f and E1_f are 136x111 matrices and teta1,teta2 and teta3 are 111x1 vectors). By writing the code below, I just obtain the result for t=1. ################ library(stats4) likelihood <- function(v1,v2,v3){ for (t in 1:136){ return(-(sum(E1_f[t,]*(v1*teta1[] + v2*teta2[] + v3*teta3[]) - E_f[t,]*log(1 + exp(v1*teta1[] + v2*teta2[] + v3*teta3[]))))) } } L_f <- mle(minuslog=likelihood, start=list(v1=1, v2=2, v3=3)) x <- summary(L_f) ################ What should I change in the code? And how can I store the values of v1(t), v2(t) and v3(t) in 3 vectors, in order to use them after? Thank you very much. Roger