jvbraun / AlgDesign

Algorithmic Experimental Design by Robert E. Wheeler
12 stars 5 forks source link

Convenience code may not work for large numbers of variables #10

Open some-guy1 opened 5 years ago

some-guy1 commented 5 years ago

This is my variable list:


"x.1"      "x.2"      "x.3"      "x.4"      "x.5"      "x.6"      "x.7"      "x.8"      "x.9"      "x.10"     "multi.2" 
"multi.3"  "multi.4"  "multi.5"  "multi.6"  "multi.7"  "multi.8"  "multi.9"  "multi.10" "multi.11" "multi.12" "multi.13" "multi.14" "multi.15" "multi.16" "multi.17" "multi.18"

I then send to expand.formula:

expand.formula(y~quad(.),varNames= names(df) )

This outputs the wrong set of variables:


y ~ (x.1 + x.2 + x.3 + x.4 + x.5 + x.6 + x.7 + x.8 + x.9 + x.10 + 
    x.11 + x.12 + x.13 + x.14 + x.15 + x.16 + x.17 + x.18 + x.19 + 
    x.20 + x.21 + x.22 + x.23 + x.24 + x.25 + x.26 + x.27)^2 + 
    I(x.1^2) + I(x.2^2) + I(x.3^2) + I(x.4^2) + I(x.5^2) + I(x.6^2) + 
    I(x.7^2) + I(x.8^2) + I(x.9^2) + I(x.10^2) + I(x.11^2) + 
    I(x.12^2) + I(x.13^2) + I(x.14^2) + I(x.15^2) + I(x.16^2) + 
    I(x.17^2) + I(x.18^2) + I(x.19^2) + I(x.20^2) + I(x.21^2) + 
    I(x.22^2) + I(x.23^2) + I(x.24^2) + I(x.25^2) + I(x.26^2) + 
    I(x.27^2)

This is because of the gsub(ag, nms[i], strg) within the quad/cubic functions is replacing too many variables in the formula string.

some-guy1 commented 5 years ago

I am thinking the gsub(ag, nms[i], strg) code could be removed and the line before the gsub replaced with something like:


strg <- paste(paste("(", paste(nms, sep = "", 
                                 collapse = "+"), ")^2", sep = ""), "+", paste("I(", 
                                  nms, "^2)", sep = "", collapse = "+"))