一点利用lme4包进行BLUP/BLUE计算的DEMO

df=data.frame(
  Y=c(101,101,100,99,201,201,200,199,51,51,50,49), 
  X2=c("1","1","1",'1','2','2','2','2','3','3','3','3'), 
  X=c(1,1,1,1,2,2,2,2,3,3,3,3), 
  R=c(1,1,2,3,1,1,2,3,1,1,2,3)
)

# BLUP
# https://mattzheng.blog.csdn.net/article/details/51636011?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-14.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-14.control
library(lme4)
fm1 <- lmer(Y ~ 1 + (1|X) + (1|R), df)
summary(fm1)
ranef(fm1)

# BLUE
# https://cloud.tencent.com/developer/article/1549810
library(lme4)
fm2 <- lmer(Y ~ X2 + (1|R), df)
summary(fm2)
fixef(fm2)
posted @ 2021-07-11 22:50  esctrionsit  阅读(702)  评论(0编辑  收藏  举报