pbreheny / visreg

Visualization of regression functions
http://pbreheny.github.io/visreg/
61 stars 18 forks source link

parseFormula.R does not correctly handle scaled interaction terms #87

Open Albert-Tate opened 3 years ago

Albert-Tate commented 3 years ago

If you have scaled interactions fixed effect such as scale(x):scale(y) in the formula, parseFormula.R will not correctly remove both strings.

Expected: x:y Actual: x):scale(y

Line 17 in parseFormula.R is the relevant snippet to change.

Workaround: Replace Line 17 with the following lines (will only work for two way interactions - I'm not time rich at the moment to do it properly)

temp <- unlist(strsplit(f[i], ':'))
if(length(temp) == 2) {
  temp <- gsub("\\b[^\\(]*\\(([^,]+).*\\)", "\\1", temp)
  f[i] <- paste(temp[1],temp[2], sep=':')
} else {
 f[i] <- gsub("\\b[^\\(]*\\(([^,]+).*\\)", "\\1", f[i])
}

A real fix should just involve changing the regex string.