I'm an R beginner and I have a large dataset containing skeletal measurements for mammals, such as femur length, cranial length, lower tooth row length, and more. Each animal is also associated with various categories, including locomotory type and diet. My goal is to automate the process of performing linear regressions in R to identify the measurements that serve as the strongest predictors of body mass.

In this dataset, I have 46 different measurements, and I'm also interested in exploring combinations of certain measurements (e.g., humerus circumference + femur circumference) as predictors. Additionally, I want to take into account the categorical variables, such as diet, which might influence specific predictors only (e.g. dental morphology).

Could you please provide guidance on how to automate this process in R? Specifically, I would like to know how to:

  1. Iterate through the measurements and combinations to perform OLS and SMA regressions.
  2. Assess the strength of each regression model to determine the strongest predictors of body mass.
  3. Consider the impact of categorical variables within the regression analysis.

I have considered using regression trees but I'm not sure that would be the best way to proceed. If possible, I would appreciate any suggested approaches to help me get started. Thank you in advance for your help!

  • 1
    $\begingroup$ This seems optimistic if you are trying to do inference. But a place to start might be regression with some regularisation, such as via the LASSO. $\endgroup$
    – mkt
    Jul 14, 2023 at 10:46
  • 1
    $\begingroup$ Welcome to Cross Validated! This question and its answers are worth a read $\endgroup$
    – Dave
    Jul 14, 2023 at 10:47
  • 1
    $\begingroup$ If you're interested in something more exploratory, you could also consider something like principal components regression. $\endgroup$
    – mkt
    Jul 14, 2023 at 10:48
  • 1
    $\begingroup$ Anatomical measures are expected to correlate in allometric relations of the form y=ax^b (i.e. linearly on log-log scales). See "The Ecological Implications of Body Size" by Peters. Hence, your skeletal measures used as predictors will be highly correlated. That's a problem. For a first simple analysis, I would (1) do a PCA on all your measures excluding body mass and ignoring categorical variables. Then (2) regress body mass on PC1 and PC2 and the categorical variables. And (3) try out various ordination methods (CA and whatever) to visualize any segregation by categorical variables. $\endgroup$ Jul 15, 2023 at 22:04

1 Answer 1


Welcome to the site.

My advice is to NOT automate this. There are a variety of methods to do automated model selection (forward, backward, stepwise). Of these, the only ones that I would use are penalized methods such as LASSO. What you seem to want is all subsets regression, which is possible in R. There are a few methods (you can Google "all subsets regression in R" to find some) but these aren't good. P values will be too low, standard errors too small, models too complex and parameter estimates biased away from 0. (See Frank Harrell's book Regression Modeling Strategies for details, examples, proofs and so on).

Worse: It stops you from thinking.

Choose models that make sense. Just a few of them. Compare those. You've already shown us that you've done some of this.

If you are interested in uncovering interactions, then trees (or some offshoot of them) may be good. I'm not sure why you are opposed.

If you want to look at combinations of variables, and don't need to include the original variables, then partial least squares might be good. From the variables you've listed, it looks like the first component will be "size", but that may be fine.

  • 4
    $\begingroup$ (+1) The general size dimension is why I think principal components regression might be reasonable here. $\endgroup$
    – mkt
    Jul 14, 2023 at 11:12
  • 8
    $\begingroup$ The worst thing I can think of saying about variable selection methods is that they fail at what they pretend to do. They can't select the right variables. And small changes in the dataset result in different variables selected. They there is their destruction of standard errors ... $\endgroup$ Jul 14, 2023 at 11:58
  • 3
    $\begingroup$ @mkt For regression, I tend to prefer PLS to principal components regression, because it incorporates the dependent variable. $\endgroup$
    – Peter Flom
    Jul 14, 2023 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.