Multiple linear regression model (AICc Based)
By- Rounak Choudhary
By- Rounak Choudhary
Multiple Linear Regression (MLR) is a statistical technique used to model the relationship between one continuous response variable and two or more predictor variables. It helps identify how multiple independent variables together influence a dependent variable, while quantifying the individual contribution of each predictor. In ecology, MLR is widely applied to understand how environmental and landscape factors—such as vegetation cover, land use, or habitat structure—affect biodiversity metrics like species richness, abundance, or biomass. For example, ecologists may use MLR to determine which habitat features most strongly predict bird diversity across different sites, enabling better conservation and land management decisions.
Pre Requirements:- You will need data in a CSV as follows:
# Install the MuMIn package (for model selection using AIC/AICc)
install.packages("MuMIn") # Only run this once
library(MuMIn) # Load the MuMIn package
# Load your dataset from a CSV file
mydata <- read.csv("C:/Users/Rounak Choudhary/Desktop/BirdAIC.csv")
# Step 1: Define a global linear model
# Fspe is the response variable (e.g., bird species richness)
# The model includes multiple landscape/environmental predictors
global.model <- lm(Fspe ~ Area + AIV + Tree + Shrub + Grass + Crop + Built + Bare +
Water + Cont + PD + ED + IJI + SDI + CA, data = mydata)
# Step 2: Ensure the model selection function handles missing values properly
options(na.action = "na.fail") # Required for dredge() to function correctly
# Step 3: Use dredge() to generate all possible models based on subsets of predictors
model.set <- dredge(global.model)
# Step 4: Print the full model selection table
# This includes models ranked by AICc, along with their variables, AICc scores, weights, etc.
print(model.set)
# Step 5: Extract the best model (i.e., the model with the lowest AICc)
best.model <- get.models(model.set, 1)[[1]] # Extract top-ranked model
# Display a detailed summary of the best model (coefficients, p-values, R², etc.)
summary(best.model)
# Compare the AIC of the global model (for context)
AIC(global.model)
# Show the top-ranked model from the selection table (can change 1:5 to see more top models)
model.set[1:1, ]
# Step 6: Extract the top 3 models from the model set based on AICc
top3.models <- get.models(model.set, subset = 1:3)
# Step 7: Display a summary of each of the top 3 models
# lapply applies summary() to each model in the list
lapply(top3.models, summary)