[R] Contour plot of bivariate log-likelihood function

From: Dale Steele <Dale_Steele_at_brown.edu>
Date: Mon 16 Oct 2006 - 02:43:51 GMT

Thanks to prior help from the list, I've made progress in adapting a univariate log-likelihood function to a bivariate one for Box-Cox transformations. However, I'm having trouble plotting values of the log-likelihood function (z) for given range of lambda(1) and lambda(2).

The current result of my function (below) is z. How can I adapt it to output the values lambda(1), lambda(2) (for each row of all_lambda) and z and then plot using contour()?

I'm also stuck on how to allow the variable xL to == log(x) when lambda(1)==0 and/or lambda(2)==0.



X <- as.matrix(cbind(x1,x2))

  bvboxcox <- function(X, min, max, step)    {

     seq <- seq(min,max,step)
     all_lambda <- expand.grid(seq,seq)
     all_lambda <- as.matrix(all_lambda)
     c <- nrow(all_lambda)
     res <- numeric(c)

     for (i in seq(1:c)){
       lambda <- all_lambda[i,]
       xL <- (X^lambda - 1)/lambda
       n <- nrow(X)
       t1 <- (-n/2)*log(det(cov(xL)))
       gsum <- apply(X,2,function(x) sum(log(x)))
       t2 <- sum((lambda - 1) * gsum)
       res[i] <- t1+t2


## For example ...

bvboxcox(X, 0.10, 0.17, 0.01)

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon Oct 16 12:56:57 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 16 Oct 2006 - 03:30:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.