2016-04-01 16 views
0

私はboxtidwellの結果を保存して、自動化を達成するためのコードを書き、手動で変数を変換しないようにしたいと思います。多くの変数が、それはとても時間的になり、その後変換する必要がありますr- boxtidwellの結果をデータフレーム/マトリックスに格納する方法

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

:私は手動で、以下のコードのように、変数を変換したくないので

>boxTidwell(prestige ~ income + education, ~ type + poly(women, 2), data = Prestige) 

##   Score Statistic p-value MLE of lambda 
## income   -4.482406 0.0000074 -0.3476283 
## education  0.216991 0.8282154  1.2538274 
## iterations = 8 

:以下の例を参照してください。消費する。私はmatrixとdata.frameを試しましたが、どちらも無駄でした。

> 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 

私は、事前に任意の提案やアイデアのための多くのおかげでしばらく探したが無駄に思えるました。

答えて

1

box$resultでアクセスできます。一般的に

box$result[,"MLE of lambda"] 

    income education 
-0.3476283 1.2538274 

ので、あなたのコードは、上記の(粗)となり
Prestige$income <- (Prestige$income)^box$result[1,3]

、あなたのオブジェクトの使用内部で何str

+0

感謝をチェックアウトし、それは便利です。しかし、改善の余地はまだありますか?たとえば、コードに変数名「income」(つまり、「Prestige $ income'」)を手動で入力することを避けることができます。これはもっと一般的な方法であるべきです: 'Prestige $ result [1,0] < - (Prestige $ income)^ box $ result [1,3]'。多くの変数を変換する必要があるかもしれないので、すべての変数を手作業で入力することはできません。 – Samoth

+0

あなたは何を意味するのか分かりません。 'box $ result'の変数の行列全体にアクセスできます。それは2行と3列を持ち、必要に応じて索引付けすることができます。 – Eugene

関連する問題