Statistical Functions using S4 Classes

Statistical Functions using S4 Classes [R logo]

Help pages for package `stats4' version 2.4.1

stats4-package | Statistical Functions using S4 Classes
AIC,ANY-method | Methods for Function `AIC' in Package `stats4'
AIC-methods | Methods for Function `AIC' in Package `stats4'
BIC | Bayesian Information Criterion
BIC,ANY-method | Bayesian Information Criterion
BIC,logLik-method | Bayesian Information Criterion
coef,ANY-method | Methods for Function `coef' in Package `stats4'
coef,mle-method | Methods for Function `coef' in Package `stats4'
coef,summary.mle-method | Methods for Function `coef' in Package `stats4'
coef-methods | Methods for Function `coef' in Package `stats4'
confint,ANY-method | Methods for Function `confint' in Package `stats4'
confint,mle-method | Methods for Function `confint' in Package `stats4'
confint,profile.mle-method | Methods for Function `confint' in Package `stats4'
confint-methods | Methods for Function `confint' in Package `stats4'
logLik,ANY-method | Methods for Function `logLik' in Package `stats4'
logLik,mle-method | Methods for Function `logLik' in Package `stats4'
logLik-methods | Methods for Function `logLik' in Package `stats4'
mle | Maximum Likelihood Estimation
mle-class | Class "mle" for Results of Maximum Likelihood Estimation
plot,ANY,ANY-method | Methods for Function `plot' in Package `stats4'
plot,profile.mle,missing-method | Methods for Function `plot' in Package `stats4'
plot-methods | Methods for Function `plot' in Package `stats4'
profile,ANY-method | Methods for Function profile in Package `stats4'
profile,mle-method | Methods for Function profile in Package `stats4'
profile-methods | Methods for Function profile in Package `stats4'
profile.mle-class | Class "profile.mle"; Profiling information for "mle" object
show,mle-method | Methods for Function show in Package `stats4'
show,summary.mle-method | Methods for Function show in Package `stats4'
show-methods | Methods for Function show in Package `stats4'
stats4 | Statistical Functions using S4 Classes
summary,ANY-method | Methods for Function summary in Package `stats4'
summary,mle-method | Methods for Function summary in Package `stats4'
summary-methods | Methods for Function summary in Package `stats4'
summary.mle-class | Class "summary.mle", summary of "mle" objects
update,ANY-method | Methods for Function `update' in Package `stats4'
update,mle-method | Methods for Function `update' in Package `stats4'
update-methods | Methods for Function `update' in Package `stats4'
vcov,ANY-method | Methods for Function `vcov' in Package `stats4'
vcov,mle-method | Methods for Function `vcov' in Package `stats4'
vcov-methods | Methods for Function `vcov' in Package `stats4'


Methods for Function 'AIC' in Package 'stats4'

Description

Calculate the Akaike information criterion for a fitted model object.

Methods

object = "ANY"
Generic function: see AIC.
[Package stats4 version 2.4.1 Index]


Bayesian Information Criterion

Description

This generic function calculates the Bayesian information criterion, also known as Schwarz's Bayesian criterion (SBC), for one or several fitted model objects for which a log-likelihood value can be obtained, according to the formula -2*log-likelihood + npar*log(nobs), where npar represents the number of parameters and nobs the number of observations in the fitted model.

Usage

BIC(object, ...)

Arguments

object | An object of a suitable class for the BIC to be calculated - usually a "logLik" object or an object for which a logLik method exists.
... | Some methods for this generic function may take additional, optional arguments. At present none do.

Value

Returns a numeric value with the corresponding BIC.

References

Schwarz, G. (1978) "Estimating the Dimension of a Model", Annals of Statistics, 6, 461-464.

See Also

logLik-methods, AIC-methods

Examples

lm1 <- lm(Fertility ~ . , data = swiss)
AIC(lm1)
BIC(lm1)


Methods for Function 'coef' in Package 'stats4'

Description

Extract the coefficient vector from "mle" objects.

Methods

object = "ANY"
Generic function: see coef.
object = "mle"
Extract the full coefficient vector (including any fixed coefficients) from the fit.
object = "summary.mle"
Extract the coefficient vector and standard errors from the summary of the fit.


