LWR {aLBI} | R Documentation |
Plot and Model Length-Weight Relationships with Optional Log Transformation
Description
This function visualizes and models the relationship between length and weight (or any two continuous variables) using linear regression. It supports both standard and log-transformed models, producing a ggplot2-based plot with a fitted line, optional confidence interval shading, and annotations for the regression equation, R^2, and p-value. When save_output is TRUE, the plot and model summary are saved to the working directory as a PDF and text file, respectively.
Usage
LWR(
data,
log_transform = TRUE,
point_col = "black",
line_col = "red",
shade_col = "red",
point_size = 2,
line_size = 1,
alpha = 0.2,
main = "Length-Weight Relationship",
xlab = NULL,
ylab = NULL,
save_output = TRUE
)
Arguments
data |
A data frame with at least two columns: the first for length, the second for weight. |
log_transform |
Logical. Whether to apply a log-log transformation to the variables. Default is |
point_col |
Color of the data points. Default is |
line_col |
Color of the regression line. Default is |
shade_col |
Color for the confidence interval ribbon. Default is |
point_size |
Size of the data points. Default is |
line_size |
Size of the regression line. Default is |
alpha |
Transparency for the confidence interval ribbon. Default is |
main |
Title of the plot. Default is |
xlab |
Optional. Custom x-axis label. If |
ylab |
Optional. Custom y-axis label. If |
save_output |
Logical. Whether to save the plot as a PDF and the model summary as a text file. Default is |
Value
A list containing:
model |
The fitted |
intercept |
The estimated intercept (back-transformed if log_transform = TRUE) |
slope |
The estimated slope |
r_squared |
R-squared value |
correlation_r |
Correlation coefficient (r) |
p_value |
P-value for slope |
plot |
The |
Examples
data(LWdata, package = "aLBI")
result <- LWR(LWdata, log_transform = TRUE, save_output = FALSE)
print(result$plot)