subsample_lm function

K-fold Resampled Coefficient Estimation for Linear Regression

K-fold Resampled Coefficient Estimation for Linear Regression

Performs k-fold resampling to estimate averaged coefficients for linear regression. The coefficients are averaged across k different subsets of the data to provide more stable estimates. For small samples (n < 100), returns a standard linear model instead.

subsample_lm(text, data, weights, k = 10)

Arguments

  • text: A character string or formula specifying the model to be fitted
  • data: A data frame containing the variables in the model
  • weights: Optional numeric vector of weights. If NULL, unweighted regression is performed
  • k: Integer specifying the number of resampling folds (default = 10)

Returns

An object of class 'lm' with averaged coefficients from k-fold resampling. For small samples, returns a standard lm object.

Details

The function splits the data into k subsets, fits a linear model on k-1 subsets, and stores the coefficients. This process is repeated k times, and the final coefficients are averaged across all iterations to provide more stable estimates.