Methods for Function 'confint' in Package 'stats4'

Description

Generate confidence intervals

Methods

object = "ANY"
Generic function: see confint.
object = "mle"
First generate profile and then confidence intervals from the profile.
object = "profile.mle"
Generate confidence intervals based on likelihood profile.


Methods for Function 'logLik' in Package 'stats4'

Description

Extract the maximized log-likelihood from "mle" objects.

Methods

object = "ANY"
Generic function: see logLik.
object = "mle"
Extract log-likelihood from the fit.


Maximum Likelihood Estimation

Description

Estimate parameters by the method of maximum likelihood.

Usage

mle(minuslogl, start = formals(minuslogl), method = "BFGS",
    fixed = list(), ...)

Arguments

minuslogl | Function to calculate negative log-likelihood.
start | Named list. Initial values for optimizer.
method | Optimization method to use. See optim.
fixed | Named list. Parameter values to keep fixed during optimization.
... | Further arguments to pass to optim.

Details

The optim optimizer is used to find the minimum of the negative log-likelihood. An approximate covariance matrix for the parameters is obtained by inverting the Hessian matrix at the optimum.

Value

An object of class mle-class.

Note

Be careful to note that the argument is -log L (not -2 log L). It is for the user to ensure that the likelihood is correct, and that asymptotic likelihood inference is valid.

See Also

mle-class

Examples

x <- 0:10
y <- c(26, 17, 13, 12, 20, 5, 9, 8, 5, 4, 8)
ll <- function(ymax=15, xhalf=6)
    -sum(stats::dpois(y, lambda=ymax/(1+x/xhalf), log=TRUE))
(fit <- mle(ll))
mle(ll, fixed=list(xhalf=6))

summary(fit)
logLik(fit)
vcov(fit)
plot(profile(fit), absVal=FALSE)
confint(fit)

## use bounded optimization
## the lower bounds are really > 0, but we use >=0 to stress-test profiling
(fit1 <- mle(ll, method="L-BFGS-B", lower=c(0, 0)))
plot(profile(fit1), absVal=FALSE)

## a better parametrization:
ll2 <- function(lymax=log(15), lxhalf=log(6))
    -sum(stats::dpois(y, lambda=exp(lymax)/(1+x/exp(lxhalf)), log=TRUE))
(fit2 <- mle(ll2))
plot(profile(fit2), absVal=FALSE)
exp(confint(fit2))


Class "mle" for Results of Maximum Likelihood Estimation

mle-class(stats4) R Documentation

Class 'mle' for Results of Maximum Likelihood Estimation

Description

This class encapsulates results of a generic maximum likelihood procedure.

Objects from the Class

Objects can be created by calls of the form new("mle", ...), but most often as the result of a call to mle.

Slots

call:
Object of class "language". The call to mle.
coef:
Object of class "numeric". Estimated parameters.
fullcoef:
Object of class "numeric". Fixed and estimated parameters.
vcov:
Object of class "matrix". Approximate variance-covariance matrix.
min:
Object of class "numeric". Minimum value of objective function.
details:
Object of class "list". List returned from optim.
minuslogl:
Object of class "function". The negative loglikelihood function.
method:
Object of class "character". The optimization method used.

Methods

confint
signature(object = "mle"): Confidence intervals from likelihood profiles.
logLik
signature(object = "mle"): Extract maximized log-likelihood.
profile
signature(fitted = "mle"): Likelihood profile generation.
show
signature(object = "mle"): Display object briefly.
summary
signature(object = "mle"): Generate object summary.
update
signature(object = "mle"): Update fit.
vcov
signature(object = "mle"): Extract variance-covariance matrix.


Methods for Function 'plot' in Package 'stats4'

Description

Plot profile likelihoods for "mle" objects.

Usage

## S4 method for signature 'profile.mle, missing':
plot(x, levels, conf = c(99, 95, 90, 80, 50)/100, nseg = 50,
     absVal = TRUE, ...)

Arguments

