[R] help with likelihood contour plot
Murray Jorgensen
maj at stats.waikato.ac.nz
Mon Mar 17 23:09:14 CET 2003
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
--
Dr Murray Jorgensen http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: maj at waikato.ac.nz Fax 7 838 4155
Phone +64 7 838 4773 wk +64 7 849 6486 home Mobile 021 1395 862
More information about the R-help
mailing list