Skip to content

Commit 906ef7a

Browse files
author
pd
committed
confint.default and AIC/BIC for S4 objects
git-svn-id: https://svn.r-project.org/R/trunk@88801 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent c2f2586 commit 906ef7a

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

doc/NEWS.Rd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616

1717
\subsection{NEW FEATURES}{
1818
\itemize{
19+
\item \code{AIC.default} and \code{BIC.default} now checks whether
20+
the \code{methods} namespace is loaded rather than \code{stats4}. It
21+
still uses \code{stats4::logLik} and \code{stats4::nobs}, but packages
22+
no longer need to load \code{stats4} explicitly.
23+
24+
\item \code{confint.default} now also works on S4 objects, as long as they
25+
have \code{coef()} and \code{vcov()} generics.
26+
1927
\item \code{binomial(identity)} and \code{quasibinomial(identity)} now work
2028
without having to quote the argument.
2129

src/library/stats/R/AIC.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ AIC.logLik <- function(object, ..., k = 2)
2929
AIC.default <- function(object, ..., k = 2)
3030
{
3131
## AIC for various fitted objects --- any for which there's a logLik() method:
32-
ll <- if(isNamespaceLoaded("stats4")) stats4::logLik else logLik
32+
ll <- if(isNamespaceLoaded("methods")) stats4::logLik else logLik
3333
if(!missing(...)) {# several objects: produce data.frame
3434
lls <- lapply(list(object, ...), ll)
3535
vals <- vapply(lls,
@@ -62,8 +62,8 @@ BIC.logLik <- function(object, ...)
6262

6363
BIC.default <- function(object, ...)
6464
{
65-
ll <- if(isNamespaceLoaded("stats4")) stats4::logLik else logLik
66-
Nobs <- if(isNamespaceLoaded("stats4")) stats4::nobs else nobs
65+
ll <- if(isNamespaceLoaded("methods")) stats4::logLik else logLik
66+
Nobs <- if(isNamespaceLoaded("methods")) stats4::nobs else nobs
6767
if(!missing(...)) {# several objects: produce data.frame
6868
lls <- lapply(list(object, ...), ll)
6969
vals <- vapply(lls,

src/library/stats/R/confint.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,23 @@ confint.profile.nls <-
156156

157157
confint.default <- function (object, parm, level = 0.95, ...)
158158
{
159+
if(isNamespaceLoaded("methods")) {
160+
coef <- stats4::coef
161+
vcov <- stats4::vcov
162+
}
159163
cf <- coef(object)
160164
pnames <- names(cf)
161165
if(missing(parm)) parm <- pnames
162166
else if(is.numeric(parm)) parm <- pnames[parm]
167+
parm_num <- match(parm, pnames) # in case names are missing from vcov
163168
a <- (1 - level)/2
164169
a <- c(a, 1 - a)
165170
pct <- .format_perc(a, 3)
166171
fac <- qnorm(a)
167172
ci <- array(NA, dim = c(length(parm), 2L),
168173
dimnames = list(parm, pct))
169-
ses <- sqrt(diag(vcov(object)))[parm]
174+
ses <- sqrt(diag(vcov(object)))[parm_num]
170175
ci[] <- cf[parm] + ses %o% fac
171176
ci
172177
}
178+

src/library/stats/man/confint.Rd

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
\description{
1616
Computes confidence intervals for one or more parameters in a fitted
1717
model. There is a default and a method for objects inheriting from class
18-
\code{"\link{lm}"}.
18+
\code{"\link{lm}"} and several other classes.
1919
}
2020
\usage{
2121
confint(object, parm, level = 0.95, \dots)
@@ -40,10 +40,13 @@ confint(object, parm, level = 0.95, \dots)
4040
1 - (1-level)/2 in \% (by default 2.5\% and 97.5\%).
4141
}
4242
\details{
43-
\code{confint} is a generic function. The default method assumes
44-
normality, and needs suitable \code{\link{coef}} and
43+
\code{confint} is a generic function. The default method is based on
44+
inverting the Wald test, assuming approximate
45+
normality of the estimator. It needs suitable \code{\link{coef}} and
4546
\code{\link{vcov}} methods to be available. The default method can be
46-
called directly for comparison with other methods.
47+
called directly for comparison with other methods. It also works for
48+
fitted models in the S4 class system, provided that the \pkg{methods}
49+
namespace is loaded.
4750

4851
For objects of class \code{"lm"} the direct formulae based on \eqn{t}
4952
values are used.

0 commit comments

Comments
 (0)