calculate_model_metrics: Function to compute model metrics to be used within 'mfp2'

View source: R/model_metrics.R

calculate_model_metricsR Documentation

Function to compute model metrics to be used within mfp2

Description

Mostly used within an mfp step to compare between the different fp models of a variable.

Usage

calculate_model_metrics(obj, n_obs, df_additional = 0)

Arguments

obj

a list returned by fit_model() representing a glm or Cox model fit.

n_obs

a numeric value indicating the number of observations for the data used to fit obj.

df_additional

a numeric value indicating the number of additional degrees of freedom to be accounted for in the computations of AIC and BIC. These may be necessary when a model uses FP terms, as these add another degree of freedom per estimated power.

Value

A numeric vector with the following entries:

  • df: number of degrees of freedom of model (i.e. coefficients plus df_additional).

  • deviance_rs: "deviance", i.e. minus twice the log likelihood. This is not the usual definition of deviance used by R, which is defined as twice the difference between the log likelihoods of the saturated model (one parameter per observation) and the null (or reduced) model. It is, however, the definition used in Royston and Sauerbrei (2008) and in mfp. For selection of fps this does not really play a role, as the common factor would be cancelled anyway when comparing models based on deviances.

  • sse: sum of squared residuals as returned by fit_model().

  • deviance_gaussian: deviance computed by deviance_gaussian(), applicable to Gaussian models and used for F-test computations.

  • aic: Akaike information criterion, defined as ⁠-2logL + 2(df + df_additional)⁠.

  • bic: Bayesian information criterion, defined as ⁠-2logL + log(n_obs)(df + df_additional)⁠.

  • df_resid: residual degrees of freedom, defined as n_obs - df. For consistency with stata we subtract the scale parameter from df.

References

Royston, P. and Sauerbrei, W., 2008. Multivariable Model - Building: A Pragmatic Approach to Regression Anaylsis based on Fractional Polynomials for Modelling Continuous Variables. John Wiley & Sons.


mfp2 documentation built on Nov. 15, 2023, 1:06 a.m.