fitted
has to be an object which supports the method
coef
and which has fitted$terms
with the same
meaning as, for example, in lm
and
glm
(see also terms
). coef(fitted)
has to be a vector of coefficients with each component
corresponding to a column of the model matrix returned by
mf <- model.frame(fitted$terms,data=eval(fitted$call$data)) ;
model.matrix(fitted$terms,mf,contrasts = fitted$contrasts)
(or just model.matrix(fitted)
, for fitted
objects that
support the model.matrix
method.)
Exception to this are objects returned by BTm
of the
BradleyTerry package, where some special handling of the required
objects takes place.
Note that any or both of data
and contrasts
could be
NULL
. This depends whether the data
argument has been
supplied to the procedure and whether fitted$contrast
exists.
The fitting procedure that resulted fitted
has to support
offset
in formula
.
Also, fitted$call
has to be the call that generated fitted
.
If the fitting procedure that resulted fitted
supports an
etastart
argument (see glm
) and
fitted$linear.predictor
contains the estimated linear
predictors then during profiling, the appropriate starting values
are supplied to the fitting procedure. In this way, the iteration is
accelerated and is more stable, numerically. However, it is not necessary
that etastart
is supported. In the latter case no starting
values are supplied to the fitting procedure during profiling.
Support for a summary
method is
optional. summary
is only used for obtaining the
estimated asymptotic standard errors associated to the coefficients in
fitted
. If stdErrors=NULL
the standard errors are taken
to be summary(fitted)$coefficients[,2]
which is the place where
the estimated asymptotic standard errors usually are for
glm
-like objects. If this this is not the case then
stdErrors
should be set appropriately.
profiling
is the workhorse function that does the basic operation of
profiling objectives over a user-specified grid of values. For a given
parameter \(\beta\), the restricted fit
\(F_{\beta=b}\) is calculated by constraining
\(\beta\) to a point \(b\) of the grid. Then the difference
$$D(F_{\beta=b}) = P(F_{\beta=b}) - P(F_0),$$
is calculated, where \(P\) is the objective specified by the user
and \(G\) is the original fit (fitted
). For convex
objectives that are minimized at the estimates of \(G\) (see
agreement
), \(D(G)=0\).
prelim.profiling
refers only to convex objectives and searches for
and returns the grid bounds (grid.bounds
) for each
profiled parameter that should be used in order the profile to cover
quantile
. For a given parameter \(\beta\),
prelim.profiling
also checks whether such enclosure can be
found and returns a logical matrix intersects
of dimension
length(which)
by 2
that indicates if the profile covers the
quantile to the left and to the right of the estimate in
fitted
. At step i
of the search a value \(b_i\) is
proposed for \(\beta\) and \(D(F_{\beta=b_i})\) is calculated. If
\(D(F_{\beta=b_i})<q\), where \(q\) is quantile
, the next
proposed value is
$$b_{i+1} = b_{i} \pm (i+1) C \min(s,30)/|L| ,$$
where \(C\) is stepsize
, \(s\) is the
estimated asymptotic standard error of \(\beta\) from \(G\) and
\(L\) is the slope of the line segment connecting the points
\((b_i, D(F_{\beta=b_i}))\) and
\((b_{i-1}, D(F_{\beta=b_{i-1}}))\). \(\pm\) is \(+\) if the search is on the
right of the estimate of \(\beta\) and \(-\) on the left. If an
increase of \(D\) is expected then the step slows down. If
\(|L|<1\) then \(|L|\) is set to 1 and if
\(|L|>500\) then \(|L|\) is set to 500. In
this way the iteration is conservative by avoiding very small steps
but not over-conservative by avoiding very large steps.
If the maximum number of steps stdn/stepsize
(call this \(M\))
was taken and the quantile was not covered by the profile but the three
last absolute slopes where positive then the iteration is restarted
form \(b_{M-1}\) with \(2C\) instead of \(C\) in the step
calculation. If the three last slopes were less than 1e-8
in
absolute value then the iteration stops and it is considered that
\(D\) has an asymptote at the corresponding direction (left or right).
Note that when the latter takes place the iteration has already moved
\(6 C\min(s,30)\) units on the scale of \(\beta\),
since the first value of \(b\) were a slope of 1e-8 in absolute value
was detected. Thus we could safely say that an asymptote has been
detected and avoid calculation of \(F_{beta=b}\) for
extremely large \(b\)'s.
Very small values of stepsize
make prelim.profiling
take
very small steps with the effect of slowing down the execution
time. Large values of stepsize
are only recommended when the
estimated asymptotic standard errors are very small in fitted
.
profileModel
is a wrapper function that collects and combines
the capabilities of profiling
and prelim.profiling
by
providing a unified interface for their functions, as well as appropriateness
checks on the arguments. When both quantile
and
grid.bounds
are NULL
then profiling
is called and
profiling takes place for stdn
estimated asymptotic standard
errors on the left and on the right of the estimates in
fitted
. This could be used for taking a quick look of the
profiles around the estimate. With only the quantile
being
NULL
, profiling is performed on the the specified grid of
values. When quantile
is specified and grid.bounds
is
NULL
, prelim.profiling
is called and its result is
passed to profiling
. If both quantile
and
grid.bounds
then grid.bounds
prevails and profiling is
performed on the specified grid.