[R] optimize()
Ben Bolker
bbolker at gmail.com
Fri Dec 9 22:44:30 CET 2011
dnz.marcio <dnz.marcio <at> gmail.com> writes:
>
[snip]
> ##### 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
>
This is actually fairly subtle: you're running into a partial
matching problem with the "interval" argument of optimize().
I added interval=NULL to the call and got a little farther,
but then I ran into an error because I hadn't specified the
"times" variable. Presumably you have defined a "times" variable?
Ben Bolker
More information about the R-help
mailing list