我想知道是否可以在R's
lme
或lmer
函数(或{{}中的其他随机效果例程中保持随机效应差异不变1}})或至少提供起始值。
这似乎可以在SAS中使用R
中的 parms 语句。在Selya et al. (2012)的论文中,作者使用它来设置模型的方差参数,其具有比完整模型更简单的固定效果结构。
他们使用的PROC MIXED中的特定调用是PROC MIXED
他们的目标是在具有不同固定效应结构的模型中保持方差估计不变(尽管我想知道这在SAS或R中是否真的可行)。
答案 0 :(得分:1)
在github上尝试gnlrim
。它可以通过参数的界限做出最大可能性。只需将起始值,下限和上限设置为随机截距方差pmix
的相同值,它就会保持不变。
以下示例显示gnlrim
使用lmer
估算与REML=FALSE
相同的模型。第一块用于轻松复制和粘贴;随后的块显示相关行的执行。
设置包,数据和拟合模型(复制和粘贴块):
library(devtools)
## if you have macOS, grab this version of libstableR:
devtools::install_github("hrbrmstr / libstableR")
devtools::install_github( "swihart/gnlrim")
## data: 4 individuals with 5 observations
dose <- c(9,12,4,9,11,10,2,11,12,9,9,9,4,9,11,9,14,7,9,8)
y <- c(8.674419, 11.506066, 11.386742, 27.414532, 12.135699, 4.359469,
1.900681, 17.425948, 4.503345, 2.691792, 5.731100, 10.534971,
11.220260, 6.968932, 4.094357, 16.393806, 14.656584, 8.786133,
20.972267, 17.178012)
id <- rep(1:4, each=5)
## fit with lmer
lmer_fit <- lme4::lmer(y~dose + (1|id), REML=FALSE)
## fit with gnlrim
gnlrim_fit <-
gnlrim(y,
mu=~a+b*dose+rand,
random="rand",
nest=id,
pmu=c(a=8.7,b=0.25),
pshape = c(shape=1),
pmix=c(var=3.0938^2),
p_uppb = c(10, 1, 5, 3.0938^3),
p_lowb = c( 5, -1, 0, 0)
)
运行这些行以查看模型的相似程度(复制和粘贴块):
## show fits are the same:
## intercept (a) slope (b)
summary(lmer_fit)$coeff[,1]
gnlrim_fit$coeff[1:2]
## Residuals standard deviation
## sigma_epsilon = 5.58
summary(lmer_fit)$varcor
sqrt(exp(gnlrim_fit$coeff[3]))
## random effects standard deviation
## sigma_id = 3.0938
summary(lmer_fit)$varcor
sqrt(gnlrim_fit$coeff[4])
## likelihood
summary(lmer_fit)$logLik
-gnlrim_fit$maxlike
采用相同的模型,但运行它设置并保持随机效果方差常数(复制和粘贴块):
## Take same model but hold constant
## random effects standard deviation
## sigma_id := 9
## sigma^2_id := 81
gnlrim_fit2 <-
gnlrim(y,
mu=~a+b*dose+rand,
random="rand",
nest=id,
pmu=c(a=8.7,b=0.25),
pshape = c(shape=1),
pmix=c(var=9^2),
p_uppb = c(10, 1, 5, 9^2),
p_lowb = c( 5, -1, 0, 9^2)
)
gnlrim_fit2$coeff
gnlrim_fit2$se
> ## show fits are the same:
> ## intercept (a) slope (b)
> summary(lmer_fit)$coeff[,1]
(Intercept) dose
8.7117914 0.2488724
> gnlrim_fit$coeff[1:2]
[1] 8.7118426 0.2488648
>
> ## Residuals standard deviation
> ## sigma_epsilon = 5.58
> summary(lmer_fit)$varcor
Groups Name Std.Dev.
id (Intercept) 3.0938
Residual 5.5880
> sqrt(exp(gnlrim_fit$coeff[3]))
[1] 5.587926
>
> ## random effects standard deviation
> ## sigma_id = 3.0938
> summary(lmer_fit)$varcor
Groups Name Std.Dev.
id (Intercept) 3.0938
Residual 5.5880
> sqrt(gnlrim_fit$coeff[4])
[1] 3.094191
>
> ## likelihood
> summary(lmer_fit)$logLik
'log Lik.' -64.64964 (df=4)
> -gnlrim_fit$maxlike
[1] -64.64958
> ## Take same model but hold constant
> ## random effects standard deviation
> ## sigma_id := 9
> ## sigma^2_id := 81
> gnlrim_fit2 <-
+ gnlrim(y,
+ mu=~a+b*dose+rand,
+ random="rand",
+ nest=id,
+ pmu=c(a=8.7,b=0.25),
+ pshape = c(shape=1),
+ pmix=c(var=9^2),
+ p_uppb = c(10, 1, 5, 9^2),
+ p_lowb = c( 5, -1, 0, 9^2)
+ )
>
> gnlrim_fit2$coeff
[1] 9.1349920 0.2012785 3.4258404 81.0000000
> gnlrim_fit2$se
[1] 6.1006729 0.4420228 0.3485940 0.0000000