5  第5章

パッケージの呼び出し.

library(tidyverse)
library(magrittr)
library(gnm)
library(broom)

モデル適合度を表示するための関数を準備する.すべてgnmによって推定を行う.

# Specify the constrasts
# Here, we use sum to zero contrast.
options(width=90, contrasts = c(factor="contr.sum", ordered="contr.treatment"))

# Define a function which calculation BIC based on L2 statistics
model.summary <- function(obj, Model = NULL){
  if (sum(class(obj) == "gnm") != 1)
    stop("estimate with gnm")
  aic <- obj$deviance - obj$df * 2 # AIC(L2)
  bic <- obj$deviance - obj$df * log(sum(obj$y)) #BIC(L2)
  delta <- 100 * sum(abs(obj$y - obj$fitted.values)) / (2 * sum(obj$y))
  p <- pchisq(obj$deviance, obj$df, lower.tail = FALSE)     #p<-ifelse(p<0.001,"<0.001",p)
  result <- matrix(0, 1, 7)
  if (is.null(Model)){ 
  Model <- deparse(substitute(obj))
  }
  result <- tibble(
    "Model Description" = Model,
    "df" = obj$df,
    "L2" = obj$deviance,
    #"AIC(L2)" = aic,
    "BIC" = bic,
    "Delta" = delta,
    "p" = p
  )
  return(result)
}

5.1 表5.1

# Table 5.1
Freq <- c(118, 28,  32,  6,  7,
        218, 28,  97, 12, 14,
         11,  2,   4,  1,  1,
        104, 22,  61,  8,  5,
        117, 24,  70,  9,  7,
         42,  6,  20,  2,  0,
         48, 16, 104, 14,  9,
        128, 52,  81, 14, 12)

worries <- gl(8,5)
situations <- gl(5,1,8*5)

tab5.1 <- tibble(Freq, worries, situations)

# Model 1 - Independence
m1 <- tab5.1 |> 
  gnm(Freq ~ worries + situations,
      family = poisson,
      trace = F,
      tolerance = 1e-12,
      data = _)
model.summary(m1)
# A tibble: 1 × 6
  `Model Description`    df    L2   BIC Delta        p
  <chr>               <int> <dbl> <dbl> <dbl>    <dbl>
1 m1                     28  121. -84.3  9.84 1.31e-13
# Model 2 - RC(1)
m2 <- tab5.1 |> 
  gnm(Freq ~ worries + situations + Mult(1, worries, situations),
      family = poisson,
      trace = F,
      tolerance = 1e-12,
      data = _)
Initialising
Running start-up iterations..
Running main iterations...................................................................
.........
Done
model.summary(m2)
# A tibble: 1 × 6
  `Model Description`    df    L2   BIC Delta      p
  <chr>               <int> <dbl> <dbl> <dbl>  <dbl>
1 m2                     18  29.2 -103.  4.01 0.0461
# Model 3 - RC(1) with equality constraints on
# MIL=ECO=MTO, ENR=SAB=OTH and ASAF=IFAA
worries.a <- worries
levels(worries.a) <- factor(c(1, 2, 2, 3, 3, 2, 4, 3))
worries.a
 [1] 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 4 4 4 4 4 3 3 3 3 3
Levels: 1 2 3 4
situations.a <- situations
levels(situations.a) <- factor(c(1, 2, 3, 3, 4))
situations.a
 [1] 1 2 3 3 4 1 2 3 3 4 1 2 3 3 4 1 2 3 3 4 1 2 3 3 4 1 2 3 3 4 1 2 3 3 4 1 2 3 3 4
Levels: 1 2 3 4
m3.un <- tab5.1 |> 
  gnm(Freq ~ worries + situations + 
        Mult(1, worries.a, situations.a), 
           family = poisson,
           trace = F, 
           tolerance = 1e-12,
      data = _)
Initialising
Running start-up iterations..
Running main iterations..........................................................
Done
model.summary(m3.un)
# A tibble: 1 × 6
  `Model Description`    df    L2   BIC Delta     p
  <chr>               <int> <dbl> <dbl> <dbl> <dbl>
