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 TRUE.

point_col

Color of the data points. Default is "black".

line_col

Color of the regression line. Default is "red".

shade_col

Color for the confidence interval ribbon. Default is "red".

point_size

Size of the data points. Default is 2.

line_size

Size of the regression line. Default is 1.

alpha

Transparency for the confidence interval ribbon. Default is 0.2.

main

Title of the plot. Default is "Length-Weight Relationship".

xlab

Optional. Custom x-axis label. If NULL, a label is generated based on log_transform.

ylab

Optional. Custom y-axis label. If NULL, a label is generated based on log_transform.

save_output

Logical. Whether to save the plot as a PDF and the model summary as a text file. Default is TRUE.

Value

A list containing:

model

The fitted lm object

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 ggplot object for further customization

Examples

data(LWdata, package = "aLBI")
result <- LWR(LWdata, log_transform = TRUE, save_output = FALSE)
print(result$plot)


[Package aLBI version 0.1.8 Index]