Use fp() or fp2() inside an mfp2() or mfpi() formula to set
fractional-polynomial (FP) options for one continuous predictor. In
mfp2(), continuous terms without fp() are also considered for FP
selection, using its top-level settings. fp() and fp2() specify the
same model term and record options for fitting; neither transforms the
values when the formula is created.
fp(
x,
df = 4,
alpha = 0.05,
select = 0.05,
shift = NULL,
scale = NULL,
center = TRUE,
acd = FALSE,
powers = NULL,
zero = FALSE,
catzero = FALSE,
spike = FALSE,
force_max_fp = FALSE,
acdx = NULL
)fp2(...)
The input vector with modelling options attached as attributes.
The options take effect when the term is used in an mfp2() or
mfpi() formula.
Continuous numeric predictor to include in the formula. Do not
wrap a factor in fp().
Maximum FP complexity: 1 for linear only, 2 for up to FP1,
or 4 (default) for up to FP2. Higher positive even values permit
higher FP degrees.
Significance level for comparisons between functional forms
under p-value selection. Default 0.05. For eligible spike-at-zero
terms, also controls tests that remove components.
Significance level for variable inclusion under p-value
selection. Default 0.05; use 1 to force inclusion. It does not
control inclusion under AIC or BIC selection.
Numeric value added before FP transformation. NULL (default)
inherits the setting from mfp2(); 0 disables shifting for this term.
Positive divisor applied after shifting. NULL (default)
inherits the setting from mfp2(); 1 disables scaling for this term.
With zero, catzero, or spike, the automatic scale is 1.
Whether to center the fitted terms. Default TRUE.
Whether to request approximate cumulative distribution (ACD)
modelling. Default FALSE.
Numeric vector of candidate FP powers for this predictor.
NULL (default) uses the global candidate set. Duplicate candidates
are removed.
If TRUE, transform only values with x > 0; exact zeros
contribute zero to the continuous component. Requires nonnegative x.
Default FALSE.
If TRUE, add a binary indicator for x = 0 alongside
the positive component. Implies zero = TRUE. Default FALSE.
If TRUE, request spike-at-zero (SAZ) model selection,
subject to eligibility checks. While eligible, it considers a positive
component and a binary indicator for x = 0. Requires nonnegative x.
Default FALSE.
If TRUE, retain the most complex form permitted by
df and bypass variable removal and functional-form simplification.
For an eligible SAZ term, retain both components. Default FALSE.
Deprecated alias for acd. Use acd; supplying both
arguments is an error.
Arguments passed by fp2() to fp().
fp2() was introduced to avoid a name conflict with mfp::fp().
That conflict is now resolved: formulas passed to mfp2() or mfpi()
use this package's fp() even when mfp is attached.
Add categorical predictors to the formula without fp() or fp2().
Convert numeric category codes with factor().
The default df = 4 permits selection of a linear effect, a first-degree
FP (FP1), or a second-degree FP (FP2). Selection may also exclude the
predictor. Use df = 2 to permit at most FP1, or df = 1 for a linear
effect only. The fitting procedure may reduce the permitted complexity
when a predictor has few distinct values.
Candidate powers default to c(-2, -1, -0.5, 0, 0.5, 1, 2, 3). A power
of zero represents a logarithm. powers changes the candidates searched;
it does not specify the powers of the final fitted function.
Options set inside fp() apply to this term. df, alpha, select,
and center have their own defaults in fp() and ignore the values
supplied to the surrounding mfp2() call; set them inside fp() to
change them. shift, scale, and powers default to NULL and use the
top-level values unless set here. Under p-value selection, select = 1
forces inclusion and alpha = 1 prevents simplification of the permitted
functional form.
fp2(), mfp2(), mfpi()
data("prostate")
# Search up to FP1 for age.
fit_fp <- mfp2(
lpsa ~ fp(age, df = 2) + svi,
data = prostate,
verbose = FALSE
)
# fp2() accepts the same options and produces the same model specification.
fit_fp2 <- mfp2(
lpsa ~ fp2(age, df = 2) + svi,
data = prostate,
verbose = FALSE
)
Run the code above in your browser using DataLab