1 m3.un                  23  29.6 -139.  4.08 0.161
mu <- getContrasts(m3.un, 
                 pickCoef(m3.un, "[.]worries.a"),
                 ref = c(1, 3, 3, 1) / 8, scaleRef = c(1, 3, 3, 1) / 8,
                 scaleWeights = c(1, 3, 3, 1))
nu <- getContrasts(m3.un, 
                 pickCoef(m3.un, "[.]situations.a"),
                 ref = c(1, 1, 2, 1) / 5, scaleRef = c(1, 1, 2, 1) / 5,
                 scaleWeights = c(1, 1, 2, 1))

con <- c(mu$qvframe[, 1][c(1, 4)], nu$qvframe[, 1][c(1, 4)])
m3 <- gnm(Freq ~ worries + situations + Mult(1, worries.a, situations.a), 
          family = poisson,
          constrain = c(14, 17, 18, 21), constrainTo = con,
          trace = F, 
          tolerance = 1e-12)
Initialising
Running start-up iterations..
Running main iterations....................................................
Done
summary(m3);mu;nu;model.summary(m3.un)

Call:
gnm(formula = Freq ~ worries + situations + Mult(1, worries.a, 
    situations.a), constrain = c(14, 17, 18, 21), constrainTo = con, 
    family = poisson, tolerance = 1e-12, trace = F)

Deviance Residuals: 
     Min        1Q    Median        3Q       Max  
-2.55631  -0.35180   0.05564   0.41188   2.91020  

Coefficients:
                                    Estimate Std. Error z value Pr(>|z|)    
(Intercept)                          2.85834    0.05067  56.406  < 2e-16 ***
worries1                             0.10499    0.16439   0.639  0.52304    
worries2                             0.88097    0.08378  10.515  < 2e-16 ***
worries3                            -2.08538    0.21086  -9.890  < 2e-16 ***
worries4                             0.34128    0.07460   4.575 4.77e-06 ***
worries5                             0.46792    0.07155   6.540 6.16e-11 ***
worries6                            -0.78133    0.12531  -6.235 4.51e-10 ***
worries7                             0.36910    0.28578   1.292  0.19651    
situations1                          1.43713    0.08740  16.443  < 2e-16 ***
situations2                         -0.02940    0.07766  -0.379  0.70501    
situations3                          0.88374    0.07261  12.172  < 2e-16 ***
situations4                         -1.07721    0.11438  -9.418  < 2e-16 ***
Mult(., worries.a, situations.a).    1.35718    0.50966   2.663  0.00775 ** 
Mult(1, ., situations.a).worries.a1 -0.42724         NA      NA       NA    
Mult(1, ., situations.a).worries.a2 -0.17319    0.11548  -1.500  0.13367    
Mult(1, ., situations.a).worries.a3  0.03189    0.09790   0.326  0.74459    
Mult(1, ., situations.a).worries.a4  0.85113         NA      NA       NA    
Mult(1, worries.a, .).situations.a1 -0.69874         NA      NA       NA    
Mult(1, worries.a, .).situations.a2 -0.29537    0.22737  -1.299  0.19392    
Mult(1, worries.a, .).situations.a3  0.45726    0.41619   1.099  0.27191    
Mult(1, worries.a, .).situations.a4  0.07959         NA      NA       NA    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for poisson family taken to be 1)

Std. Error is NA where coefficient has been constrained or is unidentified

Residual deviance: 29.612 on 23 degrees of freedom
AIC: 249.9

Number of iterations: 52
                                      Estimate Std. Error
Mult(1, ., situations.a).worries.a1 -0.4272363 0.09380998
Mult(1, ., situations.a).worries.a2 -0.1731936 0.04675330
Mult(1, ., situations.a).worries.a3  0.0318943 0.04574940
Mult(1, ., situations.a).worries.a4  0.8511342 0.03998795
                                       Estimate Std. Error
