search for: boxcoxlambda

Displaying 6 results from an estimated 6 matches for "boxcoxlambda".

2023 Jul 08
1
Getting an error calling MASS::boxcox in a function
...ts > > object > > a formula or fitted model object. Currently only lm and aov objects are handled. > ************************* > I read that as saying that > > boxcox(lm(z+1 ~ 1),...) > > should run without error. But it didn't. And perhaps here's why: > BoxCoxLambda <- function(z){ > b <- MASS:::boxcox.lm(lm(z+1 ~ 1), lambda = seq(-5, 5, length.out = > 61), plotit = FALSE) > b$x[which.max(b$y)] # best lambda > } > >> lambdas <- apply(dd,2 , BoxCoxLambda) > Error in NextMethod() : 'NextMethod' called from an...
2023 Jul 08
1
Getting an error calling MASS::boxcox in a function
...John. ?boxcox says: ************************* Arguments object a formula or fitted model object. Currently only lm and aov objects are handled. ************************* I read that as saying that boxcox(lm(z+1 ~ 1),...) should run without error. But it didn't. And perhaps here's why: BoxCoxLambda <- function(z){ b <- MASS:::boxcox.lm(lm(z+1 ~ 1), lambda = seq(-5, 5, length.out = 61), plotit = FALSE) b$x[which.max(b$y)] # best lambda } > lambdas <- apply(dd,2 , BoxCoxLambda) Error in NextMethod() : 'NextMethod' called from an anonymous function and, indeed, ?Us...
2023 Jul 08
1
Getting an error calling MASS::boxcox in a function
Dear Ron and Bert, First (and without considering why one would want to do this, e.g., adding a start of 1 to the data), the following works for me: ------ snip ------ > library(MASS) > BoxCoxLambda <- function(z){ + b <- boxcox(z + 1 ~ 1, + lambda = seq(-5, 5, length.out = 101), + plotit = FALSE) + b$x[which.max(b$y)] + } > mrow <- 500 > mcol <- 2 > set.seed(12345) > dd <- matrix(rgamma(mrow*mcol, shape = 2, scale = 5), nrow = mr...
2023 Jul 08
1
Getting an error calling MASS::boxcox in a function
...ect answers. After restarting, I continued to get the same error as you did with my supposed "fix." So just ignore what I said and sorry for the noise. -- Bert On Sat, Jul 8, 2023 at 8:28?AM Bert Gunter <bgunter.4567 at gmail.com> wrote: > Try this for your function: > > BoxCoxLambda <- function(z){ > y <- z > b <- boxcox(y + 1 ~ 1,lambda = seq(-5, 5, length.out = 61), plotit = > FALSE) > b$x[which.max(b$y)] # best lambda > } > > ***I think*** (corrections and clarification strongly welcomed!) that `~` > (the formula function) is loo...
2023 Jul 08
1
Getting an error calling MASS::boxcox in a function
Try this for your function: BoxCoxLambda <- function(z){ y <- z b <- boxcox(y + 1 ~ 1,lambda = seq(-5, 5, length.out = 61), plotit = FALSE) b$x[which.max(b$y)] # best lambda } ***I think*** (corrections and clarification strongly welcomed!) that `~` (the formula function) is looking for 'z' in the GlobalEnv,...
2023 Jul 08
1
Getting an error calling MASS::boxcox in a function
...he function either with an extracted column (ie dd1 in the reprex below) or in a call to apply I get an error (see the reprex below). I'm sure I'm doing something silly, but I can't see what it is. Any help appreciated. library(MASS) # Find optimised Lambda for Boc-Cox transformation BoxCoxLambda <- function(z){ b <- boxcox(lm(z+1 ~ 1), lambda = seq(-5, 5, length.out = 61), plotit = FALSE) b$x[which.max(b$y)] # best lambda } mrow <- 500 mcol <- 2 set.seed(12345) dd <- matrix(rgamma(mrow*mcol, shape = 2, scale = 5), nrow = mrow, ncol = mcol) # Try it not using the...