youngukoo

New Member
Hi,

I've been spending quite some time to figure out how I can get the best R squared value from randomization of some values in a linear regression equation. I have allele frequency data and 14 environmental gradient data. Allele frequency value is fixed, but 2~14 combinations of the 14 environmental variables are used.

My aim here is to find a combination of the environmental variables that yield high R squared value. Here is a simple linear regression equation code that returns R squared value.

Code:
> summary(lm(allele ~ compositevalues))\$r.squared
"compositevalues" is a sum of standardized 14 different environmental values. I want to make 2~14 combinations of variables (with no replacement:i.e. var1+var2, var1+var3, var1+var4, var1+var2+var3, var2+var3+var4, var2+var3, var2+var4, var3+var4....etc. but not var1+var1+var2) as I mentioned above.

I would appreciate it if you could instruct me on how to write a code that generate random combination of (sum of ) the variables and returns combinations of variables that are used with R squared value of >0.4.

I was looking for permutation and resampling function in R, couldn't find ones that serve my purpose.....

Below is a part of my data set. Please see the attachment for a whole data set.

Locations allele var1 var2 var3
site1 0.230271924 -0.872093023 -0.696403914 -0.398671096
site2 -1.061563963 0.944767442 1.104640692 -0.398671096
site3 -0.524508594 0.339147287 -1.296752116 0.431893688
site4 0.027061785 2.156007752 -0.096055712 0.431893688
site5 0.186726894 0.944767442 1.104640692 -0.398671096
site6 -0.118088315 -0.266472868 -0.696403914 -0.398671096
site7 -1.003503923 0.339147287 -1.296752116 0.431893688
site8 -1.569589312 0.339147287 -1.296752116 0.431893688
site9 -1.119624003 0.944767442 0.50429249 -1.22923588
site10 1.362442702 -1.477713178 -0.096055712 1.262458472
site11 0.215756914 0.339147287 -1.897100318 1.262458472
site12 0.665722223 -1.477713178 -0.096055712 1.262458472
site13 1.086657513 -1.477713178 -0.096055712 1.262458472
site14 -0.001968235 0.339147287 1.704988894 -2.059800664
site15 -1.656679372 0.339147287 1.104640692 -2.059800664
site16 0.433482064 0.339147287 1.704988894 -2.059800664
site17 -0.814808794 1.550387597 -1.296752116 -0.398671096
site18 -0.713203724 1.550387597 -0.696403914 -0.398671096

Many thanks!