x | an object of class "profile.mle"
levels | levels, on the scale of the absolute value of a t statistic, at which to interpolate intervals. Usually conf is used instead of giving levels explicitly.
conf | a numeric vector of confidence levels for profile-based confidence intervals on the parameters.
nseg | an integer value giving the number of segments to use in the spline interpolation of the profile t curves.
absVal | a logical value indicating whether or not the plots should be on the scale of the absolute value of the profile t. Defaults to TRUE.
... | other arguments to the plot function can be passed here.

Methods

x = "ANY", y = "ANY"
Generic function: see plot.
x = "profile.mle", y = "missing"
Plot likelihood profiles for x.


Methods for Function profile in Package 'stats4'

Description

Profile likelihood

Methods

fitted = "ANY"
Generic function
fitted = "mle"
Profile the likelihood in the vicinity of the optimum


Class "profile.mle"; Profiling information for "mle" object

profile.mle-class(stats4) R Documentation

Class 'profile.mle'; Profiling information for 'mle' object

Description

Likelihood profiles along each parameter of likelihood function

Objects from the Class

Objects can be created by calls of the form new("profile.mle", ...), but most often by invoking profile on an "mle" object.

Slots

profile:
Object of class "list". List of profiles, one for each requested parameter. Each profile is a data frame with the first column called z being the signed square root of the -2 log likelihood ratio, and the others being the parameters with names prefixed by par.vals.
summary:
Object of class "summary.mle". Summary of object being profiled.

Methods

confint
signature(object = "profile.mle"): Use profile to generate approximate confidence intervals for parameters.
plot
signature(x = "profile.mle", y = "missing"): Plot profiles for each parameter.

See Also

mle, mle-class, summary.mle-class


Methods for Function show in Package 'stats4'

Description

Show objects of classes mle and summary.mle

Methods

object = "mle"
Print simple summary of mle object. Just the coefficients and the call.
object = "summary.mle"
Shows call, table of coefficients and standard errors, and -2 log L


Statistical Functions using S4 Classes

Description

Statistical Functions using S4 classes.

Details

This package contains functions and classes for statistics using the S version 4 class system.

The methods currently support maximum likelihood (function mle() returning class "mle"), including methods for AIC and BIC for model selection.

Author(s)

R Development Core Team and contributors worldwide

Maintainer: R Core Team <R-core@r-project.org>


Methods for Function summary in Package 'stats4'

Description

Summarize objects

Methods

object = "ANY"
Generic function
object = "mle"
Generate a summary as an object of class "summary.mle", containing estimates, asymptotic SE, and value of -2 log L


Class "summary.mle", summary of "mle" objects

summary.mle-class(stats4) R Documentation

Class 'summary.mle' summary of 'mle' objects

Description

Extract of "mle" object

Objects from the Class

Objects can be created by calls of the form new("summary.mle", ...), but most often by invoking summary on an "mle" object. They contain values meant for printing by show.

Slots

call:
Object of class "language" The call that generated the "mle" object.
coef:
Object of class "matrix". Estimated coefficients and standard errors
m2logL:
Object of class "numeric". Minus twice the log likelihood.

Methods

show
signature(object = "summary.mle"): Pretty-prints object
coef
signature(object = "summary.mle"): Extracts the contents of the coef slot

See Also

summary, mle, mle-class


Methods for Function 'update' in Package 'stats4'

Description

Update "mle" objects.

Usage

## S4 method for signature 'mle':
update(object, ..., evaluate = TRUE)

Arguments

object | An existing fit.
... | Additional arguments to the call, or arguments with changed values. Use name=NULL to remove the argument name.
evaluate | If true evaluate the new call else return the call.

Methods

object = "ANY"
Generic function: see update.
object = "mle"
Update a fit.

Examples

x <- 0:10
y <- c(26, 17, 13, 12, 20, 5, 9, 8, 5, 4, 8)
ll <- function(ymax=15, xhalf=6)
    -sum(stats::dpois(y, lambda=ymax/(1+x/xhalf), log=TRUE))
fit <- mle(ll)
## note the recorded call contains ..1, a problem with S4 dispatch
update(fit, fixed=list(xhalf=3))


Methods for Function 'vcov' in Package 'stats4'

Description

Extract the approximate variance-covariance matrix from "mle" objects.

Methods

object = "ANY"
Generic function: see vcov.
object = "mle"
Extract the estimated variance-covariance matrix for the estimated parameters (if any).