Re: [R] Getting an error calling MASS::boxcox in a function

2023-07-08 Thread Bert Gunter
Aha. Many thanks, John. Never would have gotten there on my own. -- Bert On Sat, Jul 8, 2023 at 2:01 PM John Fox wrote: > > Hi Bert, > > On 2023-07-08 3:42 p.m., Bert Gunter wrote: > > Caution: This email may have originated from outside the organization. > > Please exercise additional caution

Re: [R] Getting an error calling MASS::boxcox in a function

2023-07-08 Thread John Fox
Hi Bert, On 2023-07-08 3:42 p.m., Bert Gunter wrote: Caution: This email may have originated from outside the organization. Please exercise additional caution with any links and attachments. Thanks John. ?boxcox says: * Arguments object a formula or fitted model

Re: [R] Getting an error calling MASS::boxcox in a function

2023-07-08 Thread Bert Gunter
Thanks 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:

Re: [R] Getting an error calling MASS::boxcox in a function

2023-07-08 Thread John Fox
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 =

Re: [R] Getting an error calling MASS::boxcox in a function

2023-07-08 Thread Bert Gunter
No, I'm afraid I'm wrong. Something went wrong with my R session and gave me incorrect 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 wrote: >

Re: [R] Getting an error calling MASS::boxcox in a function

2023-07-08 Thread Bert Gunter
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

[R] Getting an error calling MASS::boxcox in a function

2023-07-08 Thread Ron Crump via R-help
Hi, Firstly, apologies as I have posted this on community.rstudio.com too. I want to optimise a Box-Cox transformation on columns of a matrix (ie, a unique lambda for each column). So I wrote a function that includes the call to MASS::boxcox in order that it can be applied to each column