context("Tests for estimate.en_lr function")
library(binclass)
# Create example data
n = 900
K = 4
K_sig = 2
param = c( .25, .75 )
sim = bc_simulate( n, K, K_sig, param = param )
# Set up cross-validation
index = c( rep( 1, 600 ), rep( 2, 300 ) )
dat = train_test( 2, index, sim$y, sim$X )
# For debugging purposes
# control = list()
fit = bc_estimate( 'glmnet', dat )
test_that( "bc_estimate class works", {
expect_true( is.bc_estimate( fit ) )
})
val = coef( fit )
tst = coef( fit$fit, s = fit$best_lambda )
rownames( tst ) = c( 'Intercept', rownames(tst)[-1] )
tst = tst[,1]
test_that( "coefficients are extracted correctly", {
expect_equal( val, tst[-1] )
expect_equal( coef( fit, int = T ), tst )
expect_length( coef( fit, sig = F ), length( coef( sim ) ) + 1 )
})
test_that( "bc_estimate print method works", {
expect_output( print( fit ) )
})
test_that( "features are extracted correctly", {
expect_equal( features( fit ), names( val ) )
})
test_that( "bc_estimate levels method works correctly", {
expect_equal( levels( fit ), levels( dat ) )
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.