Error: $ Operator Is Invalid for Atomic Vectors

Error: $ Operator Is Invalid for Atomic Vectors

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

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

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.