Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

Error: $ operator is invalid for atomic vectors

Writer Andrew Mclaughlin

I am trying to make boxcox transformation of a variable (i.e. sqrt.CR) with lambda value from -2 to 2. On running the below R code it gives a error of invalid atomic vectors. Later on checking earlier posts i saw few suggestions to transform the matrix into a data frame. Though the error continued to show up. Do anyone know to figure out this error ?

R code.

Matrix to data frame conversion

drivers.data<-as.data.frame(drivers)

Boxcox transfrom.

drivers$box_CR<-boxcox(drivers.data$sqrt.CR,lambda=seq(-2,2))
2

2 Answers

The input to boxcox must be the output of a lm or aov call, not a vector of numbers as yours appears to be. See ?boxcox.

boxcox(object, ...)
Arguments:
object: a formula or fitted model object. Currently only ‘lm’ and ‘aov’ objects are handled.

It could be because of package conflict, in MASS,boxcox requires a model object lm, whereas in bestNormalize it requires a vector.

Try

bestNormalize::boxcox(drivers.data)

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy