I have a function called "p". In this function, there is an object called "marginal" which I need to make recognizable and retrievable outside this function when called. Right now, when I call the object "marginal" outside the function, I get an wrror message that:
object 'marginal' not found
Question: How can I make "marginal" recognizable outside the function?
p <- function(t, N1, N2=NULL, delta) {
efN = ifelse(is.null(N2), N1, N1*N2/(N1+N2))
df = ifelse(is.null(N2), N1 - 1, N1 + N2 - 2)
prior <- function(delta) dnorm(delta, 0, 1)
likelihood <- function(delta) dt(t, df, delta*sqrt(efN) )
marginal <- integrate(function(x) prior(x)*likelihood(x), -Inf, Inf)[[1]]
post <- function(x) prior(x)*likelihood(x) / marginal
return(post(delta))
list(marginal) ## What to use instead of list to object "marginal" recognizable
# outside the function?
}
marginal
object 'marginal' not found