Mult(1, worries.a, .).situations.a1 -0.69874471 0.08798182
Mult(1, worries.a, .).situations.a2 -0.29537072 0.13782241
Mult(1, worries.a, .).situations.a3  0.45726207 0.06815138
Mult(1, worries.a, .).situations.a4  0.07959129 0.22251866
# A tibble: 1 × 6
  `Model Description`    df    L2   BIC Delta     p
  <chr>               <int> <dbl> <dbl> <dbl> <dbl>
1 m3.un                  23  29.6 -139.  4.08 0.161
# Model 4 - RC(1) with equality constraints on
# MIL=ECO=MTO=ENR=SAB=OTH and ASAF=IFAA
worries.b <- worries
levels(worries.b) <- factor(c(1, 2, 2, 2, 2, 2, 3, 2))
worries.b
 [1] 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 2 2 2 2 2
Levels: 1 2 3
m4.un <- tab5.1 |> 
  gnm(Freq ~ worries + situations + Mult(1, worries.b, situations.a), 
           family = poisson,
           trace = F, 
           tolerance = 1e-12,
      data = _)
Initialising
Running start-up iterations..
Running main iterations..........................
Done
model.summary(m4.un)
# A tibble: 1 × 6
  `Model Description`    df    L2   BIC Delta      p
  <chr>               <int> <dbl> <dbl> <dbl>  <dbl>
1 m4.un                  24  34.5 -142.  4.80 0.0760
# Model 5
m5.un <- tab5.1 |> 
  gnm(Freq ~ worries + situations + 
        Mult(1, worries, situations, inst = 1) + 
        Mult(1, worries, situations, inst = 2), 
      family = poisson,
      trace = F, tolerance = 1e-12,
      data = _)
Initialising
Running start-up iterations..
Running main iterations...................................................................

Done
model.summary(m5.un)
# A tibble: 1 × 6
  `Model Description`    df    L2   BIC Delta     p
  <chr>               <int> <dbl> <dbl> <dbl> <dbl>
1 m5.un                  10  6.81 -66.7 0.872 0.743
# Model 6 - RC(2) with equality constraints on
# ECO=MTO=MIL=ENR=SAB and ASAF=IFAA in both dimensions
worries.c <- worries
levels(worries.c) <- factor(c(1,2,2,2,2,2,3,4))
worries.c
 [1] 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4
Levels: 1 2 3 4
set.seed(12345)
m6.un <- tab5.1 |> 
  gnm(Freq ~ worries + situations + 
        Mult(1, worries.c, situations.a, inst = 1) + 
        Mult(1, worries.c, situations.a, inst = 2), 
      family = poisson,
      trace = F, 
      tolerance = 1e-12,
      data = _)
Initialising
Running start-up iterations..
Running main iterations............................................
Done
model.summary(m6.un)
# A tibble: 1 × 6
  `Model Description`    df    L2   BIC Delta     p
  <chr>               <int> <dbl> <dbl> <dbl> <dbl>
1 m6.un                  20  13.7 -133.  2.82 0.847

5.2 表5.4

最適尺度法として連関モデルを利用する.

# Table 5.4
Freq<-c(1096,  1847,  1255,  925,    3321,  6123,  6830,  5524,
        1541,  3134,  3145, 3300,    1915,  4429,  7035,  9421,
        4183,  5139,  1857, 1272,    8080,  8586,  4788,  4294,
        6033,  9211,  5046, 1058,   28130, 44589, 20074,  3408,
        4354, 13430, 18670, 9821,    2250,  9075, 18286, 14358,
       14587, 31470, 16390, 3751,    8242, 17532, 12825,  3956,
        1517,  5820,  6197, 2372,     721,  2909,  4141,  2070,
        3581,  9268,  5463, 1007,    1341,  3808,  3163,   815,
        1454,  3109,  1055,  888,     563,  1909,  1018,  1051,
        3237,  3851,   377,  102,     731,   858,   247,    84,
       14882, 22182,  5363, 1136,   11650, 15818,  5524,  2122,
        6033,  3475,    63,   18,    1603,  1005,    30,    16,
        
        5968,  8783,  7701, 6483,    8733, 14329, 19386, 28143,
        1011,  2162,  3536, 6649,     697,  1299,  2362, 10796,
        3214,  3621,  2485, 3177,     793,  1134,  1292,  3597,
       11532, 16837,  6975, 1839,    2563,  2995,  2060,  1600,
        1009,  2719,  3521, 3409,     296,   503,   626,  1273,
        1586,  3025,  1726,  668,     245,   415,   238,   218,
         387,   941,   564,  316,      86,   138,    79,    48,
         994,  1988,   542,  145,     158,   259,   101,    56,
         171,   409,   223,  245,      65,   172,    99,   174,
         293,   290,    67,   31,      32,    62,    18,    30,
        4288,  4916,  1452,  766,     616,   794,   347,   300,
         370,   186,     3,    4,      67,    37,     5,     2)

