【问题标题】:Extracting random effects from a gamlss object从 gamlss 对象中提取随机效果
【发布时间】:2018-07-05 04:10:19
【问题描述】:

我已经使用 R 中的 gamlss 包运行了一个带有随机截距模型的 beta 回归。调用看起来像:

uik.max.model <- gamlss(formula = max.opp.vote ~ n_commute + vote_commute + uik_dummy +
                      opp.gd + opp.m + pay + govt_dep + higher_ed + max.opp.n +
                      opp.m*vote_commute + opp.m*n_commute +
                      re(random = ~1|mf),
                    family = BE(),
                    data = poll_df)

我想从模型对象中提取每个分组因子 (mf) 的随机效应,以创建预测概率图,但我无法找到它们存储在对象中的位置/位置。

分组因子的每个值的随机截距是否可用?如果有,在哪里?

【问题讨论】:

    标签: r gam random-effects


    【解决方案1】:

    要分析拟合对象的结构,我们可以使用str(uik.max.model)。因此可以在uik.max.model$mu.coefSmo[[1]]$coefficients$random 中找到随机效应。考虑这个例子:

    library(gamlss)
    # creating some data
    variable <- as.factor(rep(1:26, 1e3))
    levels(variable) <- LETTERS
    value <- rbinom(2.6e4, 10, .5)
    df1 <- data.frame(variable, value)
    
    # fitting a minimal model
    fit <- gamlss(formula = value ~ 1 +
                  re(random = ~1|variable),
                data = na.omit(df1))
    
    # analyzing structure of fitted object
    str(fit)
    # ...
    
    # random effects for each value of "variable"
    fit$mu.coefSmo[[1]]$coefficients$random
    # $variable
    # (Intercept)
    # A -1.029350e-07
    # B -2.465111e-09
    # C  1.326496e-07
    # D -1.632303e-08
    # E  2.731609e-09
    # F -4.403887e-08
    # G -2.465111e-09
    # H -7.695143e-08
    # I  2.698297e-08
    # J  4.950209e-08
    # K -3.191319e-08
    # L  9.627257e-08
    # M -4.057439e-08
    # N  3.737641e-08
    # O -1.285855e-08
    # P  1.551687e-07
    # Q  1.312505e-08
    # R -8.907712e-08
    # S -9.394071e-09
    # T  2.178625e-08
    # U -7.661831e-09
    # V -1.978751e-08
    # W -8.734488e-08
    # X  3.737641e-08
    # Y -1.285855e-08
    # Z -1.632303e-08
    

    【讨论】:

    • 太好了,谢谢!我用 'str()' 在错误的地方四处寻找。
    • 很高兴为您提供帮助。
    • value 的总方差是由fit$mu.coefSmo 给出的variable 给出的吗? IE。没有被variable 的水平分开的总随机截距方差。
    【解决方案2】:

    以下可能会有所帮助

    summary(getSmo(uik.max.model)) # summary
    ranef(getSmo(uik.max.model)) # random effect estimates
    coef(getSmo(uik.max.model)) # fitted coefficients
    intervals(getSmo(uik.max.model)) # Confidence intervals
    

    请参阅:Stasinopoulos D. M.、Rigby R.A.、Heller G.、Voudouris V. 和 De Bastiani F.,(2017 年)灵活回归和平滑:在 R、Chapman 和 Hall/CRC 中使用 GAMLSS。 第 10 章

    最好的问候 启

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多