English 中文(简体)
• 如何在Nlme中说明与腐蚀相关的越境随机影响?
原标题:How to specify correlated crossed random effects in nlme?

我想在使用<代码>nlme:lme(底线数据)的模式中具体说明不同的随机影响。 随机影响为:1)<代码>intercept和>>>>>>> > > > > > 代码<>> > > > > 。 2)intercept <代码>comparison。 直接使用<代码>lme4:lmer:

lmer(rating ~ 1 + position + 
     (1 + position | subject) + 
     (1 | comparison), data=d)

> ...
Random effects:
 Groups     Name        Std.Dev. Corr 
 comparison (Intercept) 0.31877       
 subject    (Intercept) 0.63289       
            position    0.06254  -1.00
 Residual               0.91458      
 ...

然而,我要坚持<代码>lme,因为我也希望模拟汽车校正结构(position是一个时间变量)。 www.un.org/Depts/DGACM/index_french.htm 我的尝试将影响推到后面,这不是我想要的。

lme(rating ~ 1 + position,
random = list( ~ 1 + position | subject,
               ~ 1 | comparison), data=d)

> ...
Random effects:
 Formula: ~1 + position | subject
 Structure: General positive-definite, Log-Cholesky parametrization
            StdDev     Corr  
(Intercept) 0.53817955 (Intr)
position    0.04847635 -1    

 Formula: ~1 | comparison %in% subject    # NESTED :(
        (Intercept)     Residual
StdDev:   0.9707665 0.0002465237
...

here,

