## ----------- echo = false,结果='hide'---------------------------------------------------------------------------------------------------------------------------------------------库(“ Knitr”)opts_chunk $ set(tidy = false,dev =“ pdf”,图。=“ hide”,图width = 4,图5.5,消息= false,parning = false)## ----选项,结果=“ hide”,echo = false ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------选项(数字= 3,width = 80,提示=“”,contine =“”)opts_chunk $ set(注释= na,图。-----------------------------------------------库('VariancePartition')库('lme4')库('r2glmm')set.seed(1)n = 1000 beta = 3 alpha = c(1,5,7)#生成1个固定变量和1个随机变量,带有3个级别data = data.frame。n),主题= sample(c('a','b','c'),100,替换= true))#仿真变量#y = x \ beta + bucact \ alpha + alpha + \ sigma^2数据$ y=数据$ x*beta + model.matrix(〜数据$主题)%*%alpha + rnorm(n,0,1)#fit model fit = lmer(y〜x +(1 |主题),数据,reml =false)#使用VAR计算方差分数iancePartition#包括分母frac = calcvarpart(fit)frac#的差异分数中的总和不包括来自分母的随机效应的方差分数与R2GLMM frac [['x''] /(frac [frac [['x''x''['x''] + frac [['残差'])#使用r2glmm r2beta(fit)## ---- resetoptions,结果=“ hide”,echo = false------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------选项(提示=“>”,继续=“+”)