Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision b58cc9cd586b6c8ac55b26c2da679f538ec801cc authored by Mark Clements on 17 October 2022, 13:50:02 UTC, committed by cran-robot on 17 October 2022, 13:50:02 UTC
version 1.5.8
1 parent dbf475c
  • Files
  • Changes
  • c88d9f4
  • /
  • man
  • /
  • predictnl.Rd
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:b58cc9cd586b6c8ac55b26c2da679f538ec801cc
directory badge
swh:1:dir:a1370f024583becfcae914c1082f8f8665bb7881
content badge
swh:1:cnt:d1e245c7e97bafd435352ab35c730095452a865f

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
predictnl.Rd
\name{predictnl}
\alias{predictnl}
\alias{predictnl.default}
\alias{predictnl.lm}
\alias{predict.formula}
\alias{print.predictnl}
\alias{confint.predictnl}
%- Also NEED an '\alias' for EACH other topic documented here.
\title{
Estimation of standard errors using the numerical delta method.
}
\description{
A simple, yet exceedingly useful, approach to estimate the variance of a
function using the numerical delta method. A number of packages provide
functions that analytically calculate the gradients; we use numerical
derivatives, which generalises to models that do not offer analytical
derivatives (e.g. ordinary differential equations, integration), or to
examples that are tedious or error-prone to calculate (e.g. sums of
predictions from GLMs).
}
\usage{
\method{predictnl}{default}(object, fun, newdata=NULL, gd=NULL, ...)
\method{predictnl}{lm}(object, fun, newdata=NULL, ...)
\method{print}{predictnl}(x, ...)
\method{predict}{formula}(object,data,newdata,na.action,type="model.matrix",...)
\method{confint}{predictnl}(object, parm, level=0.95, ...)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
  \item{object}{
An object with \code{coef}, \code{vcov} and \code{`coef<-`}
methods (required). 
}
  \item{fun}{
A function that takes \code{object} as the first argument, possibly with
\code{newdata} and other arguments (required). See notes for why it is
often useful to include \code{newdata} as an argument to the function.
}
  \item{newdata}{
An optional argument that defines newdata to be passed to \code{fun}.
}
  \item{gd}{
An optional matrix of gradients. If this is not specified, then the
gradients are calculated using finite differences.
}
  \item{parm}{
    currently ignored
}
  \item{level}{
    significance level for 2-sided confidence intervals
}
  \item{x}{
    a \code{predictnl} object to be printed.
}
  \item{data}{
    object used to define the model frame
}
  \item{na.action}{
    passed to \code{model.frame}
}
  \item{type}{
    currently restricted to \code{"model.matrix"}
}
  \item{\dots}{
    Other arguments that are passed to \code{fun}.
}
}
\details{
The signature for \code{fun}
is either \code{fun(object, ...)} or \code{fun(object, newdata=NULL,
  ...)}.

The different \code{predictnl} methods call the utility function
\code{numDeltaMethod}, which in turn calls the \code{grad} function for
numerical differentiation. The \code{numDeltaMethod} function calls the
standard \code{coef} and \code{vcov} methods, and the non-standard
\code{`coef<-`} method for changing the coefficients in a regression
object. This non-standard method has been provided for several
regression objects and essentially mirrors the \code{coef} method.

One potential issue is that some \code{predict} methods do not
re-calculate their predictions for the fitted dataset (i.e. when
\code{newdata=NULL}). As the \code{predictnl} function changes the
fitted coefficients, it is required that the predictions are
re-calculated. One solution is to pass \code{newdata} as an argument to
both \code{predictnl} and \code{fun}; alternatively, \code{newdata} can
be specified in \code{fun}. These approaches are described in the examples
below. The \code{numDeltaMethod} method called by \code{predictnl}
provides a warning when the variance estimates are zero, which may be
due to this cause.

For completeness, it is worth discussing why the example
\code{predictnl(fit,predict)} does not work for when \code{fit} is a
\code{glm} object. First, \code{predict.glm} does not update the
predictions for the fitted data. Second, the default \code{predict}
method has a signature \code{predict(object, ...)}, which does not
include a \code{newdata} argument. We could then either (i) require that
a \code{newdata} argument be passed to the \code{fun} function for all
examples, which would make this corner case work, or (ii) only pass the
\code{newdata} argument if it is non-null or in the formals for the
\code{fun} function, which would fail for this corner case. The current
API defaults to the latter case (ii).  To support this approach, the
\code{predictnl.lm} method replaces a null \code{newdata} with
\code{object$data}. We also provide a revised
\code{numdelta:::predict.lm} method that performs the same operation,
although its use is not encouraged due to its clumsiness.
}
\value{ Returns an object of class
an object with class \code{c("predictnl","data.frame")} elements
\code{c("fit","se.fit","Estimate","SE")} and with methods \code{print}
and \code{confint}. Note that the Estimate and SE fields are deprecated
and their use is discouraged, as we would like to remove them from future releases.
}
%% \references{
%% %% ~put references to the literature/web site here ~
%% }
\author{
Mark Clements
}
%% \note{
%% %%  ~~further notes~~
%% }

%% %% ~Make other sections like Warning with \section{Warning }{....} ~

%% \seealso{
%% %% ~~objects to See Also as \code{\link{help}}, ~~~
%% }
\examples{

df <- data.frame(x=0:1, y=c(10, 20))
fit <- glm(y ~ x, df, family=poisson)

predictnl(fit,
          function(obj,newdata)
          diff(predict(obj,newdata,type="response")))

}
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
%% \keyword{ ~kwd1 }
%% \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API