Dear R users,
I am a new R user and have some difficulty
understanding the functioning of “outer”, where my question is from. I have
read the posts related to the questions on the outer function, but
unfortunately could not figure out where my mistake is.
I have a function with two variables and
three parameters (a density function that is not standard) and I want to draw
the contourplot along two parameters while keeping the third fixed. When I run
the program it gives an error which is due to the outer function. I have tested
the program with another simpler function and it works. So, I know that the
problem is in the function that I have written. Below I copy the error and the
part of the
program (the function) which causes the error:
Error: outer(par1, par2, y1, y2, FUN = function.subplot, KERNEL = KERNEL,:
dims [product 25921] [1] does not match the length of the object.
par1 <- seq(-3,3,0.1)
par2<- seq(-3,3,0.1)
x<-cbind(par1,par2) # par1:parameter1,
par2: parameter2, sigma is the third parameter that I fix
densityfunction <- function(x, y1,y2, sigma=0.2){ # y1 and y2: the data
x <- matrix(x, nrow = 1)
function.value <- 0
for (i in 1:T){ # T: the length of the data
k <- y1[i] - x[,2]*y2[i] - (1-x[,2])*x[,1]
kk <- t(k)%*%k
density <- -((T+2)/2)*log(sigma^2) - (kk/(2*(sigma^2)))
function.value <- function.value + density
as.vector(function.value)
return(function.value)
}
}
Thank you very much in advance for your
suggestions.
Best regards,
P.
[[alternative HTML version deleted]]