Fit linear models with coefficient data as response or predictor.
Arguments
- data
A tibble with coefficient and/or scalar columns
- formula
A formula specifying the model. Can be:
Shape regression:
coe ~ length(shape depends on predictors)Response regression:
length ~ coe(response depends on shape)Multivariate response:
cbind(length, width) ~ coeMultiple predictors:
coe ~ length + temperatureInteractions:
coe ~ length * temperature
- ...
Additional arguments passed to
stats::lm()
Value
An object of class c("stat_lm", "momstats") containing:
data: Original tibble (unchanged)model: Thestats::lm()objectmethod: "lm"direction: "shape_regression" or "response_regression"call: The function callformula: Formula usedresponse_col: Response column name(s)predictor_cols: Predictor column name(s)r_squared: R^2 value(s)adj_r_squared: Adjusted R^2 value(s)
Details
stat_lm() provides a unified interface for linear modeling with morphometric data.
Formula directions
The function automatically detects model direction from the formula:
Shape regression (coe ~ predictors):
Fits multivariate regression with all harmonics as response
Proper treatment of shape as correlated multivariate outcome
Tests whether predictors affect shape
Example:
boteft %>% stat_lm(coe ~ length)
Response regression (response ~ coe):
Fits regression with unfolded harmonics as predictors
Tests whether shape predicts a response variable
Example:
boteft %>% stat_lm(length ~ coe)
Multivariate response (cbind(y1, y2) ~ coe):
Fits multivariate regression with multiple responses
Example:
boteft %>% stat_lm(cbind(length, width) ~ coe)
Examples
if (FALSE) { # \dontrun{
# Shape regression
lm1 <- boteft %>% stat_lm(coe ~ length)
lm2 <- boteft %>% stat_lm(coe ~ length + type)
lm3 <- boteft %>% stat_lm(coe ~ length * type)
# Response regression
lm4 <- boteft %>% stat_lm(length ~ coe)
# Multivariate response
lm5 <- boteft %>% stat_lm(cbind(length, width) ~ coe)
# Plot results
plot(lm1)
plot(lm1, type = "residuals")
# Get predictions
boteft_pred <- collect(lm1)
# Transduce to new values
new_shapes <- transduce(lm1, tibble::tibble(length = seq(50, 150, by = 10)))
} # }
