我正在处理金融/经济数据,以防您想知道以下某些系数的大小...我的一般问题与 R 中线性随机效应模型输出的参数系数的模拟有关。我是尝试使用模型系数和 R 中同一模型的方差-协方差 (VCOV) 矩阵生成 beta 系数的随机样本。我的问题是:为什么我会收到以下关于预期值平方根的错误mvtnorm{} 包中的 rmvnorm() 函数?我该如何处理这个警告/问题?
#Example call: lmer model with random effects by YEAR
#mlm<-lmer(DV~V1+V2+V3+V2*V3+V4+V5+V6+V7+V8+V9+V10+V11+(1|YEAR), data=dat)
#Note: 5 years (5 random effects total)
#LMER call yields the following information:
coef<-as.matrix(c(-28037800,0.8368619,2816347,8681918,-414002.6,371010.7,-26580.84,80.17909,271.417,-239.1172,3.463785,-828326))
sigma<-as.matrix(rbind(c(1834279134971.21,-415.95,-114036304870.57,-162630699769.14,-23984428143.44,-94539802675.96,
-4666823087.67,-93751.98,1735816.34,-1592542.75,3618.67,14526547722.87),
c(-415.95,0.00,41.69,94.17,-8.94,-22.11,-0.55,0.00,0.00,0.00,0.00,-7.97),
c(-114036304870.57,41.69,12186704885.94,12656728536.44,-227877587.40,-2267464778.61,
-4318868.82,8909.65,-355608.46,338303.72,-321.78,-1393244913.64),
c(-162630699769.14,94.17,12656728536.44,33599776473.37,542843422.84,4678344700.91,-27441015.29,
12106.86,-225140.89,246828.39,-593.79,-2445378925.66),
c(-23984428143.44,-8.94,-227877587.40,542843422.84,32114305557.09,-624207176.98,-23072090.09,
2051.16,51800.37,-49815.41,-163.76,2452174.23),
c(-94539802675.96,-22.11,-2267464778.61,4678344700.91,-624207176.98,603769409172.72,90275299.55,
9267.90,208538.76,-209180.69,-304.18,-7519167.05),
c(-4666823087.67,-0.55,-4318868.82,-27441015.29,-23072090.09,90275299.55,82486186.42,-100.73,
15112.56,-15119.40,-1.34,-2476672.62),
c(-93751.98,0.00,8909.65,12106.86,2051.16,9267.90,-100.73,2.54,8.73,-10.15,-0.01,-1507.62),
c(1735816.34,0.00,-355608.46,-225140.89,51800.37,208538.76,15112.56,8.73,527.85,-535.53,-0.01,21968.29),
c(-1592542.75,0.00,338303.72,246828.39,-49815.41,-209180.69,-15119.40,-10.15,-535.53,545.26,0.01,-23262.72),
c(3618.67,0.00,-321.78,-593.79,-163.76,-304.18,-1.34,-0.01,-0.01,0.01,0.01,42.90),
c(14526547722.87,-7.97,-1393244913.64,-2445378925.66,2452174.23,-7519167.05,-2476672.62,-1507.62,21968.29,
-23262.72,42.90,229188496.83)))
#Error begins here:
betas<-rmvnorm(n=1000, mean=coef, sigma=sigma)
#rmvnorm breaks, Error returned:
警告消息:在 sqrt(ev$values) 中:产生了 NaN
当我谷歌以下搜索字符串:“rmvnorm,”警告消息:在 sqrt(ev$values) 中:NaNs 产生,”我看到: http ://www.nickfieller.staff.shef.ac.uk/sheff-only /mvatasksols6-9.pdf 在第 4 页上,此错误表示“负特征值。”虽然,我从概念上或实际上不知道负特征值是什么,也不知道为什么会在这种情况下产生它们。
第二个搜索结果:[ http://www.r-tutor.com/r-introduction/basic-data-types/complex 2表示出现这个错误是因为试图取-1的平方根,即“不是一个复杂的值”(你不能取 -1 的平方根)。
问题仍然存在,随机生成的 beta 发生了什么,如何纠正?
sessionInfo() R 版本 3.0.2 (2013-09-25) 平台:x86_64-apple-darwin10.8.0 (64-bit)
使用以下软件包/版本 mvtnorm_0.9-9994、lme4_1.1-5、Rcpp_0.10.3、Matrix_1.1-2-2、lattice_0.20-23