R:使用as.formula修复模型中的模型调用 [英] R: fix model call in model using as.formula
本文介绍了R:使用as.formula修复模型中的模型调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个gls
模型,在其中我为该模型分配了一个公式(来自另一个对象):
I have a gls
model in which I assign a formula (from another object) to the model:
equation <- as.formula(aic.obj[row,'model'])
> equation
temp.avg ~ I(year - 1950)
mod1 <- gls(equation, data = dat)
> mod1
Generalized least squares fit by maximum likelihood
Model: equation
Data: dat
Log-likelihood: -2109.276
但是我不希望模型"成为等式",而是希望等式本身!我该怎么做?
However I do not want the "Model" to be "equation" but rather the quation itself! How do I do this??
推荐答案
您可以通过一些巧妙的语言处理来解决此问题.这将直接插入模型方程式来创建(未评估的)gls
调用,然后对其进行评估.
You can fix this up with some nifty use of language mangling. This creates the (unevaluated) gls
call with the model equation inserted directly, and then evaluates it.
cl <- substitute(gls(.equation, data=dat), list(.equation=equation))
mod1 <- eval(cl)
这篇关于R:使用as.formula修复模型中的模型调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文