从gamlss对象中提取随机效果

时间:2018-01-25 19:54:23

标签: r gam random-effects

我使用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)的随机效果,以便创建预测概率图,但我无法找到它们存储在对象中的位置。

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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

以下内容可能会帮助

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.,Vouudouris V.和De Bastiani F。,(2017年)灵活回归和平滑:在R,Chapman和Hall / CRC中使用GAMLSS。 第十章

最好的问候 凯

相关问题