Skip to content

Commit f7578ae

Browse files
author
ripley
committed
add more examples
git-svn-id: https://svn.r-project.org/R/trunk@87482 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 3869bdc commit f7578ae

File tree

2 files changed

+129
-2
lines changed

2 files changed

+129
-2
lines changed

src/library/stats/tests/loglin.R

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,34 @@ loglin(x, list(1))
1010
## failed in R 4.4.2 as R code assumed >= 2 parameters
1111
loglin(x, NULL, param = TRUE)
1212
loglin(x, list(1), param = TRUE)
13+
14+
15+
## Versions of some MASS::loglm examples
16+
# loglm(~ Type + Origin, xtabs(~ Type + Origin, Cars93))
17+
if(require("MASS", quietly = TRUE))
18+
loglin(xtabs(~ Type + Origin, Cars93), list(Type=1, Origin=2))
19+
20+
# fm <- loglm(~ 1 + 2 + 3 + 4, minn38a)
21+
mn <- structure(c(53L, 163L, 309L, 13L, 28L, 38L, 7L, 30L, 17L, 76L,
22+
118L, 89L, 36L, 116L, 225L, 11L, 53L, 68L, 16L, 41L,
23+
49L, 111L, 214L, 210L, 52L, 162L, 243L, 49L, 129L,
24+
284L, 28L, 64L, 79L, 521L, 708L, 448L, 48L, 130L,
25+
237L, 29L, 62L, 63L, 18L, 47L, 57L, 191L, 305L, 219L,
26+
12L, 35L, 72L, 10L, 37L, 21L, 5L, 11L, 20L, 101L,
27+
152L, 95L, 9L, 19L, 42L, 15L, 22L, 19L, 1L, 13L, 10L,
28+
130L, 174L, 105L, 3L, 25L, 36L, 6L, 15L, 19L, 1L, 9L,
29+
14L, 88L, 158L, 93L, 87L, 216L, 256L, 17L, 14L, 10L,
30+
3L, 4L, 2L, 105L, 118L, 53L, 72L, 159L, 176L, 18L,
31+
28L, 22L, 6L, 14L, 8L, 209L, 227L, 95L, 52L, 119L,
32+
119L, 14L, 44L, 33L, 17L, 13L, 10L, 541L, 578L, 257L,
33+
88L, 158L, 144L, 14L, 36L, 20L, 9L, 15L, 12L, 328L,
34+
304L, 115L, 32L, 43L, 42L, 12L, 7L, 7L, 1L, 5L, 2L,
35+
124L, 119L, 56L, 14L, 24L, 24L, 5L, 15L, 4L, 2L, 6L,
36+
2L, 148L, 131L, 61L, 20L, 41L, 32L, 4L, 13L, 4L, 3L,
37+
5L, 2L, 109L, 88L, 41L),
38+
dim = c(3L, 4L, 7L, 2L),
39+
dimnames = list(hs = c("L", "M", "U"),
40+
phs = c("C", "E", "N", "O"),
41+
fol = c("F1", "F2", "F3", "F4", "F5", "F6", "F7"),
42+
sex = c("F", "M")))
43+
loglin(mn, list(hs = 1, phs = 2, fol = 3, sex = 4), param = TRUE)

src/library/stats/tests/loglin.Rout.save

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

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

@@ -110,7 +110,103 @@ $param$Class
110110
-0.4115541 -0.5428901 0.3642359 0.5902083
111111

112112

