Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

FP

Fractional Polynomials


Description

Fractional polynomials transformation for continuous covariates.

Usage

FP(x, p = c(-2, -1, -0.5, 0.5, 1, 2, 3), scaling = TRUE)

Arguments

x

a numeric vector.

p

all powers of x to be included.

scaling

a logical indicating if the measurements are scaled prior to model fitting.

Details

A fractional polynomial refers to a model ∑_{j = 1}^k (β_j x^{p_j} + γ_j x^{p_j} \log(x)) + β_{k + 1} \log(x) + γ_{k + 1} \log(x)^2, where the degree of the fractional polynomial is the number of non-zero regression coefficients β and γ.

Value

A matrix including all powers p of x, all powers p of log(x), and log(x).

References

Willi Sauerbrei and Patrick Royston (1999), Building multivariable prognostic and diagnostic models: transformation of the predictors by using fractional polynomials. Journal of the Royal Statistical Society A, 162, 71–94.

See Also

gamboost to fit smooth models, bbs for P-spline base-learners

Examples

data("bodyfat", package = "TH.data")
    tbodyfat <- bodyfat

    ### map covariates into [1, 2]
    indep <- names(tbodyfat)[-2]
    tbodyfat[indep] <- lapply(bodyfat[indep], function(x) {
        x <- x - min(x)
        x / max(x) + 1
    })

    ### generate formula
    fpfm <- as.formula(paste("DEXfat ~ ",
        paste("FP(", indep, ", scaling = FALSE)", collapse = "+")))
    fpfm

    ### fit linear model
    bf_fp <- glmboost(fpfm, data = tbodyfat,
                      control = boost_control(mstop = 3000))

    ### when to stop
    mstop(aic <- AIC(bf_fp))
    plot(aic)

    ### coefficients
    cf <- coef(bf_fp[mstop(aic)])
    length(cf)
    cf[abs(cf) > 0]

mboost

Model-Based Boosting

v2.9-5
GPL-2
Authors
Torsten Hothorn [cre, aut] (<https://orcid.org/0000-0001-8301-0471>), Peter Buehlmann [aut] (<https://orcid.org/0000-0002-1782-6015>), Thomas Kneib [aut] (<https://orcid.org/0000-0003-3390-0972>), Matthias Schmid [aut] (<https://orcid.org/0000-0002-0788-0317>), Benjamin Hofner [aut] (<https://orcid.org/0000-0003-2810-3186>), Fabian Otto-Sobotka [ctb] (<https://orcid.org/0000-0002-9874-1311>), Fabian Scheipl [ctb] (<https://orcid.org/0000-0001-8172-3603>), Andreas Mayr [ctb] (<https://orcid.org/0000-0001-7106-9732>)
Initial release
2021-04-06

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.