Murray Jorgensen wrote:
Can some kind person point out my error here? I'm trying to set up a grid for a countour plot of a likelihood function.
> u <- rnorm(20,9.5,2.5)
> # sample of size 20 from N(9.5,2.5^2)
> loglik <- function(th1,th2) {
+ n <- length(u)
+ -(n/2)*log(2*pi*th2^2)-0.5*sum((u-th1)^2/th2^2)
+ }
> x <- seq(4.5,14.5,len=50)
> y <- seq(0.5,6,len=50)
> f <- outer(x, y, loglik(x,y))
Error in match.fun(FUN) : not function, character, or symbol: "loglik(x, y)"
In addition: Warning message:
longer object length
is not a multiple of shorter object length in: u - th1
> loglik(9,2)
[1] -44.56294
> is.function(loglik)
[1] TRUE
Thanks,
Murray
Murray, From ?outer:
Details:
`FUN' must be a function (or the name of it) which expects at least two arguments and which operates elementwise on arrays.
Thus, use "loglik" and not "loglik(x,y)", as in:
outer(x,y,loglik)
Regards, Sundar
______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help