Exam7.1: Example 7.1 from Generalized Linear Mixed Models: Modern...

Description Author(s) References See Also Examples

Description

Exam7.1 explains multifactor models with all factors qualitative

Author(s)

  1. Muhammad Yaseen (myaseen208@gmail.com)

  2. Adeela Munawar (adeela.uaf@gmail.com)

References

  1. Stroup, W. W. (2012). Generalized Linear Mixed Models: Modern Concepts, Methods and Applications. CRC Press.

See Also

DataSet7.1

Examples

  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
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
library(lsmeans)
library(car)
data(DataSet7.1)

DataSet7.1$a <- factor(x = DataSet7.1$a)
DataSet7.1$b <- factor(x = DataSet7.1$b)

Exam7.1.lm1 <-
     lm(
        formula     = y ~ a + b + a*b
      , data        = DataSet7.1
    # , subset
    # , weights
    # , na.action
      , method      = "qr"
      , model       = TRUE
    # , x           = FALSE
    # , y           = FALSE
      , qr          = TRUE
      , singular.ok = TRUE
      , contrasts   = NULL
    # , offset
    # , ...
         )

summary( Exam7.1.lm1 )                                   
anova(Exam7.1.lm1)
##---Result obtained as in SLICE statement in SAS for a0 & a1 
library(phia)
a0 <- list(a=c("0"=1))
phia::testInteractions(Exam7.1.lm1, custom=a0, across="b")
a1 <- list(a=c("1"=1))
phia::testInteractions(Exam7.1.lm1, custom=a1, across="b")

 
##---Interaction plot
lsmip( 
       object  = Exam7.1.lm1
     , formula = a~b
     , ylab    = "y Lsmeans"
     , main    = "Lsmeans for a*b"
      )
#-------------------------------------------------------------
## Individula least squares treatment means 
#-------------------------------------------------------------
Lsm7.1 <-
     lsmeans::lsmeans(
         object  = Exam7.1.lm1
       , specs   = ~a*b
     # , ...
     )

Lsm7.1
##---Simpe effects comparison of interaction by a 
##   (but it doesn't give the same p-value as in article 7.4.2 page#215)
SimpleEff7.1 <-
 lsmeans::lsmeans(
         object  = Exam7.1.lm1
       , specs   = pairwise~b|a
     # , ...
     )$contrasts

SimpleEff7.1

##---Alternative method of pairwise comparisons by applying contrast
##   coefficient (gives the same p-value as in 7.4.2)
ContrastLsm7.1 <-
    lsmeans::contrast(
              Lsm7.1
            , list (
                    c1 = c(1,0,-1,0,0,0)
                  , c2 = c(1,0,0,0,-1,0)
                  , c3 = c(0,0,1,0,-1,0)
                  , c4 = c(0,1,0,-1,0,0)
                  , c5 = c(0,1,0,0,0,-1)
                  , c6 = c(0,1,0,0,-1,0)
                  ) 
      )
 
ContrastLsm7.1

##---Nested Model (page 216)----
Exam7.1.lm2 <-
     lm(
        formula     = y ~ a + a %in% b
      , data        = DataSet7.1
    # , subset
    # , weights
    # , na.action
      , method      = "qr"
      , model       = TRUE
    # , x           = FALSE
    # , y           = FALSE
      , qr          = TRUE
      , singular.ok = TRUE
      , contrasts   = NULL
    # , offset
    # , ...
   )

summary( Exam7.1.lm2 )                                   
anova(Exam7.1.lm2)

ContrastA0lm2 <- car::linearHypothesis(Exam7.1.lm2, c("a0:b1=a0:b2"))
ContrastA0lm2
ContrastA1lm2 <- car::linearHypothesis(Exam7.1.lm2,c("a1:b1=a1:b2"))
ContrastA1lm2

 ##---Bonferroni's adjusted p-values
SimpleEff7.1B <-
 lsmeans::lsmeans(
         object  = Exam7.1.lm2
       , specs   = pairwise~b|a
       , adjust  = "bonferroni"
     )$contrasts

SimpleEff7.1B

##---Alternative method of pairwise comparisons by applying contrast coefficient with Bonferroni adjustment
Bonferroni7.1 <-
    lsmeans::contrast(
          Lsm7.1
        , list(
            c1 = c(1,0,-1,0,0,0)
          , c2 = c(1,0,0,0,-1,0)
          , c3 = c(0,0,1,0,-1,0)
          , c4 = c(0,1,0,-1,0,0)
          , c5 = c(0,1,0,0,0,-1)
          , c6 = c(0,1,0,0,-1,0)
              )
        , adjust="bonferroni" 
         )
Bonferroni7.1

myaseen208/StroupGLMM documentation built on May 10, 2019, 8:28 a.m.