# File Name: linear_regression_analysis.R
# Author: Gerard King - www.gerardking.dev
# Title: Linear Regression Analysis and Visualization
# Description: This R program generates a synthetic dataset, fits a linear regression model,
# and visualizes the data points along with the fitted regression line. It also outputs
# the regression coefficients and other model statistics.
# Use Cases:
# - Predictive modeling for trend analysis
# - Exploring the relationship between two variables
# - Teaching statistical concepts like linear regression
# Audience:
# - Data scientists and analysts
# - Students learning machine learning and statistics
# - Researchers conducting regression analysis
# Blue Team Uses:
# - Analyzing trends in system performance over time
# - Predicting potential future system loads or network traffic
# - Evaluating the correlation between variables in security logs
# Red Team Uses:
# - Modeling potential attack patterns based on historical data
# - Simulating data trends for penetration testing scenarios
# - Assessing the impact of a security breach on system performance
# Current Date: 2025-03-06
# Generate synthetic data for linear regression
set.seed(456)
# Simulate independent variable (x) and dependent variable (y)
x <- rnorm(100)
y <- 2 * x + rnorm(100)
# Create a data frame
data <- data.frame(x = x, y = y)
# Fit a linear regression model
model <- lm(y ~ x, data = data)
# Create a scatter plot of the data points
plot(data$x, data$y, main="Linear Regression: y = 2x + Noise",
xlab="X", ylab="Y", pch=19, col="blue")
# Add the regression line to the plot
abline(model, col="red", lwd=2)
# Display the regression coefficients
cat("Regression Coefficients:\n")
print(coef(model))
# Display the summary of the model
cat("\nModel Summary:\n")
summary(model)
# Print the current date for reference
cat("Date of execution:", Sys.Date(), "\n")