首页 > 解决方案 > 在响应变量上运行 boxcox 时出错

问题描述

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

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

卸下气缸不会改变任何事情。

标签: rregressionlinear-regression

解决方案


推荐阅读