r - Error in eval(expr, envir, enclos) in apply(boxcox) -


i have matrix of 650 columns , each column want find optimal lambda boxcox transformation. want use function boxcox mass package, outputs 2 lists: $x$ list of possible lambdas, $y$ list of log-likelihood values given lambdas. optimal lambda 1 scores highest likelihood.

i thought following piece of code work:

library(mass) optimal.lambda1 <- apply(mymatrix, 2, function (d) {     boxcoxlist <- boxcox(lm(d~1), lambda=seq(-5,5,by=.1), plotit=f)     p <- boxcoxlist$x[which.max(boxcoxlist$y)]     return(p)     } ) 

unfortunately same error:

error in eval(expr, envir, enclos): object 'd' not found 

a similar error occours if try lapply version of it:

library(mass) optimal.lambda1 <- lapply(1:ncol(mymatrix), function (d) {     boxcoxlist <- boxcox(lm(mymatrix[,d]~1), lambda=seq(-5,5,by=.1), plotit=f)     p <- boxcoxlist$x[which.max(boxcoxlist$y)]     return(p)     } ) 

also, tried isolate object function

optimal.lambda2 <- function (d) {     boxcoxlist <- boxcox(lm(d~1), lambda=seq(-5,5,by=.1), plotit=f)     p <- boxcoxlist$x[which.max(boxcoxlist$y)]     return(p)     } 

and use argument of (l)apply, second function alone returns error too; i.e., following command alone returns same error:

optimal.lambda2(mymatrix[,1]) 

any suggestion how make work?


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -