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 easil
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 f
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:
>
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 = 1
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:
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 ob
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
(Sorry for sending it twice. I forgot to reply
to the mailing list.)
Many many thanks for the comments and examples!
I could write my own function to achieve what
I want to do. However, I would like to find a method that
uses built-in functions only and prints the output in a format
identical to
8 matches
Mail list logo