在confint选项中使用配置文件和引导方法,带有glmer模型 [英] using profile and boot method within confint option, with glmer model

查看:277
本文介绍了在confint选项中使用配置文件和引导方法,带有glmer模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将glmer与logit链接用于高斯误差模型.

I am using glmer with a logit link for a gaussian error model.

当我尝试使用配置文件或带有confint选项的引导方法来获取置信区间时,在使用概要文件似然性和引导程序时会出现错误:

When I try obtaining the confidence intervals, using either profile or the boot method with the confint option, I obtain an error for use of profile likelihood, and with bootstrapping:

> Profile: Computing profile confidence intervals ... Error in
> names(opt) <- profnames(fm, signames) :    'names' attribute [2] must
> be the same length as the vector [1]
> 
> Boot: Error in if (const(t, min(1e-08, mean(t, na.rm = TRUE)/1e+06)))
> { :    missing value where TRUE/FALSE needed In addition: Warning
> message: In bootMer(object, FUN = FUN, nsim = nsim, ...) :   some
> bootstrap runs failed (9999/10000)

我已经通过安装lme4开发工具查看了有关如何解决配置文件问题的在线建议,并且还从数据集中消除了所有NA.但是,在这两种情况下,我仍然会收到相同的两条错误消息.

I have looked at online suggestions on how to overcome the profile issue, by installing the lme4 development tool and I have also eliminated all NAs from the dataset. However, in both instances, I still receive the same two error messages.

对于这是lme4问题还是更根本的问题,有人能提供任何帮助吗?

Is anybody able to offer any help as to whether this is a lme4 issue, or whether it's more fundamental.

以下是产生前20个观测值和模型格式的代码:

Here is code to produce the first 20 observations and the model format:

df2 <- data.frame(
prop1 = c(0.46, 0.471, 0.458, 0.764, 0.742, 0.746, 0.569, 0.45,    0.491,    0.467, 0.464, 
        0.556, 0.584, 0.478, 0.456, 0.46, 0.493, 0.704, 0.693, 0.651), 
prop2 = c(0.458, 0.438, 0.453, 0.731, 0.738, 0.722, 0.613, 0.498, 0.452, 0.451, 0.447,
        0.48, 0.576, 0.484, 0.473, 0.467, 0.467, 0.722, 0.707, 0.709),
site = c(1,1,2,3,3,3,4,4,4,4,4,5,5,5,6,6,7,8,8,8)
)
df2$site <- factor(df2$site)

model <- glmer(prop2 ~ prop1 + (1|site), 
           data=df2, family=gaussian(link="logit"))
summary(model)

响应与协变量一样是比例(0,1).我已经使用logit链接将响应的期望值限制在(0,1)之间,而不是与常规绑定,尽管此数据相当适合LMM.

The response is a proportion (0,1), as is the covariate. I have used the logit link to keep the expected values of the response bound between (0,1), rather than being unbound with the normal, though this data fits a LMM reasonably well.

我还将分析两个比例之间的差异,为此我希望一些差异(和拟合值)会违反(0,1)边界-因此,我将使用带有高斯误差的恒等链接对此模型进行建模,或者logit链接上的比例差异(将其强制为(0,1)).

I will also analyse the difference between the two proportions, for which I expect some differences (and fitted values) to violate the (0,1) boundary - so I will model this with either an identity link with gaussian error, or logit link on the scaled difference (coercing this to be (0,1)).

此外,由于每个站点可能只有1-5条记录,因此我自然会考虑进行线性回归或GLM(比例),如果对随机影响进行了估算,则在建模过程中将站点视为固定影响方差为零(或很小).

Also, given that there may only be 1-5 records per site, I will naturally consider running linear regression or GLM (proportions), and treat site as a fixed effect in the modelling process, if the estimate of the random effects variance is zero (or very small).

推荐答案

您已识别出当前版本lme4的错误,该错误已部分修复在Github上(可与method="boot"一起使用). (如果安装了开发工具,则devtools::install_github("lme4/lme4")应该可以安装它.)

You've identified a bug with the current version of lme4, partially fixed on Github now (it works with method="boot"). (devtools::install_github("lme4/lme4") should work to install it, if you have development tools installed.)

library(lme4)
fit_glmer <- glmer(prop2 ~ prop1 + (1|site), 
       data=df2, family=gaussian(link="logit"))

配置文件/配置文件的置信区间仍然不起作用,但存在更有意义的错误:

Profiling/profile confidence intervals still don't work, but with a more meaningful error:

try(profile(fit_glmer))
## Error in profile.merMod(fit_glmer) : 
##   can't (yet) profile GLMMs with non-fixed scale parameters

引导程序确实有效.有很多警告,很多改装尝试都失败了,但是我希望这是因为所提供的数据集很小.

Bootstrapping does work. There are lot of warnings, and a lot of refitting attempts failed, but I'm hoping that's because of the small size of the data set provided.

bci <- suppressWarnings(confint(fit_glmer,method="boot",nsim=200))

我想提出几个其他选择.您可以使用 glmmADMB prop列和prop_type列)并包括prop_type作为预测变量来建模比例类型之间的差异(可能具有识别个体水平的随机效应)哪个比例是针对同一个人测量的)...

I want to suggest a couple of other options. You can use glmmADMB or glmmTMB, and these platforms also allow you to use a Beta distribution to model proportions. I would consider modeling the difference between proportion types by "melting" the data (so that there is a prop column and a prop_type column) and including prop_type as a predictor (possibly with an individual-level random effect identifying which proportions were measured on the same individual) ...

library(glmmADMB)
fit_ADMB <- glmmadmb(prop2 ~ prop1 + (1|site), 
       data=df2, family="gaussian",link="logit")
## warning message about 'sd.est' not defined -- only a problem
## for computing standard errors of predictions, I think?

library(glmmTMB)
fit_TMB <- glmmTMB(prop2 ~ prop1 + (1|site), 
       data=df2, family=list(family="gaussian",link="logit"))

听起来您的数据可能更适合Beta模型?

It sounds like your data might be more appropriate for a Beta model?

fit_ADMB_beta <- glmmadmb(prop2 ~ prop1 + (1|site), 
       data=df2, family="beta",link="logit")
fit_TMB_beta <- glmmTMB(prop2 ~ prop1 + (1|site), 
       data=df2,
       family=list(family="beta",link="logit"))

比较结果(比需要的结果更漂亮)

Compare results (fancier than it needs to be)

library(broom)
library(plyr)
library(dplyr)
library(dwplot)

tab <- ldply(lme4:::namedList(fit_TMB_beta,
                        fit_ADMB_beta,
                        fit_ADMB,
                        fit_TMB,
                        fit_glmer),
      tidy,.id="model") %>%
    filter(term != "(Intercept)")
dwplot(tab) + 
    facet_wrap(~term,scale="free",
                       ncol=1)+theme_set(theme_bw())

这篇关于在confint选项中使用配置文件和引导方法,带有glmer模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