Problems using integrate while writing a likelihood function
I'm trying to write a likelihood function for a distribution which is defined by an integration. I'm using the integrate() function, but when I try to use this in the rest of the function I get the error:
"Error in B(alpha + i, beta + 6 - i)/B(alpha, beta) : non-numeric argument to binary operator"
The value of the integration is for example "9.501501 with absolute error < 0.00078". I've tried to use trunc() but this doesn't help either. I'm relatively new to R, so is there a known solution to this? Any help would be appreciated!
B <- function(a,b){ integrand <- function(t){(t^(a-1))*((1-t)^(b-1))} integrate(integrand,lower=0,upper=1) } betalik <- function(alpha,beta){ likelihood <- 0 Z <- c(37,22,25,29,34,49) for(i in 1:6) likelihood <- likelihood + Z[i]*log((B(alpha+i,beta+6-i))/B(alpha,beta)) return(likelihood)
}
Dorian,