income <- gl(4, 1, 192)  # 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 ...
occ <- gl(12, 8, 192)  # 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 ...
edu1 <- rep(c(1,2), each = 4, length.out = 96)
edu2 <- rep(c(3,4), each = 4, length.out = 96)
educ <- c(edu1, edu2) |> factor()

# 確認
matrix(income, nrow = 24, ncol = 8, byrow = TRUE)
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
 [1,] "1"  "2"  "3"  "4"  "1"  "2"  "3"  "4" 
 [2,] "1"  "2"  "3"  "4"  "1"  "2"  "3"  "4" 
 [3,] "1"  "2"  "3"  "4"  "1"  "2"  "3"  "4" 
 [4,] "1"  "2"  "3"  "4"  "1"  "2"  "3"  "4" 
 [5,] "1"  "2"  "3"  "4"  "1"  "2"  "3"  "4" 
 [6,] "1"  "2"  "3"  "4"  "1"  "2"  "3"  "4" 
 [7,] "1"  "2"  "3"  "4"  "1"  "2"  "3"  "4" 
 [8,] "1"  "2"  "3"  "4"  "1"  "2"  "3"  "4" 
 [9,] "1"  "2"  "3"  "4"  "1"  "2"  "3"  "4" 
[10,] "1"  "2"  "3"  "4"  "1"  "2"  "3"  "4" 
[11,] "1"  "2"  "3"  "4"  "1"  "2"  "3"  "4" 
[12,] "1"  "2"  "3"  "4"  "1"  "2"  "3"  "4" 
[13,] "1"  "2"  "3"  "4"  "1"  "2"  "3"  "4" 
[14,] "1"  "2"  "3"  "4"  "1"  "2"  "3"  "4" 
[15,] "1"  "2"  "3"  "4"  "1"  "2"  "3"  "4" 
[16,] "1"  "2"  "3"  "4"  "1"  "2"  "3"  "4" 
[17,] "1"  "2"  "3"  "4"  "1"  "2"  "3"  "4" 
[18,] "1"  "2"  "3"  "4"  "1"  "2"  "3"  "4" 
[19,] "1"  "2"  "3"  "4"  "1"  "2"  "3"  "4" 
[20,] "1"  "2"  "3"  "4"  "1"  "2"  "3"  "4" 
[21,] "1"  "2"  "3"  "4"  "1"  "2"  "3"  "4" 
[22,] "1"  "2"  "3"  "4"  "1"  "2"  "3"  "4" 
[23,] "1"  "2"  "3"  "4"  "1"  "2"  "3"  "4" 
[24,] "1"  "2"  "3"  "4"  "1"  "2"  "3"  "4" 
matrix(occ, nrow = 24, ncol = 8, byrow = TRUE)
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
 [1,] "1"  "1"  "1"  "1"  "1"  "1"  "1"  "1" 
 [2,] "2"  "2"  "2"  "2"  "2"  "2"  "2"  "2" 
 [3,] "3"  "3"  "3"  "3"  "3"  "3"  "3"  "3" 
 [4,] "4"  "4"  "4"  "4"  "4"  "4"  "4"  "4" 
 [5,] "5"  "5"  "5"  "5"  "5"  "5"  "5"  "5" 
 [6,] "6"  "6"  "6"  "6"  "6"  "6"  "6"  "6" 
 [7,] "7"  "7"  "7"  "7"  "7"  "7"  "7"  "7" 
 [8,] "8"  "8"  "8"  "8"  "8"  "8"  "8"  "8" 
 [9,] "9"  "9"  "9"  "9"  "9"  "9"  "9"  "9" 
