指定该模型是对数变换以绘制反向变换的趋势
Specifying that model is logit transformed to plot backtransformed trends
我已经在 R 中安装了一个 lme 模型,其中包含一个 logit 转换响应。我一直无法找到执行 logit 转换的直接命令,所以我手动完成了。
logitr<-log(r/1-r)
然后我将其用作我的 lme 模型中的响应,其中包含两个因素和一个数值变量之间的相互作用。
model<-lme(logitr<-factor1*factor2*numeric,random=1|random)
现在,R显然不知道这个模型是logit变换的。我如何将其指定给 R?
我试过运气不好:
update(model, tran="logit")
之所以要指定模型是logit变换的,是因为我想使用emmeans包中的函数emmip绘制反向变换的结果,显示我的变量之间交互的趋势。
通常(如果我只有因子)我会使用:
update_refgrid_model<-update(ref_grid(model, tran="logit"))
但是当我想使用emmip 绘制数值变量与因子之间交互作用的趋势时,这种方法不起作用。如果我指定:
emmip(update_refgrid_model, factor1~numeric|factor2, cov.reduce = range, type = "response")
然后我没有绘制任何趋势图,只有数值变量的平均水平估计值。
那么,我如何指定 logit 变换并绘制具有与数值变量相互作用的因子的 lme 模型的反向变换趋势?
你不更新模型对象,你更新参考网格:
rg = update(ref_grid(model, cov.reduce = range), tran = "logit")
emmip(rg, factor1~numeric|factor2, type = "response")
可以用其他东西更新模型,但不能用转换;在 emmGrid
对象的 update
方法中。
更新
这是一个展示其工作原理的示例
require(emmeans)
## Loading required package: emmeans
foo = transform(fiber, p = (strength - 25)/25)
foo.lm = lm(log(p/(1-p)) ~ machine*diameter, data = foo)
emm = emmeans(foo.lm, ~diameter|machine,
tran = "logit", at = list(diameter = 15:32))
## Warning in ref_grid(object, ...): There are unevaluated constants in the response formula
## Auto-detection of the response transformation may be incorrect
emmip(emm, machine ~ diameter)
emmip(emm, machine ~ diameter, type = "r")
由 reprex package (v0.3.0)
于 2020 年 6 月 2 日创建
我已经在 R 中安装了一个 lme 模型,其中包含一个 logit 转换响应。我一直无法找到执行 logit 转换的直接命令,所以我手动完成了。
logitr<-log(r/1-r)
然后我将其用作我的 lme 模型中的响应,其中包含两个因素和一个数值变量之间的相互作用。
model<-lme(logitr<-factor1*factor2*numeric,random=1|random)
现在,R显然不知道这个模型是logit变换的。我如何将其指定给 R?
我试过运气不好:
update(model, tran="logit")
之所以要指定模型是logit变换的,是因为我想使用emmeans包中的函数emmip绘制反向变换的结果,显示我的变量之间交互的趋势。
通常(如果我只有因子)我会使用:
update_refgrid_model<-update(ref_grid(model, tran="logit"))
但是当我想使用emmip 绘制数值变量与因子之间交互作用的趋势时,这种方法不起作用。如果我指定:
emmip(update_refgrid_model, factor1~numeric|factor2, cov.reduce = range, type = "response")
然后我没有绘制任何趋势图,只有数值变量的平均水平估计值。
那么,我如何指定 logit 变换并绘制具有与数值变量相互作用的因子的 lme 模型的反向变换趋势?
你不更新模型对象,你更新参考网格:
rg = update(ref_grid(model, cov.reduce = range), tran = "logit")
emmip(rg, factor1~numeric|factor2, type = "response")
可以用其他东西更新模型,但不能用转换;在 emmGrid
对象的 update
方法中。
更新
这是一个展示其工作原理的示例
require(emmeans)
## Loading required package: emmeans
foo = transform(fiber, p = (strength - 25)/25)
foo.lm = lm(log(p/(1-p)) ~ machine*diameter, data = foo)
emm = emmeans(foo.lm, ~diameter|machine,
tran = "logit", at = list(diameter = 15:32))
## Warning in ref_grid(object, ...): There are unevaluated constants in the response formula
## Auto-detection of the response transformation may be incorrect
emmip(emm, machine ~ diameter)
emmip(emm, machine ~ diameter, type = "r")
由 reprex package (v0.3.0)
于 2020 年 6 月 2 日创建