From 1ece058e0dbd63e372a2455d1ead2bcbb4f5907a Mon Sep 17 00:00:00 2001 From: George Ostrouchov Date: Tue, 15 Jan 2019 13:44:21 -0500 Subject: [PATCH] as.formula and as.data.frame + reg exp for strsplit --- R/FSR.R | 2 +- R/FSR_helpers.R | 2 +- R/plm.R | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/R/FSR.R b/R/FSR.R index 091604f..3d1e82a 100644 --- a/R/FSR.R +++ b/R/FSR.R @@ -250,7 +250,7 @@ FSR <- function(Xy, if(grepl("\\*", out$models$features[m])){ - tmp <- unlist(strsplit(out$models$features[m], "\\*")) + tmp <- unlist(strsplit(out$models$features[m], "[ ]*\\*[ ]*")) if(mean(tmp %in% out$models$features[out$models$accepted]) == 1){ out$models$formula[m] <- paste(out[["best_formula"]], "+", out$models$features[m]) }else{ diff --git a/R/FSR_helpers.R b/R/FSR_helpers.R index 7bc739a..4466ae9 100644 --- a/R/FSR_helpers.R +++ b/R/FSR_helpers.R @@ -25,7 +25,7 @@ pow <- function(X, degree){ model_matrix <- function(f, d, intercept, noisy=TRUE){ - tried <- try(model.matrix(f, d, na.action = "na.omit"), silent=TRUE) + tried <- try(model.matrix(as.formula(f), d, na.action = "na.omit"), silent=TRUE) if(inherits(tried, "try-error")){ if(noisy) cat("model.matrix() reported the following error:\n", tried, "\n\n") diff --git a/R/plm.R b/R/plm.R index 1b13335..5f80008 100644 --- a/R/plm.R +++ b/R/plm.R @@ -555,7 +555,6 @@ predict.polyFit <- function(object,newdata) new_data <- getPoly(newdata, object$degree, object$maxInteractDeg)$xdata plm.newdata <- predict(object$pca.xy, new_data)[,1:object$pcaCol] - plm.newdata <- as.data.frame(plm.newdata) } else stop('invalid pcaLocation') } else if (object$PCA == "RSpectra") { if (object$pcaLocation == "front") { @@ -571,9 +570,9 @@ predict.polyFit <- function(object,newdata) xy.eig <- object$pca.xy plm.newdata <- as.matrix(new_data) %*% xy.eig$vectors[,1:object$pcaCol] - plm.newdata <- as.data.frame(plm.newdata) } } # end doPCA + plm.newdata <- as.data.frame(plm.newdata) if (object$use == "lm") { pred <- predict(object$fit, plm.newdata)