context("Tests for bc_simulate function")
library(binclass)
# Simple univariate example
sim = bc_simulate( 100, 1, 1 )
test_that( "bc_simulate class works", {
expect_true( is.bc_simulate( sim ) )
})
test_that( "subset method works", {
expect_equal( sim$y, subset( sim ) )
expect_equal( sim$X, subset( sim, F ) )
})
levs = c( 'Disorder', 'No disorder' )
sim = bc_simulate( 100, 1, 1, levels = levs )
test_that( "levels method works", {
expect_equal( levels(sim), levs )
})
sim = bc_simulate( 100, 8, 4 )
prd = paste( 'P', 1:8, sep = '' )
test_that( "dimnames method works", {
expect_equal( dimnames(sim), prd )
})
test_that( "coef method works", {
expect_equal( sim$beta, coef( sim ) )
cmp = c( Intercept = sim$intercept,
sim$beta )
expect_equal( cmp, coef( sim, int = T ) )
})
n = 10000 # Expect error to be 1%
p = .8
val = log( p/(1-p) )
sim = bc_simulate( 10000, 1, 0, intercept = val )
# 99.9% confidence intervals
alpha = .999
interval = (1-alpha)/2
interval = c( interval, interval + alpha )
CI = c(
qbinom( interval[1], n, p )/n,
qbinom( interval[2], n, p )/n
)
test_that( "intercept can be adjusted", {
m = mean( as.integer( sim ) )
expect_true( all( m > CI[1] & m < CI[2] ) )
})
sim = bc_simulate( 100, 1, 1, param = c( .2, .8 ) )
cf = coef( sim )
test_that( "coefficient bounds can be adjusted", {
expect_true( abs(cf) > .2 & abs(cf) < .8 )
})
test_that( "bc_simulate print method runs without error", {
expect_output( print( sim ) )
})
test_that( "bc_simulate features method works", {
sel = coef( sim ) != 0
expect_equal( features( sim ), names( coef( sim ) )[sel] )
})
sim = bc_simulate( 400, 8, 4 )
test_that( "bc_simulate dim method works", {
expect_equal( size( sim ), 400 )
expect_equal( size( sim, F ), c( 400, 8 ) )
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.