Skip to content

Commit

Permalink
cv-ncvreg: adding test for return Y
Browse files Browse the repository at this point in the history
  • Loading branch information
pbreheny committed Jan 4, 2024
1 parent e9c9d89 commit 17ceee3
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion inst/tinytest/cv-ncvreg.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
if (interactive()) library(tinytest)
suppressPackageStartupMessages(library(glmnet))

#### Linear regression ####

# Linear regression -------------------------------------------------------

# Works
X <- matrix(rnorm(500), 50, 10)
Expand Down Expand Up @@ -116,3 +118,12 @@ y <- rnorm(n, mean=X%*%b) > 0
cvfit <- cv.ncvreg(X, y, family='binomial', returnY=TRUE)
pe <- apply((cvfit$Y>=0.5)!=y, 2, mean)
expect_equivalent(pe, cvfit$pe, tol= .001)

# Return Y ----------------------------------------------------------------

X <- matrix(rnorm(500), 50, 10)
y <- 100 + X[,1] + rnorm(50)
cvfit <- cv.ncvreg(X, y, returnY=TRUE)
expect_equivalent(
cvfit$cve,
apply((cvfit$Y - y)^2, 2, mean))

0 comments on commit 17ceee3

Please sign in to comment.