www.un.org/Depts/DGACM/index_spanish.htm The data used in the example

   d <- structure(list(
  rating = c(
    2, 3, 4, 3, 2, 4, 4, 3, 2, 1, 3, 2, 
    2, 2, 4, 2, 4, 3, 2, 2, 3, 5, 3, 4, 4, 4, 3, 2, 3, 5, 4, 5, 2, 
    3, 4, 2, 4, 4, 1, 2, 4, 5, 4, 2, 3, 4, 3, 2, 2, 2, 4, 5, 4, 4, 
    5, 2, 3, 4, 3, 2), 
  subject = structure(c(
    1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
    4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 
    6L, 6L, 6L, 6L, 6L, 6L, 6L), 
    .Label = c(
      "1", "2", "3", "4", "5", 
      "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", 
      "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", 
      "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", 
      "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", 
      "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", 
      "61", "62", "63"), 
    class = "factor"), 
  position = c(
    1, 2, 3, 4, 
    5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 
    5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 
    5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 
  comparison = structure(c(
    1L, 
    7L, 9L, 8L, 3L, 4L, 10L, 2L, 5L, 6L, 2L, 6L, 4L, 5L, 8L, 10L, 
    7L, 3L, 1L, 9L, 3L, 9L, 10L, 1L, 5L, 7L, 6L, 8L, 2L, 4L, 4L, 
    2L, 8L, 6L, 7L, 5L, 1L, 10L, 9L, 3L, 5L, 10L, 6L, 3L, 2L, 9L, 
    4L, 1L, 8L, 7L, 6L, 5L, 2L, 10L, 4L, 3L, 8L, 9L, 7L, 1L), 
    contrasts = structure(c(
      1, 
      0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 
      0, 1, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0, 0, 0, -1, 0, 
      0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0, 0, -1, 0, 
      0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 1, 0, -1, 0, 
      0, 0, 0, 0, 0, 0, 0, 1, -1), 
      .Dim = c(10L, 9L), .Dimnames = list(
        c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"), NULL)), 
    .Label = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"), 
    class = "factor")), 
  .Names = c("rating", "subject", "position", "comparison"), 
  row.names = c(
    1L, 2L, 3L, 
    4L, 5L, 6L, 7L, 8L, 9L, 10L, 111L, 112L, 113L, 114L, 115L, 116L, 
    117L, 118L, 119L, 120L, 221L, 222L, 223L, 224L, 225L, 226L, 227L, 
    228L, 229L, 230L, 331L, 332L, 333L, 334L, 335L, 336L, 337L, 338L, 
    339L, 340L, 441L, 442L, 443L, 444L, 445L, 446L, 447L, 448L, 449L, 
    450L, 551L, 552L, 553L, 554L, 555L, 556L, 557L, 558L, 559L, 560L), 
  class = "data.frame")
str(Data)
最佳回答

我真的说是想把这一点推向一边。 如果没有更多的工作,我就不认为我可以完全获得与<条码>lme4相同的模式,但我可以结束。

## source("SO36643713.dat")
library(nlme)
library(lme4)

这是你所希望的模式,其全文为:subject(与斜坡和拦截有关)和comparison的随机接口:

m1 <- lmer(rating ~ 1 + position + 
               (1 + position | subject) + 
               (1 | comparison), data=d)

这是我可以说明如何在<代码>lme上复制:独立拦截和斜坡”。 (我尤其不喜欢这些模式,但是这些模式被相当普遍地用作人们简化过于复杂的随机影响模型的一种方法。)

m2 <- lmer(rating ~ 1 + position + 
               (1 + position || subject) + 
               (1 | comparison), data=d)

Results:

VarCorr(m2)
##  Groups     Name        Std.Dev.
##  comparison (Intercept) 0.28115 
##  subject    position    0.00000 
##  subject.1  (Intercept) 0.28015 
##  Residual               0.93905 

对于这一特定数据集,随机斜坡估计会有任何差异。

现在请设<代码>lme。 关键(吗? )的见解是,<条码>pdBlock(>矩阵中的所有术语都必须<>在同一组别的可变<>内公布。 例如,在皮涅罗和Bates第163页的跨地-效果例子中,区块内的区块、区块内的区块和区块内的栏目是随机影响。 由于没有任何组别因素使<代码>comparison <>和subject均被封成,Im刚刚组成一个“<条码>dummy“因果”的“要素”,其中包括一个组块中的全部数据:

d$dummy <- factor(1)

我们现在可以采用这一模式。

m3 <- lme(rating~1+position,
          random=list(dummy =
                pdBlocked(list(pdIdent(~subject-1),
                               pdIdent(~position:subject),
                               pdIdent(~comparison-1)))),
          data=d)

我们在随机影响表中有三个部分:一个是<代码>subject,一个是<编码>>>>>> >>-逐-subject/code>互动,另一个是comparison。 缺乏品牌新<代码>pdMat 舱位,Isn t 显示每个斜坡(>position:subject)与相应的拦截相关(subjectXX)。 (你可能认为你可以建立一个<代码>pdBlock<>/code>结构,但我看不出任何办法限制差异估计数在<代码>pdBlock标的多个区块之间相同。)

这些结果大致相同,尽管它们的报告不同。

vv <- VarCorr(m3)
vv2 <- vv[c("subject1","position:subject1","comparison1","Residual"),]
storage.mode(vv2) <- "numeric"
print(vv2,digits=4)
                   Variance    StdDev
subject1          7.849e-02 2.802e-01
position:subject1 4.681e-11 6.842e-06
comparison1       7.905e-02 2.812e-01
Residual          8.818e-01 9.390e-01
问题回答

虽然nlme是强有力的,包括随机影响、误差相关性和差异结构,但估算这些要素中的多种可能具有挑战性。 通常,随机影响和相关错误都是相互排斥的。 查明随机影响已经使同一群体的意见与特定模式相一致。 因此,在出现随机影响的情况下,遗留物的相对结构往往没有必要。

除了本·博尔克的答复外,为了允许按主题进行相关的拦截和位置的斜坡,我们应当使用<代码>pdSymm(或pd CarloChol(,该编码构建一个通用的肯定性不对称成分矩阵,取代pdIdent(),该表要求固定的分辨率(不同随机影响预测器之间的相同差异)和零外差元素(不同随机影响预测器之间没有相互关系)。 <>代码>pdSymm() 是pdBlock(>内的一种缺省方法,如果只有一种公式按照提供?pdBlock。 在<代码>pdBlock()外,pdlogChol()是按<代码>制定的随机效应结构缺省法? 回答:。 • 如何产生两种随机影响,一种在Nlme被nes为一种;

summary(Model <- lme(
  rating ~ 1 + position, random = list(
    one = pdIdent(~ 0 + comparison), 
    subject = pdSymm(~ 1 + position)),
  data = Data %>% mutate(one = factor(1))))
ranef(Model)
"       AIC      BIC    logLik
  187.7118 202.1349 -86.85592
 Formula: ~0 + comparison | one
 Structure: Multiple of an Identity
        comparison1 comparison2 comparison3 comparison4 comparison5 comparison6
StdDev:   0.3187715   0.3187715   0.3187715   0.3187715   0.3187715   0.3187715
        comparison7 comparison8 comparison9 comparison10
StdDev:   0.3187715   0.3187715   0.3187715    0.3187715
 Formula: ~1 + position | subject %in% one
 Structure: General positive-definite
            StdDev     Corr  
(Intercept) 0.63288465 (Intr)
position    0.06254075 -1    
Residual    0.91457562       
                Value Std.Error DF   t-value p-value
(Intercept)  3.903085 0.3789931 53 10.298566  0.0000
position    -0.139955 0.0489547 53 -2.858867  0.0061
comparison1 comparison2 comparison3 comparison4 comparison5 comparison6
1   -0.124214   0.1165746   -0.346355   0.3041951 -0.06813102  -0.1990121
  comparison7 comparison8 comparison9 comparison10
1   0.1665042  -0.1454743   0.1223316    0.1735809
Level: subject %in% one 
    (Intercept)     position
1/1 -0.38340091  0.037887119
1/2 -0.73473740  0.072605685
1/3  0.28043574 -0.027712235
1/4  0.04564053 -0.004510136
1/5  0.20881591 -0.020634898
1/6  0.58324613 -0.057635535
pdLogChol reports nlminb problem, convergence error code = 1
  message = iteration limit reached without convergence (10) 
pdNatural works"

在这种情况下,pdSymm(> converged, but pd CarloChol(没有,这表明模型规格不可靠。 这些结果与<代码>lmer非常相似。 请注意,确保分类变量,除非放在<编码>>/>>>/代码之后,或作为清单要素的名称,必须是一个因素,否则,必须加以计算,只形成一个组。

summary(Model <- lmer(
  rating ~ 1 + position + (1 + position | subject) + (1 | comparison), 
  data = Data))
ranef(Model)
"REML criterion at convergence: 173.7
 Groups     Name        Variance Std.Dev. Corr 
 comparison (Intercept) 0.101324 0.31831       
 subject    (Intercept) 0.398420 0.63121       
            position    0.003882 0.06231  -1.00
 Residual               0.836809 0.91477       
Number of obs: 60, groups:  comparison, 10; subject, 6
            Estimate Std. Error t value
(Intercept)  3.90306    0.37852  10.311
position    -0.13995    0.04891  -2.861
$comparison
   (Intercept)
1  -0.12403765
2   0.11632288
3  -0.34563369
4   0.30355427
5  -0.06790331
6  -0.19857126
7   0.16608863
8  -0.14527984
9   0.12212718
10  0.17333278
$subject
  (Intercept)     position
1 -0.38245981  0.037753107
2 -0.73275744  0.072331444
3  0.28017368 -0.027656310
4  0.04548482 -0.004489866
5  0.20779079 -0.020511300
6  0.58176795 -0.057427074"

在<代码>nlme中,在具体说明跨随机影响时,作为整体样本中形成了一种ake形结构,其中,个人在需求范围内跨越了成分而无需相关术语,每个需要填写在pdIdent(。 这一ake子下的其他随机影响结构将要求更多的参数,试图估算大的var变矩阵,并打破常规估算。 关键的挑战是随机影响之间的相互关系,pdIdent(<>>/code>是不够的。 随机影响清单的最后一个组成部分可以是实际的组别结构,这种结构必须在整个样本中采用。 具有相关性的随机影响部分必须作为<代码> random = 清单的最后一项内容加以规定,因为nlme假设后一项要素(subject)在前一种要素(one <>>>>>>。 加上这种实际的分组结构,不能再添加具有相关性的成分。 如果没有相关的随机影响,可以增加跨面的层面。

summary(Model <- lme(
  rating ~ 1 + position, random = list(one = pdBlocked(list(
    pdIdent(~ 0 + subject), pdIdent(~ 0 + subject:position), 
    pdIdent(~ 0 + comparison)))),
  data = Data %>% mutate(one = factor(1))))
summary(Model <- lme(
  rating ~ 1 + position, random = list(
    one = pdIdent(~ 0 + subject), 
    one = pdIdent(~ 0 + subject:position), 
    one = pdIdent(~ 0 + comparison)),
  data = Data %>% mutate(one = factor(1))))
ranef(Model)
"       AIC      BIC    logLik
  186.6318 198.9944 -87.31588
 Block 1: subject1, subject2, subject3, subject4, subject5, subject6
 Formula: ~0 + subject | one
 Structure: Multiple of an Identity
         subject1  subject2  subject3  subject4  subject5  subject6
StdDev: 0.2801523 0.2801523 0.2801523 0.2801523 0.2801523 0.2801523
 Block 2: subject1:position, subject2:position, subject3:position, 
 Formula: ~0 + subject:position | one
 Structure: Multiple of an Identity
        subject1:position subject2:position subject3:position subject4:position
StdDev:      7.413267e-06      7.413267e-06      7.413267e-06      7.413267e-06
        subject5:position subject6:position
StdDev:      7.413267e-06      7.413267e-06
 Block 3: comparison1, comparison2, comparison3, comparison4, comparison5,
 Formula: ~0 + comparison | one
 Structure: Multiple of an Identity
        comparison1 comparison2 comparison3 comparison4 comparison5 comparison6
StdDev:   0.2811532   0.2811532   0.2811532   0.2811532   0.2811532   0.2811532
        comparison7 comparison8 comparison9 comparison10  Residual
StdDev:   0.2811532   0.2811532   0.2811532    0.2811532 0.9390491
Fixed effects:  rating ~ 1 + position 
                Value Std.Error DF   t-value p-value
(Intercept)  3.898558 0.3016027 58 12.926139  0.0000
position    -0.139132 0.0427492 58 -3.254607  0.0019
    subject1   subject2  subject3    subject4    subject5  subject6
1 -0.1569707 -0.2511531 0.2197589 -0.01569707 -0.01569706 0.2197589
  subject1:position subject2:position subject3:position subject4:position
1     -3.832871e-10     -2.115069e-10      1.345151e-09     -3.438398e-10
  subject5:position subject6:position comparison1 comparison2 comparison3
1     -7.796287e-10      3.731118e-10  -0.1145524  0.08768834   -0.271683
  comparison4 comparison5 comparison6 comparison7 comparison8 comparison9
1   0.2367088  -0.0370021  -0.1535825   0.1186084  -0.1388825   0.1104984
  comparison10
1    0.1621986"

As both lmer and lme with random-effects correlation report an estimate of the correlation coefficient at its boundary, they are over specified and will benefit from a simpler specification. Without random-effects correlation, many crossed terms can be estimated, either in pdBlocked() or a list of crossed components named by the fake grouping variable. From the above summary, the standard deviation of position is very small, compared with those of the other two random effects, thus worth dropping. It is fine to reuse the same grouping variable in multiple nested structures to mimic crossed random effects, as group one nested within one has still only one unique level. However, it can be a challenge for postestimation tools to identify the correct level.

summary(Model <- lme(
  rating ~ 1 + position, random = list(
    one = pdIdent(~ 0 + subject), 
    one = pdIdent(~ 0 + comparison)),
  data = Data %>% mutate(one = factor(1))))
ranef(Model)
intervals(Model)
"       AIC     BIC    logLik
  184.6318 194.934 -87.31588
 Formula: ~0 + subject | one
 Structure: Multiple of an Identity
         subject1  subject2  subject3  subject4  subject5  subject6
StdDev: 0.2801524 0.2801524 0.2801524 0.2801524 0.2801524 0.2801524
 Formula: ~0 + comparison | one %in% one
 Structure: Multiple of an Identity
        comparison1 comparison2 comparison3 comparison4 comparison5 comparison6
StdDev:   0.2811532   0.2811532   0.2811532   0.2811532   0.2811532   0.2811532
        comparison7 comparison8 comparison9 comparison10  Residual
StdDev:   0.2811532   0.2811532   0.2811532    0.2811532 0.9390491
                Value Std.Error DF   t-value p-value
(Intercept)  3.898558 0.3016027 58 12.926139  0.0000
position    -0.139132 0.0427492 58 -3.254607  0.0019
Level: one 
    subject1   subject2 subject3    subject4    subject5 subject6
1 -0.1569707 -0.2511531 0.219759 -0.01569707 -0.01569707 0.219759
Level: one %in% one 
  comparison1 comparison2 comparison3 comparison4 comparison5 comparison6
1  -0.1145525  0.08768836   -0.271683   0.2367089 -0.03700211  -0.1535825
  comparison7 comparison8 comparison9 comparison10
1   0.1186084  -0.1388825   0.1104984    0.1621986
 Random Effects:
  Level: one            lower      est.    upper
sd(0 + comparison) 0.07356078 0.2801524 1.066946
  Level: one            lower      est.    upper
sd(0 + comparison) 0.07356078 0.2801524 1.066946"
summary(Model <- lme(
  rating ~ 1 + position, random = list(
    one = pdIdent(~ 0 + subject), 
    two = pdIdent(~ 0 + comparison)),
  data = Data %>% mutate(one = factor(1), two = factor(2))))
ranef(Model)
intervals(Model)
"Approximate 95% confidence intervals
 Fixed effects:
                 lower       est.       upper
(Intercept)  3.2948350  3.8985584  4.50228184
position    -0.2247037 -0.1391318 -0.05356001
 Random Effects:
  Level: one         lower      est.    upper
sd(0 + subject) 0.07356078 0.2801524 1.066946
  Level: two           lower      est.    upper
sd(0 + comparison) 0.0709893 0.2811532 1.113508
 Within-group standard error:
    lower      est.     upper 
0.7621853 0.9390491 1.1569539 "

由于通过<代码>subjectcomparison的随机拦截、随机斜坡和切除的相互关系,上述模型在所有测试中具有最小的AIC和BIC。 通过将伪造的nes塞变数重新命名为不同的横跨术语,intervals()不再混淆随机影响术语以提取。 如果在多个层次上使用同样的排外变量,则只报告排泄结构底层层的信任间隔。 采用<代码>pdBlock(>>办法,不会受到这一可变命名问题的影响。

summary(Model <- lme(
  rating ~ 1 + position, random = list(one = pdBlocked(list(
    pdIdent(~ 0 + subject), pdIdent(~ 0 + comparison)))),
  data = Data %>% mutate(one = factor(1))))
intervals(Model)
" Random Effects:
  Level: one            lower      est.    upper
sd(0 + subject)    0.07362742 0.2801524 1.065980
sd(0 + comparison) 0.07107054 0.2811532 1.112235"

简言之,通过nes,允许“任意横跨和nes的随机影响”。 然而,只有一种[与]越境随机影响的相关性才能估算。 在设计矩阵中,如<代码>pdIdent(~ 0+话题)将添加6列指标,subject = 1, ......,subject = 6,因为删除了拦截词。 每一栏均允许有与其他栏目不同的随机斜坡(而不是随机拦截)。 因此,确保<条码>目标是个不构成愤怒的因素,否则,只有一栏的分类账才产生单一组别的偏差,而不是按主题分列的六个偏差。 然而,pdIdent(>>>要求这六个栏目中所有各栏均对随机斜坡有相同的差异。 因此,在<代码>summary()中,仅估算一个参数(专题指标随机斜坡的标准偏差),而在<代码>ranef(<>)中对这一随机影响的6个不同评价。





相关问题
How to plot fitted model over observed time series

This is a really really simple question to which I seem to be entirely unable to get a solution. I would like to do a scatter plot of an observed time series in R, and over this I want to plot the ...

REvolution for R

since the latest Ubuntu release (karmic koala), I noticed that the internal R package advertises on start-up the REvolution package. It seems to be a library collection for high-performance matrix ...

R - capturing elements of R output into text files

I am trying to run an analysis by invoking R through the command line as follows: R --no-save < SampleProgram.R > SampleProgram.opt For example, consider the simple R program below: mydata =...

R statistical package: wrapping GOFrame objects

I m trying to generate GOFrame objects to generate a gene ontology mapping in R for unsupported organisms (see http://www.bioconductor.org/packages/release/bioc/vignettes/GOstats/inst/doc/...

Changing the order of dodged bars in ggplot2 barplot

I have a dataframe df.all and I m plotting it in a bar plot with ggplot2 using the code below. I d like to make it so that the order of the dodged bars is flipped. That is, so that the bars labeled "...

Strange error when using sparse matrices and glmnet

I m getting a weird error when training a glmnet regression. invalid class "dgCMatrix" object: length(Dimnames[[2]]) must match Dim[2] It only happens occasionally, and perhaps only under larger ...

Generating non-duplicate combination pairs in R

Sorry for the non-descriptive title but I don t know whether there s a word for what I m trying to achieve. Let s assume that I have a list of names of different classes like c( 1 , 2 , 3 , 4 ) ...

Per panel smoothing in ggplot2

I m plotting a group of curves, using facet in ggplot2. I d like to have a smoother applied to plots where there are enough points to smooth, but not on plots with very few points. In particular I d ...

热门标签