R
パッケージmice
は、次の例が付属しています:数式を変数として実行しているマウス:後で評価するのではなく即時評価を実行しますか?
library("mice")
imp <- mice(nhanes)
fit <- with(data=imp,exp=lm(bmi~hyp+chl))
は、私のようなwith()
の柔軟な呼び出したい:
model_formula <- bmi~hyp+chl
fit <- with(data=imp,exp=lm(model_formula))
をしかし、これはError in eval(predvars, data, env) : object 'bmi' not found
をスローします。私は同様の問題を探しました。私が見つけたクローゼットの問題はHelp understand the error in a function I defined in Rでした。 私の印象は、という表現は即座に評価されますが、exp = lm(bmi~hyp+chl)
と書くと直ちに評価されません。代わりに関数with.mice()
で結果が出ますか?もしそうなら、どうすれば即時評価を防ぐことができますか?
私は、これが起因して、かなり評価の時よりも、おそらくスコープの問題だと思いますどのようにwith.midsが書かれていますか?代わりに、数式を文字列 'model_formula < - " bmi〜hyp + chl "'として定義し、with.midsスコープ 'with(imp、lm(formula(model_formula)))内の式を定義することもできます' – user20650