在响应变量上运行 boxcox 时出错

时间:2021-07-28 21:37:00

标签: r regression linear-regression

我正在使用以下代码尝试转换响应变量以进行回归。似乎需要对数转换。

bc = boxCox(auto.tf.lm)

lambda.mpg = bc$x[which.max(bc$y)]

auto.tf.bc <- with(auto_mpg, data.frame(log(mpg), as.character(cylinders), displacement**.2, log(as.numeric(horsepower)), log(weight), log(acceleration), model_year))

auto.tf.bc.lm <- lm(log(mpg) ~ ., data = auto.tf.bc)
view(auto.tf.bc)

不过我收到了这个错误。

Error in Math.data.frame(mpg) : 
  non-numeric variable(s) in data frame: manufacturer, model, trans, drv, fl, class

不知道如何解决这个问题。数据在数据框中,而不是 csv。

这是 str(auto.tf.bc) 的输出。抱歉这么糟糕的问题格式。

'data.frame':   392 obs. of  7 variables:
$ log.mpg.               : num  2.89 2.71 2.89 2.77 2.83 ...
$ as.character.cylinders.: chr  "8" "8" "8" "8" ...
$ displacement.0.2       : num  3.14 3.23 3.17 3.14 3.13 ...
$ log.horsepower.        : num  4.87 5.11 5.01 5.01 4.94 ...
$ log.weight.            : num  8.16 8.21 8.14 8.14 8.15 ...
$ log.acceleration.      : num  2.48 2.44 2.4 2.48 2.35 ...
$ model_year             : num  70 70 70 70 70 70 70 70 70 70 ...

移除气缸不会改变任何东西。

0 个答案:

没有答案
相关问题