Mukhtar Ahmed
Mukhtar Ahmed

Reputation: 71

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))

Upvotes: 0

Views: 5438

Answers (2)

Khathu
Khathu

Reputation: 41

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)

Upvotes: 4

mathematical.coffee
mathematical.coffee

Reputation: 56905

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.

Upvotes: 6

Related Questions