tests/testthat/test_EI_and_MEI.R

# TESTING EI AND MEI ------------------------------------------------------

N = 2

time_grid = seq( 0, 1, length.out = N * 1e2 )

Data = matrix( 0, nrow = N, ncol = length( time_grid ) )

for( iObs in 1 : N )
{
  Data[ iObs, ] =  as.numeric( time_grid >= ( iObs - 1 ) / N & time_grid < iObs / N )
}

Data[ N, length( time_grid ) ] = 1

test_that( "Correctness of EI",
           expect_equal( EI( Data ), rep( 1 / N, N )  ) )

test_that( "Correctness of MEI",
           expect_equal( MEI( Data ), rep( 1 - ( N - 1 ) / N^2, N )  ) )



# TEST BY JAMES LONG (TAMU) -------------------------------------------------------------------

yints = c( 1.27, .927, 1/2, .217, 0)
slopes = c( -1, -1, 0, 1, 1 )
time_grid = ( 0 : 100 ) / 100

Data = matrix( 0, nrow = length( yints ),
            ncol = length( time_grid ) )

for( i in 1 : length( yints ) )

    Data[ i, ] = yints[ i ] + time_grid * slopes[ i ]

test_that( "Correctness of EI - James Long test",
           expect_equal( EI( Data ), c( 0.2, 0.4, 0.2, 0.2, 0.4 ) ) )

Try the roahd package in your browser

Any scripts or data that you put into this service are public.

roahd documentation built on May 30, 2017, 6:09 a.m.