In your case, it might be feasible to try out all combinations (there are 16383 combinations) of sums. I wrote a quick and dirty implementation of that. With 14 variables it takes less than a minute to try out all combinations. If you want a random combination, you can modify the code to meet your needs.
my.vars <- matrix(NA, ncol=14, nrow=) # a matrix with your 14 different environmental variables
colnames(my.vars) <- paste("var", 1:14, sep="") # add row names "var1" - "var14"
my.grad.data <- 1:14
sum.vars <- vector()
r.2 <- vector()
comb.mat <- matrix(numeric(0), nrow=14, ncol=0) # initialise the matrix containing all combinations
for ( i in 1:14 ) { # generate and store all possible combination of sums of the 14 variables
t.mat <- combn(my.grad.data, m=i)
comb.mat <- cbind(comb.mat, rbind(t.mat, matrix(NA, ncol=dim(t.mat)[2] , nrow=14-i)))
}
for ( j in 1:dim(comb.mat)[2] ) { # calculate and store the R2 for all combinations
sum.vec <- rowSums(my.vars[, comb.mat[, j]], na.rm=TRUE)
sum.vars[j] <- paste(
colnames(my.vars[, comb.mat[, j]])[!is.na(colnames(my.vars[, comb.mat[, j]]))],
collapse="+")
r.2[j] <- summary(lm(allele ~ sum.vec))$r.squared
}
result.frame <- data.frame(combination=sum.vars, r2=r.2)
result.frame.sorted <- result.frame[order(r.2, decreasing=TRUE), ]
head(result.frame.sorted, n=10) # the 10 "best" combinations
Best Answer
The OP essentially wants to calculate the $R^2$ differences for individual variables. So the models would be:
And then you can do
But this probably doesn't do what you think it does (explain exactly how much the individual variables explain via the $R^2$ difference) - at least if there is any multicollinearity (which there usually is).