[10,] "10" "10" "10" "10" "10" "10" "10" "10"
[11,] "11" "11" "11" "11" "11" "11" "11" "11"
[12,] "12" "12" "12" "12" "12" "12" "12" "12"
[13,] "1"  "1"  "1"  "1"  "1"  "1"  "1"  "1" 
[14,] "2"  "2"  "2"  "2"  "2"  "2"  "2"  "2" 
[15,] "3"  "3"  "3"  "3"  "3"  "3"  "3"  "3" 
[16,] "4"  "4"  "4"  "4"  "4"  "4"  "4"  "4" 
[17,] "5"  "5"  "5"  "5"  "5"  "5"  "5"  "5" 
[18,] "6"  "6"  "6"  "6"  "6"  "6"  "6"  "6" 
[19,] "7"  "7"  "7"  "7"  "7"  "7"  "7"  "7" 
[20,] "8"  "8"  "8"  "8"  "8"  "8"  "8"  "8" 
[21,] "9"  "9"  "9"  "9"  "9"  "9"  "9"  "9" 
[22,] "10" "10" "10" "10" "10" "10" "10" "10"
[23,] "11" "11" "11" "11" "11" "11" "11" "11"
[24,] "12" "12" "12" "12" "12" "12" "12" "12"
matrix(educ, nrow = 24, ncol = 8, byrow = TRUE)
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
 [1,] "1"  "1"  "1"  "1"  "2"  "2"  "2"  "2" 
 [2,] "1"  "1"  "1"  "1"  "2"  "2"  "2"  "2" 
 [3,] "1"  "1"  "1"  "1"  "2"  "2"  "2"  "2" 
 [4,] "1"  "1"  "1"  "1"  "2"  "2"  "2"  "2" 
 [5,] "1"  "1"  "1"  "1"  "2"  "2"  "2"  "2" 
 [6,] "1"  "1"  "1"  "1"  "2"  "2"  "2"  "2" 
 [7,] "1"  "1"  "1"  "1"  "2"  "2"  "2"  "2" 
 [8,] "1"  "1"  "1"  "1"  "2"  "2"  "2"  "2" 
 [9,] "1"  "1"  "1"  "1"  "2"  "2"  "2"  "2" 
[10,] "1"  "1"  "1"  "1"  "2"  "2"  "2"  "2" 
[11,] "1"  "1"  "1"  "1"  "2"  "2"  "2"  "2" 
[12,] "1"  "1"  "1"  "1"  "2"  "2"  "2"  "2" 
[13,] "3"  "3"  "3"  "3"  "4"  "4"  "4"  "4" 
[14,] "3"  "3"  "3"  "3"  "4"  "4"  "4"  "4" 
[15,] "3"  "3"  "3"  "3"  "4"  "4"  "4"  "4" 
[16,] "3"  "3"  "3"  "3"  "4"  "4"  "4"  "4" 
[17,] "3"  "3"  "3"  "3"  "4"  "4"  "4"  "4" 
[18,] "3"  "3"  "3"  "3"  "4"  "4"  "4"  "4" 
[19,] "3"  "3"  "3"  "3"  "4"  "4"  "4"  "4" 
[20,] "3"  "3"  "3"  "3"  "4"  "4"  "4"  "4" 
[21,] "3"  "3"  "3"  "3"  "4"  "4"  "4"  "4" 
[22,] "3"  "3"  "3"  "3"  "4"  "4"  "4"  "4" 
[23,] "3"  "3"  "3"  "3"  "4"  "4"  "4"  "4" 
[24,] "3"  "3"  "3"  "3"  "4"  "4"  "4"  "4" 
# 分析用データ
tab5.4 <- data.frame(Freq, income, occ, educ)
########################################################################################

