Skip to content

Commit

Permalink
add more examples
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@87482 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
ripley committed Dec 29, 2024
1 parent 3869bdc commit f7578ae
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 2 deletions.
31 changes: 31 additions & 0 deletions src/library/stats/tests/loglin.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,34 @@ loglin(x, list(1))
## failed in R 4.4.2 as R code assumed >= 2 parameters
loglin(x, NULL, param = TRUE)
loglin(x, list(1), param = TRUE)


## Versions of some MASS::loglm examples
# loglm(~ Type + Origin, xtabs(~ Type + Origin, Cars93))
if(require("MASS", quietly = TRUE))
loglin(xtabs(~ Type + Origin, Cars93), list(Type=1, Origin=2))

# fm <- loglm(~ 1 + 2 + 3 + 4, minn38a)
mn <- structure(c(53L, 163L, 309L, 13L, 28L, 38L, 7L, 30L, 17L, 76L,
118L, 89L, 36L, 116L, 225L, 11L, 53L, 68L, 16L, 41L,
49L, 111L, 214L, 210L, 52L, 162L, 243L, 49L, 129L,
284L, 28L, 64L, 79L, 521L, 708L, 448L, 48L, 130L,
237L, 29L, 62L, 63L, 18L, 47L, 57L, 191L, 305L, 219L,
12L, 35L, 72L, 10L, 37L, 21L, 5L, 11L, 20L, 101L,
152L, 95L, 9L, 19L, 42L, 15L, 22L, 19L, 1L, 13L, 10L,
130L, 174L, 105L, 3L, 25L, 36L, 6L, 15L, 19L, 1L, 9L,
14L, 88L, 158L, 93L, 87L, 216L, 256L, 17L, 14L, 10L,
3L, 4L, 2L, 105L, 118L, 53L, 72L, 159L, 176L, 18L,
28L, 22L, 6L, 14L, 8L, 209L, 227L, 95L, 52L, 119L,
119L, 14L, 44L, 33L, 17L, 13L, 10L, 541L, 578L, 257L,
88L, 158L, 144L, 14L, 36L, 20L, 9L, 15L, 12L, 328L,
304L, 115L, 32L, 43L, 42L, 12L, 7L, 7L, 1L, 5L, 2L,
124L, 119L, 56L, 14L, 24L, 24L, 5L, 15L, 4L, 2L, 6L,
2L, 148L, 131L, 61L, 20L, 41L, 32L, 4L, 13L, 4L, 3L,
5L, 2L, 109L, 88L, 41L),
dim = c(3L, 4L, 7L, 2L),
dimnames = list(hs = c("L", "M", "U"),
phs = c("C", "E", "N", "O"),
fol = c("F1", "F2", "F3", "F4", "F5", "F6", "F7"),
sex = c("F", "M")))
loglin(mn, list(hs = 1, phs = 2, fol = 3, sex = 4), param = TRUE)
100 changes: 98 additions & 2 deletions src/library/stats/tests/loglin.Rout.save
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

R Under development (unstable) (2024-12-28 r87474) -- "Unsuffered Consequences"
R Under development (unstable) (2024-12-29 r87480) -- "Unsuffered Consequences"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin24.2.0

Expand Down Expand Up @@ -110,7 +110,103 @@ $param$Class
-0.4115541 -0.5428901 0.3642359 0.5902083


>
>
> ## Versions of some MASS::loglm examples
> # loglm(~ Type + Origin, xtabs(~ Type + Origin, Cars93))
> if(require("MASS", quietly = TRUE))
+ loglin(xtabs(~ Type + Origin, Cars93), list(Type=1, Origin=2))
2 iterations: deviation 0
$lrt
[1] 18.36179

$pearson
[1] 14.07985

$df
[1] 5

$margin
$margin$Type
[1] "Type"

$margin$Origin
[1] "Origin"


>
> # fm <- loglm(~ 1 + 2 + 3 + 4, minn38a)
> mn <- structure(c(53L, 163L, 309L, 13L, 28L, 38L, 7L, 30L, 17L, 76L,
+ 118L, 89L, 36L, 116L, 225L, 11L, 53L, 68L, 16L, 41L,
+ 49L, 111L, 214L, 210L, 52L, 162L, 243L, 49L, 129L,
+ 284L, 28L, 64L, 79L, 521L, 708L, 448L, 48L, 130L,
+ 237L, 29L, 62L, 63L, 18L, 47L, 57L, 191L, 305L, 219L,
+ 12L, 35L, 72L, 10L, 37L, 21L, 5L, 11L, 20L, 101L,
+ 152L, 95L, 9L, 19L, 42L, 15L, 22L, 19L, 1L, 13L, 10L,
+ 130L, 174L, 105L, 3L, 25L, 36L, 6L, 15L, 19L, 1L, 9L,
+ 14L, 88L, 158L, 93L, 87L, 216L, 256L, 17L, 14L, 10L,
+ 3L, 4L, 2L, 105L, 118L, 53L, 72L, 159L, 176L, 18L,
+ 28L, 22L, 6L, 14L, 8L, 209L, 227L, 95L, 52L, 119L,
+ 119L, 14L, 44L, 33L, 17L, 13L, 10L, 541L, 578L, 257L,
+ 88L, 158L, 144L, 14L, 36L, 20L, 9L, 15L, 12L, 328L,
+ 304L, 115L, 32L, 43L, 42L, 12L, 7L, 7L, 1L, 5L, 2L,
+ 124L, 119L, 56L, 14L, 24L, 24L, 5L, 15L, 4L, 2L, 6L,
+ 2L, 148L, 131L, 61L, 20L, 41L, 32L, 4L, 13L, 4L, 3L,
+ 5L, 2L, 109L, 88L, 41L),
+ dim = c(3L, 4L, 7L, 2L),
+ dimnames = list(hs = c("L", "M", "U"),
+ phs = c("C", "E", "N", "O"),
+ fol = c("F1", "F2", "F3", "F4", "F5", "F6", "F7"),
+ sex = c("F", "M")))
> loglin(mn, list(hs = 1, phs = 2, fol = 3, sex = 4), param = TRUE)
2 iterations: deviation 1.818989e-12
$lrt
[1] 3711.914

$pearson
[1] 4161.597

$df
[1] 155

$margin
$margin$hs
[1] "hs"

$margin$phs
[1] "phs"

$margin$fol
[1] "fol"

$margin$sex
[1] "sex"


$param
$param$`(Intercept)`
[1] 3.821018

$param$hs
L M U
-0.22433867 0.18885681 0.03548186

$param$phs
C E N O
0.5314514 -0.5543160 -1.2296056 1.2524702

$param$fol
F1 F2 F3 F4 F5 F6
0.07299887 0.25202915 0.98907052 0.44505330 -0.50834637 -0.53414145
F7
-0.71666403

$param$sex
F M
0.1181181 -0.1181181


>
> proc.time()
user system elapsed
0.068 0.012 0.078
0.074 0.014 0.085

0 comments on commit f7578ae

Please sign in to comment.