My objective is to evaluate and to plot the following log-likelihood function with two parameters:
set.seed(123)
N = 100
x = 4*rnorm(N)
y = 0.8*x + 2*rnorm(N);
LogL <- function(param,x,y,N){
beta = param[1]
sigma2 = param[2]
LogLikelihood = -N/2*log(2*pi*sigma2) - sum( (y - beta*x)^2 / (2*sigma2) ) }
I've tried using 'outer' in order to use 'wireframe' as in the following thread:
How can I plot 3D function in r?
but without success:
param1 <- seq(-2, 2, length= 30)
param2 <- seq(0.1, 4, length= 30)
values1 <- matrix(c(param1,param2),30)
z <- outer(values1, x=x,y=y,N=N, LogL)
How can I use 'outer' properly in this case? Is there any other alternative to evaluate and to plot the function 'LogL'?