# Table 5.5
# Model 1: Complete Independence
m1 <- tab5.4 |> 
  gnm(Freq ~ educ + occ + income, 
          data = _, 
          family = poisson, 
          tolerance = 1e-12)
model.summary(m1) 
# A tibble: 1 × 6
  `Model Description`    df      L2     BIC Delta     p
  <chr>               <int>   <dbl>   <dbl> <dbl> <dbl>
1 m1                    174 586906. 584537.  33.8     0
# Model 2: Conditional Independence
m2 <- tab5.4 |> 
  gnm(Freq ~ educ * occ + income * occ, 
          data = _, 
          family = poisson, 
          tolerance = 1e-12)
model.summary(m2)
# A tibble: 1 × 6
  `Model Description`    df     L2    BIC Delta     p
  <chr>               <int>  <dbl>  <dbl> <dbl> <dbl>
1 m2                    108 27957. 26487.  6.00     0
# Model 3: All two-way interaction
m3 <- tab5.4 |> 
  gnm(Freq ~ educ * occ + income * occ + educ * income, 
          data = _, 
          family = poisson, tolerance = 1e-12)
model.summary(m3)
# A tibble: 1 × 6
  `Model Description`    df    L2   BIC Delta     p
  <chr>               <int> <dbl> <dbl> <dbl> <dbl>
1 m3                     99 6540. 5192.  2.64     0
# Model 4: RC(1)+RL(1) partial association
m4 <- tab5.4 |> 
  gnm(Freq ~ educ + occ + income + Mult(1, occ, educ) + Mult(1, occ, income),
          data = _, 
          family = poisson,
          tolerance = 1e-12)
Initialising
Running start-up iterations..
Running main iterations...................................................................
.....
Done
model.summary(m4)
# A tibble: 1 × 6
  `Model Description`    df     L2    BIC Delta     p
  <chr>               <int>  <dbl>  <dbl> <dbl> <dbl>
1 m4                    148 70861. 68846.  11.2     0
# Model 5: Model 4 with consistent row (occupation) scores
m5 <- tab5.4 |> 
  gnm(Freq ~ educ + occ + income + Mult(1, occ, educ + income),
          data = _, 
          family = poisson, 
          tolerance = 1e-12)
Initialising
Running start-up iterations..
Running main iterations...................................................................
..........................................................................................
......................................
Done
model.summary(m5)
# A tibble: 1 × 6
  `Model Description`    df      L2     BIC Delta     p
  <chr>               <int>   <dbl>   <dbl> <dbl> <dbl>
1 m5                    158 185515. 183364.  18.3     0
mu <- getContrasts(model = m5, 
                   set = pickCoef(m5, "[.]occ")[1:12],
                   ref = "mean", 
                   scaleRef = "mean", 
                   scaleWeights = "unit")
mu
                                   Estimate  Std. Error
Mult(1, ., educ + income).occ1  -0.54805987 0.001793134
Mult(1, ., educ + income).occ2  -0.38746682 0.001271727
Mult(1, ., educ + income).occ3  -0.21717857 0.001291161
Mult(1, ., educ + income).occ4  -0.14398575 0.001002368
Mult(1, ., educ + income).occ5  -0.08607017 0.001273939
Mult(1, ., educ + income).occ6   0.15776750 0.001820890
Mult(1, ., educ + income).occ7   0.05029005 0.002500252
Mult(1, ., educ + income).occ8   0.14092026 0.002598170
Mult(1, ., educ + income).occ9   0.02379483 0.003466324
Mult(1, ., educ + income).occ10  0.39930723 0.004697125
Mult(1, ., educ + income).occ11  0.10479535 0.001779509
Mult(1, ., educ + income).occ12  0.50588597 0.004258340
# Model 6: RC(1)+RL(1)+CL(1) partial association
m6 <- tab5.4 |> 
  gnm(Freq ~ educ + occ + income + 
        Mult(1, occ, educ) + 
        Mult(1, occ, income) +
        Mult(1, educ, income),
      data = _, 
      family = poisson, 
      tolerance = 1e-12)
