R Under development (unstable) (2025-05-01 r88184 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > > library(modeltools) Loading required package: stats4 > > d <- data.frame(x = rnorm(100), y = rnorm(100), z = runif(100)) > d[["x"]][1:10] <- NA > > a <- linearModel@dpp(y ~ x + z - 1, data = d, na.action = na.pass) > b <- na.omit(a) > mod1 <- linearModel@fit(b) > > mod2 <- lm(y ~ x + z - 1, data = d) > > nd <- data.frame(x = rnorm(100), z = runif(100)) > > stopifnot(identical(mod1$predict_response(nd), predict(mod2, newdata = nd))) > > stopifnot(identical(coef(mod1), coef(mod2))) > > u <- linearModel@fit > system.time(for (i in 1:100) mod1 <- u(b)) user system elapsed 0.02 0.02 0.04 > system.time(for (i in 1:100) mod2 <- lm(y ~ x + z - 1, data = d)) user system elapsed 0.11 0.01 0.13 > > dn <- data.frame(x = rnorm(100), y = rnorm(100), z = runif(100)) > all.equal(Predict(mod1, dn), Predict(mod2, dn)) [1] TRUE > > system.time(for (i in 1:100) p1 <- Predict(mod1, dn)) user system elapsed 0.03 0.00 0.04 > system.time(for (i in 1:100) p2 <- Predict(mod2, dn)) user system elapsed 0.06 0.01 0.08 > > system.time(for (i in 1:100) p1 <- predict(mod1, dn)) user system elapsed 0.04 0.00 0.04 > system.time(for (i in 1:100) p2 <- predict(mod2, dn)) user system elapsed 0.05 0.02 0.06 > > ### check bug fix: non-misssing `data' argument > df <- data.frame(y = 1:10, x = 1:10 + 1, z = 1:10 + 2) > mf <- ModelEnvFormula(y ~ x, data = df, other = list(part = ~ z)) > stopifnot(isTRUE(all.equal(mf@get("part")$z, df[["z"]]))) > df2 <- df + 1 > stopifnot(isTRUE(all.equal(mf@get("part", data = df2)$z, df2[["z"]]))) > > ### ~ 1 > df <- data.frame(y = 1:10) > mf <- ModelEnvFormula(y ~ 1, data = df) > x <- mf@get("designMatrix") > stopifnot(nrow(x) == 10 && all(x[,1] == 1)) > > ### bugfix: subset was not correctly interpreted in `frame' > tmp <- function(formula, data = list(), subset = NULL) + ModelEnvFormula(formula, data, subset = subset, frame = parent.frame()) > foo <- function(x, y, subset, ...) tmp(y ~ x, subset = subset, ...) > a <- 1:10 > b <- 1:10 > stopifnot(identical(foo(a, b, subset = 1:5)@get("response")[[1]],1:5)) > > x <- 1 > y <- 2 > stopifnot(identical(foo(a, b, subset = 1:5)@get("response")[[1]],1:5)) > > ### subset problems > menv <- ModelEnvFormula(Species ~ ., data = iris, + subset = (iris$Species != "virginica")) > stopifnot(nrow(menv@get("input")) == 100) > stopifnot(nrow(menv@get("input", data = iris)) == 150) > > menv <- ModelEnvFormula(Species ~ ., data = iris, + subset = (iris$Species != "virginica"), + keep.subset = TRUE) > stopifnot(nrow(menv@get("input")) == 100) > stopifnot(nrow(menv@get("input", data = iris)) == 150) > > > ###********************************************************** > > stopifnot(!empty(menv)) > menv1 <- new("ModelEnv") > stopifnot(empty(menv1)) > > ### fixed in 0.2-17 > dpp(linearModel, Sepal.Length ~ 1, data = iris, na.action = na.omit) A ModelEnvFormula with response variable(s): Sepal.Length input variable(s): number of observations: 150 > > proc.time() user system elapsed 0.92 0.20 1.10