[R] optimize()
dnz.marcio
dnz.marcio at gmail.com
Thu Dec 8 20:27:13 CET 2011
Hi!
I have a difficulty in the use of function optimize(). Could you help me?
I want to maximize this function:
##### Logaritmo da distribuição condicional de alpha[i]
lp_alphai <- function(alphai, i, beta, tau, N){
t1 <- (N[i+1] - N[i])*log(alphai)
t2 <- - (N[i+1] - N[i])*alphai*log(beta[i])
t3 <- (alphai - 1)*sum(log(times[(N[i] + 1):N[i+1]]))
t4 <- - exp(alphai*(log(tau[i+1]) - log(beta[i])))
t5 <- 0
if(i > 1)
t5 <- exp(alphai*(log(tau[i]) - log(beta[i])))
v <- t1 + t2 + t3 + t4 + t5
return(v)
}
Then, I've done:
optimize(lp_alphai, lower = 0, upper = 10, maximum = TRUE, tol =
0.00000000001, i = 1, beta = 125, tau = c(0,1900), N = c(0,236))$maximum
However, I face this problem:
Error in i + 1 : 'i' missing
I've been in this problem all this day, but, I can't find a solution.
Thank you.
--
View this message in context: http://r.789695.n4.nabble.com/optimize-tp4173920p4173920.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list