r-如何将boxtidwell的结果存储到数据帧/矩阵中

时间:2016-04-01 03:06:00

标签: r linear-regression

我想存储boxtidwell的结果,以便编写一些代码来实现自动化并避免手动转换变量。见下面的例子:

 >Prestige$income <- (Prestige$income )^(-0.3476283)

因为我不想手动转换变量,例如下面的代码:

> box<-boxTidwell(prestige ~ income + education, ~ type + poly(women, 2),   data = Prestige)
> box<-as.data.frame(box)

#Error in as.data.frame.default(box) : 
#cannot coerce class ""boxTidwell"" to a data.frame

> box<-as.matrix(box)
> box

#Error in round(x$result, digits) : 
#non-numeric argument to mathematical function

当需要转换许多变量时,它将非常耗时。我试过矩阵和data.frame但都徒劳无功。

output_buffering = 4096

我已经搜索了一段时间,但似乎徒劳无功,非常感谢提前提出任何建议和想法。

1 个答案:

答案 0 :(得分:1)

可以box$result访问,例如

box$result[,"MLE of lambda"]

    income  education 
-0.3476283  1.2538274 

所以上面的代码变得(粗略地)
Prestige$income <- (Prestige$income )^box$result[1,3]

一般情况下,要查看对象中的内容,请使用str