Learn R Programming

AICcPermanova (version 0.0.2)

akaike_adjusted_rsq: Akaike-Adjusted R Squared Calculation with Model Averaging

Description

Calculates the adjusted R squared for each predictor using the Akaike Information Criterion (AIC) and model averaging. AIC is used to compare the performance of candidate models and select the best one. Then, the R squared is adjusted based on the weight of evidence in favor of each model. The final result is a long-format table of variable names and corresponding adjusted R squared values.

Usage

akaike_adjusted_rsq(DF)

Value

A data.frame with columns "Variable" and "Full_Akaike_Adjusted_RSq". Each row represents a predictor, and its corresponding adjusted R squared value based on the Akaike-adjusted model averaging process.

Arguments

DF

A data.frame containing the variables to calculate the adjusted R squared for. The data.frame should include the columns: "form", "AICc", "max_vif", "k", "DeltaAICc", "AICWeight", and "N".

Details

The adjusted R squared is calculated as: $$Adjusted R^2 = 1 - (RSS / (N - k - 1)) * ((N - 1) / (N - k - 1))$$ where RSS is the residual sum of squares, N is the sample size, and k is the number of predictors. The R squared is adjusted based on the weight of evidence in favor of each model, which is calculated as: $$w_i = exp(-0.5 * DeltaAICc_i) / sum(exp(-0.5 * DeltaAICc))$$ where w_i is the weight of evidence in favor of the ith model, and DeltaAICc_i is the difference in AICc between the ith model and the best model. Model averaging uses the weights to combine the performance of different models in the final calculation of the adjusted R squared.

Examples

Run this code
library(data.table)
df <- data.table(form = c(1,2,3),
                 AICc = c(10,20,30),
                 max_vif = c(3,4,5),
                 k = c(1,2,3),
                 DeltaAICc = c(2,5,8),
                 AICWeight = c(0.2,0.5,0.3),
                 N = c(100,100,100),
                 A1 = c(0.3, 0.5, NA),
                 A2 = c(0.7, NA, 0.2),
                 A3 = c(0.2, 0.3, 0.6))
akaike_adjusted_rsq(df)

Run the code above in your browser using DataLab