Initialising
Running start-up iterations..
Running main iterations...................................................................
..
Done
model.summary(m6)
# A tibble: 1 × 6
  `Model Description`    df     L2    BIC Delta     p
  <chr>               <int>  <dbl>  <dbl> <dbl> <dbl>
1 m6                    143 42101. 40154.  8.27     0
# Model 7: Model 6 with consistent row (occupation) scores
m7 <- tab5.4 |> 
  gnm(Freq ~ educ + occ + income + 
        Mult(1, occ, educ + income) + 
        Mult(1, educ, income),
      data = _, 
      family = poisson, 
      tolerance = 1e-12)
Initialising
Running start-up iterations..
Running main iterations...................................................................
..........................................................................................
..........................................................................................
........................
Done
model.summary(m7)
# A tibble: 1 × 6
  `Model Description`    df      L2     BIC Delta     p
  <chr>               <int>   <dbl>   <dbl> <dbl> <dbl>
1 m7                    153 174073. 171990.  17.8     0
mu <- getContrasts(model = m7, 
                   set = pickCoef(m7, "[.]occ"),
                   ref = "mean", 
                   scaleRef = "mean", 
                   scaleWeights = "unit")
mu
                                   Estimate  Std. Error
Mult(1, ., educ + income).occ1   0.56931429 0.001883457
Mult(1, ., educ + income).occ2   0.37928161 0.001275097
Mult(1, ., educ + income).occ3   0.22247516 0.001381547
Mult(1, ., educ + income).occ4   0.17045561 0.001046926
Mult(1, ., educ + income).occ5   0.05464251 0.001423421
Mult(1, ., educ + income).occ6  -0.16380722 0.001871288
Mult(1, ., educ + income).occ7  -0.07890623 0.002667870
Mult(1, ., educ + income).occ8  -0.14504188 0.002680434
Mult(1, ., educ + income).occ9  -0.04282708 0.003676179
Mult(1, ., educ + income).occ10 -0.39013284 0.004810546
Mult(1, ., educ + income).occ11 -0.09178943 0.001794307
Mult(1, ., educ + income).occ12 -0.48366450 0.004397647
# Model 8: model 6 with consistent row, column and layer scores
# currently, this might not be fitted with gnm!
  • 表5.5のモデル1については原著および訳書ともに\(\Delta\)の値が間違っているので注意すること(印刷後に修正漏れに気づきました).実際は33.85である.
# 2つの引数についてのリストを作成
## 第1引数はモデル
models <- list(m1, m2, m3, m4, m5, m6, m7)
## 第2引数はモデルの内容
model_desctiption <- 
  list("完全独立", 
       "条件付き独立", 
       "すべての2元交互作用",
       "RC(1)+RL(1) 部分連関",
       "一貫した行(職業)スコアのあるRC(1)+RL(1) 部分連関",
       "RC(1)+RL(1)+CL(1) 部分連関",
       "一貫した行(職業)スコアのあるRC(1)+RL(1)+CL(1)部分連関")
# 結果をまとめる
map2_dfr(models, model_desctiption, model.summary, .id = "Model") |> 
  knitr::kable()
Model Model Description df L2 BIC Delta p
1 完全独立 174 586906.225 584536.899 33.848968 0
2 条件付き独立 108 27957.399 26486.783 6.003195 0
3 すべての2元交互作用 99 6540.396 5192.331 2.635334 0
4 RC(1)+RL(1) 部分連関 148 70860.986 68845.698 11.169390 0
5 一貫した行(職業)スコアのあるRC(1)+RL(1) 部分連関 158 185515.252 183363.795 18.266858 0
6 RC(1)+RL(1)+CL(1) 部分連関 143 42101.443 40154.238 8.274821 0
7 一貫した行(職業)スコアのあるRC(1)+RL(1)+CL(1)部分連関 153 174073.129 171989.756 17.803352 0