Skip to content

Commit 3869bdc

Browse files
author
ripley
committed
fix oglin(, param = TRUE) in some corner cases
git-svn-id: https://svn.r-project.org/R/trunk@87480 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 9fe56f2 commit 3869bdc

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

doc/NEWS.Rd

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,13 @@
490490
\item Silent integer overflow could occur in the
491491
\sQuote{exact} computations for \code{fisher.test()} for
492492
unrealistic inputs: this is now an error.
493-
}
493+
494+
\item Some inalid C-level memory accesses are avoided for
495+
\code{loglin(, margin = NULL)}.
496+
497+
\code{loglin(, param = TRUE)} no longer gives an eror in corner
498+
cases such as a one-dimensional input.
499+
}
494500
}
495501
}
496502

src/library/stats/R/loglin.R

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,21 @@ loglin <- function(table, margin, start = rep(1, length(table)), fit =
113113
parnam[1L] <- "(Intercept)"
114114
fit <- fit - parval[[1L]]
115115

116-
## Get the u_i(B) in the rows of 'dyadic', see above.
117-
dyadic <- NULL
118-
while(any(terms > 0)) {
119-
dyadic <- cbind(dyadic, terms %% 2)
120-
terms <- terms %/% 2
121-
}
122-
dyadic <- dyadic[order(rowSums(dyadic)), , drop = FALSE]
123-
124-
for (i in 2 : parlen) {
125-
vars <- which(dyadic[i - 1, ] > 0)
126-
parval[[i]] <- apply(fit, vars, mean)
127-
parnam[i] <- paste(varnames[vars], collapse = ".")
128-
fit <- sweep(fit, vars, parval[[i]], check.margin=FALSE)
116+
if(parlen > 1) {
117+
## Get the u_i(B) in the rows of 'dyadic', see above.
118+
dyadic <- NULL
119+
while(any(terms > 0)) {
120+
dyadic <- cbind(dyadic, terms %% 2)
121+
terms <- terms %/% 2
122+
}
123+
dyadic <- dyadic[order(rowSums(dyadic)), , drop = FALSE]
124+
125+
for (i in 2 : parlen) {
126+
vars <- which(dyadic[i - 1, ] > 0)
127+
parval[[i]] <- apply(fit, vars, mean)
128+
parnam[i] <- paste(varnames[vars], collapse = ".")
129+
fit <- sweep(fit, vars, parval[[i]], check.margin=FALSE)
130+
}
129131
}
130132

131133
names(parval) <- parnam

0 commit comments

Comments
 (0)