From 9cdddb56ffa264de673c335cccde115504abaa62 Mon Sep 17 00:00:00 2001 From: Shawn Garbett Date: Tue, 4 Oct 2022 15:46:32 -0500 Subject: [PATCH] Fixed Issue #2 works with ns now --- DESCRIPTION | 5 +++-- R/strip_.glm.R | 2 +- R/strip_.lm.R | 4 ++-- tests/testthat/test-strip.R | 10 +++++++--- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5457dea..88205f4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: strip Type: Package Title: Lighten your R Model Outputs -Version: 1.0.0 +Version: 1.0.1 Date: 2018-09-30 Authors@R: person("Paul", "Poncet", , "paulponcet@yahoo.fr", role = c("aut", "cre")) Description: The strip function deletes components of R model outputs that are useless for specific purposes, such as predict[ing], print[ing], summary[izing], etc. @@ -19,7 +19,8 @@ Suggests: randomForest, stats, testthat, - utils + utils, + splines URL: https://github.com/paulponcet/strip BugReports: https://github.com/paulponcet/strip/issues RoxygenNote: 6.1.0 diff --git a/R/strip_.glm.R b/R/strip_.glm.R index dcda900..6677839 100644 --- a/R/strip_.glm.R +++ b/R/strip_.glm.R @@ -39,7 +39,7 @@ function(object, op$family$aic <- NULL op$family$validmu <- NULL op$family$simulate <- NULL - attr(op$terms,".Environment") <- NULL + #attr(op$terms,".Environment") <- NULL attr(op$formula,".Environment") <- NULL } else { diff --git a/R/strip_.lm.R b/R/strip_.lm.R index 39018c0..aba6e5e 100644 --- a/R/strip_.lm.R +++ b/R/strip_.lm.R @@ -30,7 +30,7 @@ function(object, op$prior.weights <- NULL op$linear.predictors <- NULL - attr(op$terms,".Environment") <- NULL + #attr(op$terms,".Environment") <- NULL attr(op$formula,".Environment") <- NULL } else if ("predictci" %in% keep) { @@ -44,7 +44,7 @@ function(object, op$prior.weights <- NULL op$linear.predictors <- NULL - attr(op$terms,".Environment") <- NULL + #attr(op$terms,".Environment") <- NULL attr(op$formula,".Environment") <- NULL } else { diff --git a/tests/testthat/test-strip.R b/tests/testthat/test-strip.R index 069891f..c8a8c42 100644 --- a/tests/testthat/test-strip.R +++ b/tests/testthat/test-strip.R @@ -1,10 +1,11 @@ context("Strip") +library(splines) test_that("predict.lm works correctly after stripping", { set.seed(111) mtcars <- datasets::mtcars i <- sample(2, nrow(mtcars), replace = TRUE, prob = c(0.8, 0.2)) - r1 <- stats::lm(mpg ~ ., data = mtcars[i == 1,]) + r1 <- stats::lm(mpg ~ cyl + ns(disp,2)+hp+drat+wt+qsec+vs+am+gear+carb, data = mtcars[i == 1,]) r2 <- strip(r1, keep = "predict") p1 <- stats::predict(r1, newdata = mtcars[i == 2,]) p2 <- try(stats::predict(r2, newdata = mtcars[i == 2,]), silent = TRUE) @@ -27,13 +28,16 @@ test_that("print.lm works correctly after stripping", { test_that("predict.glm works correctly after stripping", { ldose <- rep(0:5, 2) numdead <- c(1, 4, 9, 13, 18, 20, 0, 2, 6, 10, 12, 16) + sex <- factor(rep(c("M", "F"), c(6, 6))) + other<-rnorm(12) SF <- cbind(numdead, numalive = 20-numdead) ld <- seq(0, 5, 0.1) - r1 <- stats::glm(SF ~ sex*ldose, family = binomial) + r1 <- stats::glm(SF ~ sex*ldose+ns(other,2), family = binomial) r2 <- strip(r1, keep = "predict") df <- data.frame(ldose = ld, - sex = factor(rep("M", length(ld)), levels = levels(sex))) + sex = factor(rep("M", length(ld)), levels = levels(sex)), + other=rnorm(length(ld))) p1 <- stats::predict(r1, newdata = df, type = "response") p2 <- try(stats::predict(r2, newdata = df, type = "response"), silent = TRUE)