Skip to content

Commit 1705b1e

Browse files
committed
expand unit tests for pt() and correct use of pt() with ncp argument
1 parent 52398e9 commit 1705b1e

File tree

4 files changed

+43
-18
lines changed

4 files changed

+43
-18
lines changed

ChangeLog

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
2013-11-22 Dirk Eddelbuettel <edd@debian.org>
22

3-
* inst/include/Rcpp/stats/nt.h: Correct expandion for (d|q|p)nt() function
3+
* inst/include/Rcpp/stats/nt.h: Correct expansion of (d|q|p)nt()
4+
* inst/unitTests/runit.stats.R: Added unit tests for t dist with ncp
5+
* inst/unitTests/cpp/stats.cpp: C++ side of expamded unit tests
46

57
2013-11-05 Dirk Eddelbuettel <edd@debian.org>
68

inst/NEWS.Rd

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
\title{News for Package 'Rcpp'}
33
\newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}}
44

5-
\section{Changes in Rcpp version 0.10.7 (2013-11-21)}{
5+
\section{Changes in [unreleased] Rcpp version 0.10.7 (2013-11-21)}{
66
\itemize{
77
\item Changes in Rcpp API:
88
\itemize{
99
\item The function \code{dnt}, \code{pnt}, \code{qnt} sugar
10-
functions were incorrectly expanding to the no-degree-of-freedoms variant.
10+
functions were incorrectly expanding to the no-degree-of-freedoms
11+
variant.
12+
\item Unit tests for \code{pnt} were added.
1113
}
1214
}
1315
}

inst/unitTests/cpp/stats.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,19 @@ List runit_ppois( NumericVector xx){
197197
}
198198

199199
// [[Rcpp::export]]
200-
List runit_pt( NumericVector xx ){
201-
return List::create(
202-
_["false"] = pt( xx, 5, true),
203-
_["true"] = pt( xx, 5, true, true )
204-
);
200+
List runit_pt(NumericVector xx){
201+
return List::create(_["lowerNoLog"] = pt( xx, 5 /*true, false*/),
202+
_["lowerLog"] = pt( xx, 5, true, true),
203+
_["upperNoLog"] = pt( xx, 5, false /*,false*/),
204+
_["upperLog"] = pt( xx, 5, false, true) );
205+
}
206+
207+
// [[Rcpp::export]]
208+
List runit_pnt(cdNumericVector xx){
209+
return List::create(_["lowerNoLog"] = pnt( xx, 5, 7 /*true, false*/),
210+
_["lowerLog"] = pnt( xx, 5, 7, true, true),
211+
_["upperNoLog"] = pnt( xx, 5, 7, false /*,false*/),
212+
_["upperLog"] = pnt( xx, 5, 7, false, true) );
205213
}
206214

207215
// [[Rcpp::export]]

inst/unitTests/runit.stats.R

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
if (.runThisTest) {
2424

25-
.setUp <- Rcpp:::unit_test_setup( "stats.cpp" )
25+
.setUp <- Rcpp:::unit_test_setup( "stats.cpp" )
2626

2727
test.stats.dbeta <- function() {
2828
vv <- seq(0, 1, by = 0.1)
@@ -225,7 +225,7 @@ test.stats.pnorm <- function( ) {
225225
checkEqualsNumeric(pz$lowerNoLog, runit_pnorm(-z)$upperNoLog, msg = "stats.pnorm")
226226
checkEqualsNumeric(log(pz$lowerNoLog[z.ok]), pz$lowerLog[z.ok], msg = "stats.pnorm")
227227
## FIXME: Add tests that use non-default mu and sigma
228-
}
228+
}
229229

230230
test.stats.ppois <- function( ) {
231231
vv <- 0:20
@@ -241,10 +241,23 @@ test.stats.ppois <- function( ) {
241241
test.stats.pt <- function( ) {
242242
v <- seq(0.0, 1.0, by=0.1)
243243
checkEquals(runit_pt(v),
244-
list( false = pt(v, 5), true = pt(v, 5, log=TRUE ) ), # NB: need log=TRUE here
244+
list(lowerNoLog = pt(v, 5),
245+
lowerLog = pt(v, 5, log=TRUE),
246+
upperNoLog = pt(v, 5, lower=FALSE),
247+
upperLog = pt(v, 5, lower=FALSE, log=TRUE) ),
245248
msg = "stats.pt" )
246249
}
247250

251+
test.stats.pnt <- function( ) {
252+
v <- seq(0.0, 1.0, by=0.1)
253+
checkEquals(runit_pnt(v),
254+
list(lowerNoLog = pt(v, 5, ncp=7),
255+
lowerLog = pt(v, 5, ncp=7, log=TRUE),
256+
upperNoLog = pt(v, 5, ncp=7, lower=FALSE),
257+
upperLog = pt(v, 5, ncp=7, lower=FALSE, log=TRUE) ),
258+
msg = "stats.pnt" )
259+
}
260+
248261
test.stats.qbinom <- function( ) {
249262
n <- 20
250263
p <- 0.5
@@ -299,19 +312,19 @@ test.stats.qt <- function( ) {
299312
( x1 <- runit_qt(v, 5, FALSE, FALSE) )
300313
( x2 <- qt(v, df=5, lower=FALSE, log=FALSE) )
301314
checkEquals(x1, x2, msg="stats.qt.f.f")
302-
315+
303316
( x1 <- runit_qt(v, 5, TRUE, FALSE) )
304-
( x2 <- qt(v, df=5, lower=TRUE, log=FALSE) )
317+
( x2 <- qt(v, df=5, lower=TRUE, log=FALSE) )
305318
checkEquals(x1, x2, msg="stats.qt.t.f")
306-
319+
307320
( x1 <- runit_qt(-v, 5, FALSE, TRUE) )
308-
( x2 <- qt(-v, df=5, lower=FALSE, log=TRUE) )
321+
( x2 <- qt(-v, df=5, lower=FALSE, log=TRUE) )
309322
checkEquals(x1, x2, msg="stats.qt.f.t")
310-
323+
311324
( x1 <- runit_qt(-v, 5, TRUE, TRUE) )
312-
( x2 <- qt(-v, df=5, lower=TRUE, log=TRUE) )
325+
( x2 <- qt(-v, df=5, lower=TRUE, log=TRUE) )
313326
checkEquals(x1, x2, msg="stats.qt.t.t")
314-
327+
315328
}
316329

317330
# TODO: test.stats.qgamma

0 commit comments

Comments
 (0)