113+
>
114+
>
115+
> ## Versions of some MASS::loglm examples
116+
> # loglm(~ Type + Origin, xtabs(~ Type + Origin, Cars93))
117+
> if(require("MASS", quietly = TRUE))
118+
+ loglin(xtabs(~ Type + Origin, Cars93), list(Type=1, Origin=2))
119+
2 iterations: deviation 0
120+
$lrt
121+
[1] 18.36179
122+
123+
$pearson
124+
[1] 14.07985
125+
126+
$df
127+
[1] 5
128+
129+
$margin
130+
$margin$Type
131+
[1] "Type"
132+
133+
$margin$Origin
134+
[1] "Origin"
135+
136+
137+
>
138+
> # fm <- loglm(~ 1 + 2 + 3 + 4, minn38a)
139+
> mn <- structure(c(53L, 163L, 309L, 13L, 28L, 38L, 7L, 30L, 17L, 76L,
140+
+ 118L, 89L, 36L, 116L, 225L, 11L, 53L, 68L, 16L, 41L,
141+
+ 49L, 111L, 214L, 210L, 52L, 162L, 243L, 49L, 129L,
142+
+ 284L, 28L, 64L, 79L, 521L, 708L, 448L, 48L, 130L,
143+
+ 237L, 29L, 62L, 63L, 18L, 47L, 57L, 191L, 305L, 219L,
144+
+ 12L, 35L, 72L, 10L, 37L, 21L, 5L, 11L, 20L, 101L,
145+
+ 152L, 95L, 9L, 19L, 42L, 15L, 22L, 19L, 1L, 13L, 10L,
146+
+ 130L, 174L, 105L, 3L, 25L, 36L, 6L, 15L, 19L, 1L, 9L,
147+
+ 14L, 88L, 158L, 93L, 87L, 216L, 256L, 17L, 14L, 10L,
148+
+ 3L, 4L, 2L, 105L, 118L, 53L, 72L, 159L, 176L, 18L,
149+
+ 28L, 22L, 6L, 14L, 8L, 209L, 227L, 95L, 52L, 119L,
150+
+ 119L, 14L, 44L, 33L, 17L, 13L, 10L, 541L, 578L, 257L,
151+
+ 88L, 158L, 144L, 14L, 36L, 20L, 9L, 15L, 12L, 328L,
152+
+ 304L, 115L, 32L, 43L, 42L, 12L, 7L, 7L, 1L, 5L, 2L,
153+
+ 124L, 119L, 56L, 14L, 24L, 24L, 5L, 15L, 4L, 2L, 6L,
154+
+ 2L, 148L, 131L, 61L, 20L, 41L, 32L, 4L, 13L, 4L, 3L,
155+
+ 5L, 2L, 109L, 88L, 41L),
156+
+ dim = c(3L, 4L, 7L, 2L),
157+
+ dimnames = list(hs = c("L", "M", "U"),
158+
+ phs = c("C", "E", "N", "O"),
159+
+ fol = c("F1", "F2", "F3", "F4", "F5", "F6", "F7"),
160+
+ sex = c("F", "M")))
161+
> loglin(mn, list(hs = 1, phs = 2, fol = 3, sex = 4), param = TRUE)
162+
2 iterations: deviation 1.818989e-12
163+
$lrt
164+
[1] 3711.914
165+
166+
$pearson
167+
[1] 4161.597
168+
169+
$df
170+
[1] 155
171+
172+
$margin
173+
$margin$hs
174+
[1] "hs"
175+
176+
$margin$phs
177+
[1] "phs"
178+
179+
$margin$fol
180+
[1] "fol"
181+
182+
$margin$sex
183+
[1] "sex"
184+
185+
186+
$param
187+
$param$`(Intercept)`
188+
[1] 3.821018
189+
190+
$param$hs
191+
L M U
192+
-0.22433867 0.18885681 0.03548186
193+
194+
$param$phs
195+
C E N O
196+
0.5314514 -0.5543160 -1.2296056 1.2524702
197+
198+
$param$fol
199+
F1 F2 F3 F4 F5 F6
200+
0.07299887 0.25202915 0.98907052 0.44505330 -0.50834637 -0.53414145
201+
F7
202+
-0.71666403
203+
204+
$param$sex
205+
F M
206+
0.1181181 -0.1181181
207+
208+
113209
>
114210
> proc.time()
115211
user system elapsed
116-
0.068 0.012 0.078
212+
0.074 0.014 0.085

0 commit comments

Comments
 (0)